source: src/ResolvExpr/Cost.h @ d104b02

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

Merge branch 'master' into references

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[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//
[b46e3bd]7// Cost.h --
[a32b204]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
[51b7345]17
18#include <iostream>
19
20namespace ResolvExpr {
[a32b204]21        class Cost {
[89be1c68]22          private:
[7ebaa56]23                Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost );
[b46e3bd]24
[89be1c68]25          public:
26                Cost & incUnsafe( int inc = 1 );
27                Cost & incPoly( int inc = 1 );
28                Cost & incSafe( int inc = 1 );
[7ebaa56]29                Cost & incReference( int inc = 1 );
[b46e3bd]30
[a32b204]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 );
[b46e3bd]38
[a32b204]39                static const Cost zero;
40                static const Cost infinity;
[7ebaa56]41
[b46e3bd]42                static const Cost unsafe;
43                static const Cost poly;
44                static const Cost safe;
[7ebaa56]45                static const Cost reference;
[a32b204]46          private:
47                int compare( const Cost &other ) const;
48
[b46e3bd]49                int unsafeCost;
50                int polyCost;
51                int safeCost;
[7ebaa56]52                int referenceCost;
[a32b204]53        };
54
[7ebaa56]55        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {}
[a32b204]56
[89be1c68]57        inline Cost & Cost::incUnsafe( int inc ) {
[17f22e78]58                if ( *this == infinity ) return *this;
[b46e3bd]59                unsafeCost += inc;
[89be1c68]60                return *this;
[a32b204]61        }
62
[89be1c68]63        inline Cost & Cost::incPoly( int inc ) {
[17f22e78]64                if ( *this == infinity ) return *this;
[b46e3bd]65                polyCost += inc;
[89be1c68]66                return *this;
[a32b204]67        }
68
[89be1c68]69        inline Cost & Cost::incSafe( int inc ) {
[17f22e78]70                if ( *this == infinity ) return *this;
[b46e3bd]71                safeCost += inc;
[89be1c68]72                return *this;
[a32b204]73        }
74
[7ebaa56]75        inline Cost & Cost::incReference( int inc ) {
[17f22e78]76                if ( *this == infinity ) return *this;
[7ebaa56]77                referenceCost += inc;
78                return *this;
79        }
80
[a32b204]81        inline Cost Cost::operator+( const Cost &other ) const {
[17f22e78]82                if ( *this == infinity || other == infinity ) return infinity;
[7ebaa56]83                return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost );
[a32b204]84        }
85
86        inline Cost Cost::operator-( const Cost &other ) const {
[17f22e78]87                if ( *this == infinity || other == infinity ) return infinity;
[7ebaa56]88                return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost );
[a32b204]89        }
90
91        inline Cost &Cost::operator+=( const Cost &other ) {
[17f22e78]92                if ( *this == infinity ) return *this;
93                if ( other == infinity ) {
94                        *this = infinity;
95                        return *this;
96                }
[b46e3bd]97                unsafeCost += other.unsafeCost;
98                polyCost += other.polyCost;
99                safeCost += other.safeCost;
[7ebaa56]100                referenceCost += other.referenceCost;
[a32b204]101                return *this;
102        }
103
104        inline bool Cost::operator<( const Cost &other ) const {
[b46e3bd]105                if ( *this == infinity ) return false;
106                if ( other == infinity ) return true;
107
108                if ( unsafeCost > other.unsafeCost ) {
[a32b204]109                        return false;
[b46e3bd]110                } else if ( unsafeCost < other.unsafeCost ) {
[a32b204]111                        return true;
[b46e3bd]112                } else if ( polyCost > other.polyCost ) {
[a32b204]113                        return false;
[b46e3bd]114                } else if ( polyCost < other.polyCost ) {
[a32b204]115                        return true;
[b46e3bd]116                } else if ( safeCost > other.safeCost ) {
[a32b204]117                        return false;
[b46e3bd]118                } else if ( safeCost < other.safeCost ) {
[a32b204]119                        return true;
[7ebaa56]120                } else if ( referenceCost > other.referenceCost ) {
121                        return false;
122                } else if ( referenceCost < other.referenceCost ) {
123                        return true;
[b46e3bd]124                } else {
[a32b204]125                        return false;
[b46e3bd]126                } // if
[d9a0e76]127        }
128
[a32b204]129        inline bool Cost::operator==( const Cost &other ) const {
[b46e3bd]130                return unsafeCost == other.unsafeCost
131                        && polyCost == other.polyCost
[7ebaa56]132                        && safeCost == other.safeCost
133                        && referenceCost == other.referenceCost;
[a32b204]134        }
[d9a0e76]135
[a32b204]136        inline bool Cost::operator!=( const Cost &other ) const {
137                return !( *this == other );
138        }
[d9a0e76]139
[a32b204]140        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
[7ebaa56]141                os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )";
[a32b204]142                return os;
143        }
[51b7345]144} // namespace ResolvExpr
145
[a32b204]146// Local Variables: //
147// tab-width: 4 //
148// mode: c++ //
149// compile-command: "make install" //
150// End: //
Note: See TracBrowser for help on using the repository browser.