diff options
Diffstat (limited to 'impl/VariableAssignment.hpp')
-rw-r--r-- | impl/VariableAssignment.hpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp index e41f3d8..a2d0afd 100644 --- a/impl/VariableAssignment.hpp +++ b/impl/VariableAssignment.hpp @@ -6,11 +6,36 @@ template<typename T> struct VariableAssignment { VariableAssignment(unsigned int length) - : _length(length), _assignment(new T[length]) { } + : _length(length), _assignment(new T[length]) { + for (unsigned int i = 0; i < _length; ++i) { + _assignment[i] = -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; + } + } + 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; } - const T& operator[] (const Variable<T> x) const { + 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() < 0 || x.id() >= _length) { throw "Array out of bounds"; } @@ -22,6 +47,21 @@ struct VariableAssignment { } 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; + } private: unsigned int _length; T* _assignment; |