[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
|
---|
[6b0b624] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Sat Jul 22 09:35:55 2017
|
---|
| 13 | // Update Count : 5
|
---|
[a32b204] | 14 | //
|
---|
| 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[51b73452] | 17 |
|
---|
| 18 | #include <iostream>
|
---|
| 19 |
|
---|
| 20 | namespace ResolvExpr {
|
---|
[a32b204] | 21 | class Cost {
|
---|
| 22 | public:
|
---|
| 23 | Cost();
|
---|
| 24 | Cost( int unsafe, int poly, int safe );
|
---|
[51b73452] | 25 |
|
---|
[a32b204] | 26 | void incUnsafe( int inc = 1 );
|
---|
| 27 | void incPoly( int inc = 1 );
|
---|
| 28 | void incSafe( int inc = 1 );
|
---|
[51b73452] | 29 |
|
---|
[a32b204] | 30 | Cost operator+( const Cost &other ) const;
|
---|
| 31 | Cost operator-( const Cost &other ) const;
|
---|
| 32 | Cost &operator+=( const Cost &other );
|
---|
| 33 | bool operator<( const Cost &other ) const;
|
---|
| 34 | bool operator==( const Cost &other ) const;
|
---|
| 35 | bool operator!=( const Cost &other ) const;
|
---|
| 36 | friend std::ostream &operator<<( std::ostream &os, const Cost &cost );
|
---|
[51b73452] | 37 |
|
---|
[a32b204] | 38 | static const Cost zero;
|
---|
| 39 | static const Cost infinity;
|
---|
| 40 | private:
|
---|
| 41 | int compare( const Cost &other ) const;
|
---|
| 42 |
|
---|
| 43 | int unsafe;
|
---|
| 44 | int poly;
|
---|
| 45 | int safe;
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | inline Cost::Cost() : unsafe( 0 ), poly( 0 ), safe( 0 ) {}
|
---|
| 49 |
|
---|
| 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;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | inline void Cost::incPoly( int inc ) {
|
---|
[5aa708c] | 57 | poly += inc;
|
---|
[a32b204] | 58 | }
|
---|
| 59 |
|
---|
| 60 | inline void Cost::incSafe( int inc ) {
|
---|
[5aa708c] | 61 | safe += inc;
|
---|
[a32b204] | 62 | }
|
---|
| 63 |
|
---|
| 64 | inline Cost Cost::operator+( const Cost &other ) const {
|
---|
| 65 | return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe );
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | inline Cost Cost::operator-( const Cost &other ) const {
|
---|
| 69 | return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe );
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | inline Cost &Cost::operator+=( const Cost &other ) {
|
---|
| 73 | unsafe += other.unsafe;
|
---|
| 74 | poly += other.poly;
|
---|
| 75 | safe += other.safe;
|
---|
| 76 | return *this;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | inline bool Cost::operator<( const Cost &other ) const {
|
---|
[d9a0e76] | 80 | if ( *this == infinity ) return false;
|
---|
| 81 | if ( other == infinity ) return true;
|
---|
| 82 | if ( unsafe > other.unsafe ) {
|
---|
[a32b204] | 83 | return false;
|
---|
[d9a0e76] | 84 | } else if ( unsafe < other.unsafe ) {
|
---|
[a32b204] | 85 | return true;
|
---|
[d9a0e76] | 86 | } else if ( poly > other.poly ) {
|
---|
[a32b204] | 87 | return false;
|
---|
[d9a0e76] | 88 | } else if ( poly < other.poly ) {
|
---|
[a32b204] | 89 | return true;
|
---|
[d9a0e76] | 90 | } else if ( safe > other.safe ) {
|
---|
[a32b204] | 91 | return false;
|
---|
[d9a0e76] | 92 | } else if ( safe < other.safe ) {
|
---|
[a32b204] | 93 | return true;
|
---|
[d9a0e76] | 94 | } else {
|
---|
[a32b204] | 95 | return false;
|
---|
| 96 | } // if
|
---|
[d9a0e76] | 97 | }
|
---|
| 98 |
|
---|
[a32b204] | 99 | inline bool Cost::operator==( const Cost &other ) const {
|
---|
| 100 | return unsafe == other.unsafe
|
---|
| 101 | && poly == other.poly
|
---|
| 102 | && safe == other.safe;
|
---|
| 103 | }
|
---|
[d9a0e76] | 104 |
|
---|
[a32b204] | 105 | inline bool Cost::operator!=( const Cost &other ) const {
|
---|
| 106 | return !( *this == other );
|
---|
| 107 | }
|
---|
[d9a0e76] | 108 |
|
---|
[a32b204] | 109 | inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
|
---|
| 110 | os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )";
|
---|
| 111 | return os;
|
---|
| 112 | }
|
---|
[51b73452] | 113 | } // namespace ResolvExpr
|
---|
| 114 |
|
---|
[a32b204] | 115 | // Local Variables: //
|
---|
| 116 | // tab-width: 4 //
|
---|
| 117 | // mode: c++ //
|
---|
| 118 | // compile-command: "make install" //
|
---|
| 119 | // End: //
|
---|