source: src/ResolvExpr/Cost.h @ 7069652

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 7069652 was 5aa708c, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

fix paste error in incPoly and incSafe

  • Property mode set to 100644
File size: 2.9 KB
Line 
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 : Rob Schluntz
12// Last Modified On : Wed Jul 22 16:43:10 2015
13// Update Count     : 4
14//
15
16#ifndef COST_H
17#define COST_H
18
19#include <iostream>
20
21namespace ResolvExpr {
22        class Cost {
23          public:
24                Cost();
25                Cost( int unsafe, int poly, int safe );
26 
27                void incUnsafe( int inc = 1 );
28                void incPoly( int inc = 1 );
29                void incSafe( int inc = 1 );
30 
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 );
38 
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 ) {
58                poly += inc;
59        }
60
61        inline void Cost::incSafe( int inc ) {
62                safe += inc;
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 {
81            if ( *this == infinity ) return false;
82            if ( other == infinity ) return true;
83            if ( unsafe > other.unsafe ) {
84                        return false;
85            } else if ( unsafe < other.unsafe ) {
86                        return true;
87            } else if ( poly > other.poly ) {
88                        return false;
89            } else if ( poly < other.poly ) {
90                        return true;
91            } else if ( safe > other.safe ) {
92                        return false;
93            } else if ( safe < other.safe ) {
94                        return true;
95            } else {
96                        return false;
97            } // if
98        }
99
100        inline bool Cost::operator==( const Cost &other ) const {
101                return unsafe == other.unsafe
102                        && poly == other.poly
103                        && safe == other.safe;
104        }
105
106        inline bool Cost::operator!=( const Cost &other ) const {
107                return !( *this == other );
108        }
109
110        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
111                os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )";
112                return os;
113        }
114} // namespace ResolvExpr
115
116#endif // COST_H
117
118// Local Variables: //
119// tab-width: 4 //
120// mode: c++ //
121// compile-command: "make install" //
122// End: //
Note: See TracBrowser for help on using the repository browser.