Changes in src/ResolvExpr/Cost.h [6b0b624:ddf8a29]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Cost.h
r6b0b624 rddf8a29 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Cost.h -- 7 // Cost.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 20 20 namespace ResolvExpr { 21 21 class Cost { 22 private: 23 Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ); 24 22 25 public: 23 Cost(); 24 Cost( int unsafe, int poly, int safe ); 25 26 void incUnsafe( int inc = 1 ); 27 void incPoly( int inc = 1 ); 28 void incSafe( int inc = 1 ); 29 26 Cost & incUnsafe( int inc = 1 ); 27 Cost & incPoly( int inc = 1 ); 28 Cost & incSafe( int inc = 1 ); 29 Cost & incReference( int inc = 1 ); 30 31 int get_unsafeCost() const { return unsafeCost; } 32 int get_polyCost() const { return polyCost; } 33 int get_safeCost() const { return safeCost; } 34 int get_referenceCost() const { return referenceCost; } 35 30 36 Cost operator+( const Cost &other ) const; 31 37 Cost operator-( const Cost &other ) const; … … 35 41 bool operator!=( const Cost &other ) const; 36 42 friend std::ostream &operator<<( std::ostream &os, const Cost &cost ); 37 43 38 44 static const Cost zero; 39 45 static const Cost infinity; 46 47 static const Cost unsafe; 48 static const Cost poly; 49 static const Cost safe; 50 static const Cost reference; 40 51 private: 41 52 int compare( const Cost &other ) const; 42 53 43 int unsafe; 44 int poly; 45 int safe; 54 int unsafeCost; 55 int polyCost; 56 int safeCost; 57 int referenceCost; 46 58 }; 47 59 48 inline Cost::Cost( ) : unsafe( 0 ), poly( 0 ), safe( 0) {}60 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {} 49 61 50 inline Cost ::Cost( int unsafe, int poly, int safe ) : unsafe( unsafe ), poly( poly ), safe( safe ) {}51 52 inline void Cost::incUnsafe( int inc ) {53 unsafe += inc;62 inline Cost & Cost::incUnsafe( int inc ) { 63 if ( *this == infinity ) return *this; 64 unsafeCost += inc; 65 return *this; 54 66 } 55 67 56 inline void Cost::incPoly( int inc ) { 57 poly += inc; 68 inline Cost & Cost::incPoly( int inc ) { 69 if ( *this == infinity ) return *this; 70 polyCost += inc; 71 return *this; 58 72 } 59 73 60 inline void Cost::incSafe( int inc ) { 61 safe += inc; 74 inline Cost & Cost::incSafe( int inc ) { 75 if ( *this == infinity ) return *this; 76 safeCost += inc; 77 return *this; 78 } 79 80 inline Cost & Cost::incReference( int inc ) { 81 if ( *this == infinity ) return *this; 82 referenceCost += inc; 83 return *this; 62 84 } 63 85 64 86 inline Cost Cost::operator+( const Cost &other ) const { 65 return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe ); 87 if ( *this == infinity || other == infinity ) return infinity; 88 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost ); 66 89 } 67 90 68 91 inline Cost Cost::operator-( const Cost &other ) const { 69 return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe ); 92 if ( *this == infinity || other == infinity ) return infinity; 93 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost ); 70 94 } 71 95 72 96 inline Cost &Cost::operator+=( const Cost &other ) { 73 unsafe += other.unsafe; 74 poly += other.poly; 75 safe += other.safe; 97 if ( *this == infinity ) return *this; 98 if ( other == infinity ) { 99 *this = infinity; 100 return *this; 101 } 102 unsafeCost += other.unsafeCost; 103 polyCost += other.polyCost; 104 safeCost += other.safeCost; 105 referenceCost += other.referenceCost; 76 106 return *this; 77 107 } 78 108 79 109 inline bool Cost::operator<( const Cost &other ) const { 80 if ( *this == infinity ) return false; 81 if ( other == infinity ) return true; 82 if ( unsafe > other.unsafe ) { 110 if ( *this == infinity ) return false; 111 if ( other == infinity ) return true; 112 113 if ( unsafeCost > other.unsafeCost ) { 83 114 return false; 84 } else if ( unsafe < other.unsafe) {115 } else if ( unsafeCost < other.unsafeCost ) { 85 116 return true; 86 } else if ( poly > other.poly) {117 } else if ( polyCost > other.polyCost ) { 87 118 return false; 88 } else if ( poly < other.poly) {119 } else if ( polyCost < other.polyCost ) { 89 120 return true; 90 } else if ( safe > other.safe) {121 } else if ( safeCost > other.safeCost ) { 91 122 return false; 92 } else if ( safe < other.safe) {123 } else if ( safeCost < other.safeCost ) { 93 124 return true; 94 } else{125 } else if ( referenceCost > other.referenceCost ) { 95 126 return false; 96 } // if 127 } else if ( referenceCost < other.referenceCost ) { 128 return true; 129 } else { 130 return false; 131 } // if 97 132 } 98 133 99 134 inline bool Cost::operator==( const Cost &other ) const { 100 return unsafe == other.unsafe 101 && poly == other.poly 102 && safe == other.safe; 135 return unsafeCost == other.unsafeCost 136 && polyCost == other.polyCost 137 && safeCost == other.safeCost 138 && referenceCost == other.referenceCost; 103 139 } 104 140 … … 108 144 109 145 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 110 os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe<< " )";146 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )"; 111 147 return os; 112 148 }
Note: See TracChangeset
for help on using the changeset viewer.