Changeset d9a0e76 for translator/ResolvExpr/Cost.h
- Timestamp:
- Dec 16, 2014, 9:41:50 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 17cd4eb
- Parents:
- 3848e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ResolvExpr/Cost.h
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Cost.h,v 1.2 2003/01/27 14:46:59 rcbilson Exp $5 *6 */7 8 1 #ifndef RESOLVEXPR_COST_H 9 2 #define RESOLVEXPR_COST_H … … 12 5 13 6 namespace ResolvExpr { 7 class Cost { 8 public: 9 Cost(); 10 Cost( int unsafe, int poly, int safe ); 11 12 void incUnsafe( int inc = 1 ); 13 void incPoly( int inc = 1 ); 14 void incSafe( int inc = 1 ); 15 16 Cost operator+( const Cost &other ) const; 17 Cost operator-( const Cost &other ) const; 18 Cost &operator+=( const Cost &other ); 19 bool operator<( const Cost &other ) const; 20 bool operator==( const Cost &other ) const; 21 bool operator!=( const Cost &other ) const; 22 friend std::ostream &operator<<( std::ostream &os, const Cost &cost ); 23 24 static const Cost zero; 25 static const Cost infinity; 26 private: 27 int compare( const Cost &other ) const; 14 28 15 class Cost 16 { 17 public: 18 Cost(); 19 Cost( int unsafe, int poly, int safe ); 20 21 void incUnsafe( int inc = 1 ); 22 void incPoly( int inc = 1 ); 23 void incSafe( int inc = 1 ); 24 25 Cost operator+( const Cost &other ) const; 26 Cost operator-( const Cost &other ) const; 27 Cost &operator+=( const Cost &other ); 28 bool operator<( const Cost &other ) const; 29 bool operator==( const Cost &other ) const; 30 bool operator!=( const Cost &other ) const; 31 friend std::ostream &operator<<( std::ostream &os, const Cost &cost ); 32 33 static const Cost zero; 34 static const Cost infinity; 35 36 private: 37 int compare( const Cost &other ) const; 29 int unsafe; 30 int poly; 31 int safe; 32 }; 38 33 39 int unsafe; 40 int poly; 41 int safe; 42 }; 34 inline Cost::Cost() : unsafe( 0 ), poly( 0 ), safe( 0 ) {} 43 35 44 inline 45 Cost::Cost() 46 : unsafe( 0 ), poly( 0 ), safe( 0 ) 47 { 48 } 36 inline Cost::Cost( int unsafe, int poly, int safe ) : unsafe( unsafe ), poly( poly ), safe( safe ) {} 49 37 50 inline 51 Cost::Cost( int unsafe, int poly, int safe ) 52 : unsafe( unsafe ), poly( poly ), safe( safe ) 53 { 54 } 38 inline void 39 Cost::incUnsafe( int inc ) { 40 unsafe += inc; 41 } 55 42 56 inline void 57 Cost::incUnsafe( int inc ) 58 { 59 unsafe += inc; 60 } 43 inline void 44 Cost::incPoly( int inc ) { 45 unsafe += inc; 46 } 61 47 62 inline void 63 Cost::incPoly( int inc ) 64 { 65 unsafe += inc; 66 } 48 inline void 49 Cost::incSafe( int inc ) { 50 unsafe += inc; 51 } 67 52 68 inline void 69 Cost::incSafe( int inc ) 70 { 71 unsafe += inc; 72 } 53 inline Cost Cost::operator+( const Cost &other ) const { 54 return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe ); 55 } 73 56 74 inline Cost 75 Cost::operator+( const Cost &other ) const 76 { 77 return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe ); 78 } 57 inline Cost Cost::operator-( const Cost &other ) const { 58 return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe ); 59 } 79 60 80 inline Cost 81 Cost::operator-( const Cost &other ) const 82 { 83 return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe ); 84 } 61 inline Cost &Cost::operator+=( const Cost &other ) { 62 unsafe += other.unsafe; 63 poly += other.poly; 64 safe += other.safe; 65 return *this; 66 } 85 67 86 inline Cost & 87 Cost::operator+=( const Cost &other ) 88 { 89 unsafe += other.unsafe; 90 poly += other.poly; 91 safe += other.safe; 92 return *this; 93 } 68 inline bool Cost::operator<( const Cost &other ) const { 69 if ( *this == infinity ) return false; 70 if ( other == infinity ) return true; 71 if ( unsafe > other.unsafe ) { 72 return false; 73 } else if ( unsafe < other.unsafe ) { 74 return true; 75 } else if ( poly > other.poly ) { 76 return false; 77 } else if ( poly < other.poly ) { 78 return true; 79 } else if ( safe > other.safe ) { 80 return false; 81 } else if ( safe < other.safe ) { 82 return true; 83 } else { 84 return false; 85 } 86 } 94 87 95 inline bool 96 Cost::operator<( const Cost &other ) const 97 { 98 if( *this == infinity ) return false; 99 if( other == infinity ) return true; 100 if( unsafe > other.unsafe ) { 101 return false; 102 } else if( unsafe < other.unsafe ) { 103 return true; 104 } else if( poly > other.poly ) { 105 return false; 106 } else if( poly < other.poly ) { 107 return true; 108 } else if( safe > other.safe ) { 109 return false; 110 } else if( safe < other.safe ) { 111 return true; 112 } else { 113 return false; 114 } 115 } 88 inline bool Cost::operator==( const Cost &other ) const { 89 return unsafe == other.unsafe 90 && poly == other.poly 91 && safe == other.safe; 92 } 116 93 117 inline bool 118 Cost::operator==( const Cost &other ) const 119 { 120 return unsafe == other.unsafe 121 && poly == other.poly 122 && safe == other.safe; 123 } 94 inline bool Cost::operator!=( const Cost &other ) const { 95 return !( *this == other ); 96 } 124 97 125 inline bool 126 Cost::operator!=( const Cost &other ) const 127 { 128 return !( *this == other ); 129 } 130 131 inline std::ostream & 132 operator<<( std::ostream &os, const Cost &cost ) 133 { 134 os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )"; 135 return os; 136 } 137 98 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 99 os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )"; 100 return os; 101 } 138 102 } // namespace ResolvExpr 139 103 140 #endif / * #ifndef RESOLVEXPR_COST_H */104 #endif // RESOLVEXPR_COST_H
Note: See TracChangeset
for help on using the changeset viewer.