source: translator/ResolvExpr/Cost.h@ c8ffe20b

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since c8ffe20b was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: Cost.h,v 1.2 2003/01/27 14:46:59 rcbilson Exp $
5 *
6 */
7
8#ifndef RESOLVEXPR_COST_H
9#define RESOLVEXPR_COST_H
10
11#include <iostream>
12
13namespace ResolvExpr {
14
15class Cost
16{
17public:
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
36private:
37 int compare( const Cost &other ) const;
38
39 int unsafe;
40 int poly;
41 int safe;
42};
43
44inline
45Cost::Cost()
46 : unsafe( 0 ), poly( 0 ), safe( 0 )
47{
48}
49
50inline
51Cost::Cost( int unsafe, int poly, int safe )
52 : unsafe( unsafe ), poly( poly ), safe( safe )
53{
54}
55
56inline void
57Cost::incUnsafe( int inc )
58{
59 unsafe += inc;
60}
61
62inline void
63Cost::incPoly( int inc )
64{
65 unsafe += inc;
66}
67
68inline void
69Cost::incSafe( int inc )
70{
71 unsafe += inc;
72}
73
74inline Cost
75Cost::operator+( const Cost &other ) const
76{
77 return Cost( unsafe + other.unsafe, poly + other.poly, safe + other.safe );
78}
79
80inline Cost
81Cost::operator-( const Cost &other ) const
82{
83 return Cost( unsafe - other.unsafe, poly - other.poly, safe - other.safe );
84}
85
86inline Cost &
87Cost::operator+=( const Cost &other )
88{
89 unsafe += other.unsafe;
90 poly += other.poly;
91 safe += other.safe;
92 return *this;
93}
94
95inline bool
96Cost::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}
116
117inline bool
118Cost::operator==( const Cost &other ) const
119{
120 return unsafe == other.unsafe
121 && poly == other.poly
122 && safe == other.safe;
123}
124
125inline bool
126Cost::operator!=( const Cost &other ) const
127{
128 return !( *this == other );
129}
130
131inline std::ostream &
132operator<<( std::ostream &os, const Cost &cost )
133{
134 os << "( " << cost.unsafe << ", " << cost.poly << ", " << cost.safe << " )";
135 return os;
136}
137
138} // namespace ResolvExpr
139
140#endif /* #ifndef RESOLVEXPR_COST_H */
Note: See TracBrowser for help on using the repository browser.