| [a32b204] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
|  | 7 | // Cost.h -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Sun May 17 09:39:50 2015 | 
|---|
| [5aa708c] | 11 | // Last Modified By : Rob Schluntz | 
|---|
|  | 12 | // Last Modified On : Wed Jul 22 16:43:10 2015 | 
|---|
|  | 13 | // Update Count     : 4 | 
|---|
| [a32b204] | 14 | // | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #ifndef COST_H | 
|---|
|  | 17 | #define COST_H | 
|---|
| [51b73452] | 18 |  | 
|---|
|  | 19 | #include <iostream> | 
|---|
|  | 20 |  | 
|---|
|  | 21 | namespace ResolvExpr { | 
|---|
| [a32b204] | 22 | class Cost { | 
|---|
|  | 23 | public: | 
|---|
|  | 24 | Cost(); | 
|---|
|  | 25 | Cost( int unsafe, int poly, int safe ); | 
|---|
| [51b73452] | 26 |  | 
|---|
| [a32b204] | 27 | void incUnsafe( int inc = 1 ); | 
|---|
|  | 28 | void incPoly( int inc = 1 ); | 
|---|
|  | 29 | void incSafe( int inc = 1 ); | 
|---|
| [51b73452] | 30 |  | 
|---|
| [a32b204] | 31 | Cost operator+( const Cost &other ) const; | 
|---|
|  | 32 | Cost operator-( const Cost &other ) const; | 
|---|
|  | 33 | Cost &operator+=( const Cost &other ); | 
|---|
|  | 34 | bool operator<( const Cost &other ) const; | 
|---|
|  | 35 | bool operator==( const Cost &other ) const; | 
|---|
|  | 36 | bool operator!=( const Cost &other ) const; | 
|---|
|  | 37 | friend std::ostream &operator<<( std::ostream &os, const Cost &cost ); | 
|---|
| [51b73452] | 38 |  | 
|---|
| [a32b204] | 39 | static const Cost zero; | 
|---|
|  | 40 | static const Cost infinity; | 
|---|
|  | 41 | private: | 
|---|
|  | 42 | int compare( const Cost &other ) const; | 
|---|
|  | 43 |  | 
|---|
|  | 44 | int unsafe; | 
|---|
|  | 45 | int poly; | 
|---|
|  | 46 | int safe; | 
|---|
|  | 47 | }; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | inline Cost::Cost() : unsafe( 0 ), poly( 0 ), safe( 0 ) {} | 
|---|
|  | 50 |  | 
|---|
|  | 51 | inline Cost::Cost( int unsafe, int poly, int safe ) : unsafe( unsafe ), poly( poly ), safe( safe ) {} | 
|---|
|  | 52 |  | 
|---|
|  | 53 | inline void Cost::incUnsafe( int inc ) { | 
|---|
|  | 54 | unsafe += inc; | 
|---|
|  | 55 | } | 
|---|
|  | 56 |  | 
|---|
|  | 57 | inline void Cost::incPoly( int inc ) { | 
|---|
| [5aa708c] | 58 | poly += inc; | 
|---|
| [a32b204] | 59 | } | 
|---|
|  | 60 |  | 
|---|
|  | 61 | inline void Cost::incSafe( int inc ) { | 
|---|
| [5aa708c] | 62 | safe += inc; | 
|---|
| [a32b204] | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 | inline Cost Cost::operator+( const Cost &other ) const { | 
|---|
|  | 66 | return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe ); | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | inline Cost Cost::operator-( const Cost &other ) const { | 
|---|
|  | 70 | return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe ); | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | inline Cost &Cost::operator+=( const Cost &other ) { | 
|---|
|  | 74 | unsafe += other.unsafe; | 
|---|
|  | 75 | poly += other.poly; | 
|---|
|  | 76 | safe += other.safe; | 
|---|
|  | 77 | return *this; | 
|---|
|  | 78 | } | 
|---|
|  | 79 |  | 
|---|
|  | 80 | inline bool Cost::operator<( const Cost &other ) const { | 
|---|
| [d9a0e76] | 81 | if ( *this == infinity ) return false; | 
|---|
|  | 82 | if ( other == infinity ) return true; | 
|---|
|  | 83 | if ( unsafe > other.unsafe ) { | 
|---|
| [a32b204] | 84 | return false; | 
|---|
| [d9a0e76] | 85 | } else if ( unsafe < other.unsafe ) { | 
|---|
| [a32b204] | 86 | return true; | 
|---|
| [d9a0e76] | 87 | } else if ( poly > other.poly ) { | 
|---|
| [a32b204] | 88 | return false; | 
|---|
| [d9a0e76] | 89 | } else if ( poly < other.poly ) { | 
|---|
| [a32b204] | 90 | return true; | 
|---|
| [d9a0e76] | 91 | } else if ( safe > other.safe ) { | 
|---|
| [a32b204] | 92 | return false; | 
|---|
| [d9a0e76] | 93 | } else if ( safe < other.safe ) { | 
|---|
| [a32b204] | 94 | return true; | 
|---|
| [d9a0e76] | 95 | } else { | 
|---|
| [a32b204] | 96 | return false; | 
|---|
|  | 97 | } // if | 
|---|
| [d9a0e76] | 98 | } | 
|---|
|  | 99 |  | 
|---|
| [a32b204] | 100 | inline bool Cost::operator==( const Cost &other ) const { | 
|---|
|  | 101 | return unsafe == other.unsafe | 
|---|
|  | 102 | && poly == other.poly | 
|---|
|  | 103 | && safe == other.safe; | 
|---|
|  | 104 | } | 
|---|
| [d9a0e76] | 105 |  | 
|---|
| [a32b204] | 106 | inline bool Cost::operator!=( const Cost &other ) const { | 
|---|
|  | 107 | return !( *this == other ); | 
|---|
|  | 108 | } | 
|---|
| [d9a0e76] | 109 |  | 
|---|
| [a32b204] | 110 | inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { | 
|---|
|  | 111 | os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )"; | 
|---|
|  | 112 | return os; | 
|---|
|  | 113 | } | 
|---|
| [51b73452] | 114 | } // namespace ResolvExpr | 
|---|
|  | 115 |  | 
|---|
| [a32b204] | 116 | #endif // COST_H | 
|---|
|  | 117 |  | 
|---|
|  | 118 | // Local Variables: // | 
|---|
|  | 119 | // tab-width: 4 // | 
|---|
|  | 120 | // mode: c++ // | 
|---|
|  | 121 | // compile-command: "make install" // | 
|---|
|  | 122 | // End: // | 
|---|