diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-05-25 13:24:37 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-05-25 13:24:37 +1000 |
commit | 61f90f14af8796bbed074538882e76f1e1bf3333 (patch) | |
tree | 5d1dc744b47817a39b905418b1fc76bb828cea4a /impl/VariableAssignment.hpp | |
parent | ee8547cf3c89c51ff10603814e6f745466bc4c79 (diff) |
Try to make some more modular Fixpoint algorithms.
Diffstat (limited to 'impl/VariableAssignment.hpp')
-rw-r--r-- | impl/VariableAssignment.hpp | 78 |
1 files changed, 5 insertions, 73 deletions
diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp index d604a74..9d8137a 100644 --- a/impl/VariableAssignment.hpp +++ b/impl/VariableAssignment.hpp @@ -2,84 +2,16 @@ #define VARIABLE_ASSIGNMENT_HPP #include "Variable.hpp" -#include <ostream> +#include "IdMap.hpp" template<typename T> -struct VariableAssignment { +struct VariableAssignment : public IdMap<Variable<T>,T> { VariableAssignment(unsigned int length) - : _length(length), _assignment(new T[length]) { - for (unsigned int i = 0; i < _length; ++i) { - _assignment[i] = -infinity<T>(); - } - } + : IdMap<Variable<T>,T>(length, -infinity<T>()) { } VariableAssignment(unsigned int length, const T& initial) - : _length(length), _assignment(new T[length]) { - for (unsigned int i = 0; i < _length; ++i) { - _assignment[i] = initial; - } - } + : IdMap<Variable<T>,T>(length, initial) { } VariableAssignment(const VariableAssignment& other) - : _length(other._length), _assignment(new T[other._length]) { - for (unsigned int i = 0; i < _length; ++i) { - _assignment[i] = other._assignment[i]; - } - } - ~VariableAssignment() { - delete[] _assignment; - } - VariableAssignment& operator=(const VariableAssignment& other) { - delete[] _assignment; - _length = other._length; - _assignment = new T[_length]; - for (unsigned int i = 0; i < _length; ++i) { - _assignment[i] = other._assignment[i]; - } - return *this; - } - const T& operator[] (const Variable<T>& x) const { - if (x.id() >= _length) { - throw "Array out of bounds"; - } - return _assignment[x.id()]; - } - T& operator[] (const Variable<T>& x) { - if (x.id() >= _length) { - throw "Array out of bounds"; - } - return _assignment[x.id()]; - } - - VariableAssignment<T> expand(const VariableAssignment<T>& other) { - return expand(other, infinity<T>()); - } - VariableAssignment<T> expand(const VariableAssignment<T>& other, const T& value) { - VariableAssignment<T> expansion(_length); - for (unsigned int i = 0; i < _length; ++i) { - if (_assignment[i] == other._assignment[i]) { - expansion._assignment[i] = _assignment[i]; - } else { - expansion._assignment[i] = value; - } - } - return expansion; - } - - bool operator==(const VariableAssignment& other) const { - if (_length != other._length) - return false; - for (unsigned int i = 0; i < _length; ++i) { - if (_assignment[i] != other._assignment[i]) { - return false; - } - } - return true; - } - bool operator!=(const VariableAssignment& other) const { - return !(*this == other); - } - private: - unsigned int _length; - T* _assignment; + : IdMap<Variable<T>,T>(other) { } }; #endif |