source: src/ResolvExpr/Cost.h @ b46e3bd

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 b46e3bd was b46e3bd, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Update Cost structure to include static unsafe, poly, safe members

  • Property mode set to 100644
File size: 3.2 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 unsafeCost, int polyCost, int safeCost );
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                static const Cost unsafe;
42                static const Cost poly;
43                static const Cost safe;
44          private:
45                int compare( const Cost &other ) const;
46
47                int unsafeCost;
48                int polyCost;
49                int safeCost;
50        };
51
52        inline Cost::Cost() : unsafeCost( 0 ), polyCost( 0 ), safeCost( 0 ) {}
53
54        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ) {}
55
56        inline void Cost::incUnsafe( int inc ) {
57                unsafeCost += inc;
58        }
59
60        inline void Cost::incPoly( int inc ) {
61                polyCost += inc;
62        }
63
64        inline void Cost::incSafe( int inc ) {
65                safeCost += inc;
66        }
67
68        inline Cost Cost::operator+( const Cost &other ) const {
69                return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost );
70        }
71
72        inline Cost Cost::operator-( const Cost &other ) const {
73                return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost );
74        }
75
76        inline Cost &Cost::operator+=( const Cost &other ) {
77                unsafeCost += other.unsafeCost;
78                polyCost += other.polyCost;
79                safeCost += other.safeCost;
80                return *this;
81        }
82
83        inline bool Cost::operator<( const Cost &other ) const {
84                if ( *this == infinity ) return false;
85                if ( other == infinity ) return true;
86
87                if ( unsafeCost > other.unsafeCost ) {
88                        return false;
89                } else if ( unsafeCost < other.unsafeCost ) {
90                        return true;
91                } else if ( polyCost > other.polyCost ) {
92                        return false;
93                } else if ( polyCost < other.polyCost ) {
94                        return true;
95                } else if ( safeCost > other.safeCost ) {
96                        return false;
97                } else if ( safeCost < other.safeCost ) {
98                        return true;
99                } else {
100                        return false;
101                } // if
102        }
103
104        inline bool Cost::operator==( const Cost &other ) const {
105                return unsafeCost == other.unsafeCost
106                        && polyCost == other.polyCost
107                        && safeCost == other.safeCost;
108        }
109
110        inline bool Cost::operator!=( const Cost &other ) const {
111                return !( *this == other );
112        }
113
114        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
115                os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << " )";
116                return os;
117        }
118} // namespace ResolvExpr
119
120#endif // COST_H
121
122// Local Variables: //
123// tab-width: 4 //
124// mode: c++ //
125// compile-command: "make install" //
126// End: //
Note: See TracBrowser for help on using the repository browser.