Changeset a32b204 for translator/ResolvExpr/Cost.h
- Timestamp:
- May 17, 2015, 1:19:35 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:
- 0dd3a2f
- Parents:
- b87a5ed
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ResolvExpr/Cost.h
rb87a5ed ra32b204 1 #ifndef RESOLVEXPR_COST_H 2 #define RESOLVEXPR_COST_H 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 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 09:42:04 2015 13 // Update Count : 3 14 // 15 16 #ifndef COST_H 17 #define COST_H 3 18 4 19 #include <iostream> 5 20 6 21 namespace ResolvExpr { 7 8 9 Cost();10 Cost( int unsafe, int poly, int safe );22 class Cost { 23 public: 24 Cost(); 25 Cost( int unsafe, int poly, int safe ); 11 26 12 void incUnsafe( int inc = 1 );13 void incPoly( int inc = 1 );14 void incSafe( int inc = 1 );27 void incUnsafe( int inc = 1 ); 28 void incPoly( int inc = 1 ); 29 void incSafe( int inc = 1 ); 15 30 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 );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 ); 23 38 24 static const Cost zero;25 static const Cost infinity;26 27 int compare( const Cost &other ) const;39 static const Cost zero; 40 static const Cost infinity; 41 private: 42 int compare( const Cost &other ) const; 28 43 29 int unsafe;30 int poly;31 int safe;32 44 int unsafe; 45 int poly; 46 int safe; 47 }; 33 48 34 49 inline Cost::Cost() : unsafe( 0 ), poly( 0 ), safe( 0 ) {} 35 50 36 51 inline Cost::Cost( int unsafe, int poly, int safe ) : unsafe( unsafe ), poly( poly ), safe( safe ) {} 37 52 38 inline void 39 Cost::incUnsafe( int inc ) { 40 unsafe += inc; 41 } 53 inline void Cost::incUnsafe( int inc ) { 54 unsafe += inc; 55 } 42 56 43 inline void 44 Cost::incPoly( int inc ) { 45 unsafe += inc; 46 } 57 inline void Cost::incPoly( int inc ) { 58 unsafe += inc; 59 } 47 60 48 inline void 49 Cost::incSafe( int inc ) { 50 unsafe += inc; 51 } 61 inline void Cost::incSafe( int inc ) { 62 unsafe += inc; 63 } 52 64 53 54 return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe );55 65 inline Cost Cost::operator+( const Cost &other ) const { 66 return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe ); 67 } 56 68 57 58 return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe );59 69 inline Cost Cost::operator-( const Cost &other ) const { 70 return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe ); 71 } 60 72 61 62 unsafe += other.unsafe;63 poly += other.poly;64 safe += other.safe;65 return *this;66 73 inline Cost &Cost::operator+=( const Cost &other ) { 74 unsafe += other.unsafe; 75 poly += other.poly; 76 safe += other.safe; 77 return *this; 78 } 67 79 68 80 inline bool Cost::operator<( const Cost &other ) const { 69 81 if ( *this == infinity ) return false; 70 82 if ( other == infinity ) return true; 71 83 if ( unsafe > other.unsafe ) { 72 return false;84 return false; 73 85 } else if ( unsafe < other.unsafe ) { 74 return true;86 return true; 75 87 } else if ( poly > other.poly ) { 76 return false;88 return false; 77 89 } else if ( poly < other.poly ) { 78 return true;90 return true; 79 91 } else if ( safe > other.safe ) { 80 return false;92 return false; 81 93 } else if ( safe < other.safe ) { 82 return true;94 return true; 83 95 } else { 84 return false;85 } 96 return false; 97 } // if 86 98 } 87 99 88 89 return unsafe == other.unsafe90 && poly == other.poly91 && safe == other.safe;92 100 inline bool Cost::operator==( const Cost &other ) const { 101 return unsafe == other.unsafe 102 && poly == other.poly 103 && safe == other.safe; 104 } 93 105 94 95 return !( *this == other );96 106 inline bool Cost::operator!=( const Cost &other ) const { 107 return !( *this == other ); 108 } 97 109 98 99 os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )";100 return os;101 110 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 111 os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )"; 112 return os; 113 } 102 114 } // namespace ResolvExpr 103 115 104 #endif // RESOLVEXPR_COST_H 116 #endif // COST_H 117 118 // Local Variables: // 119 // tab-width: 4 // 120 // mode: c++ // 121 // compile-command: "make install" // 122 // End: //
Note: See TracChangeset
for help on using the changeset viewer.