From 2c22cee1f8fa87c527449a8bdc668ea311fdaf64 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Fri, 27 Apr 2012 13:33:58 +1000 Subject: Bit more work. maxFixpoint should be working now. --- impl/VariableAssignment.hpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'impl/VariableAssignment.hpp') 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 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(); + } + } + 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 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& 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 expand(const VariableAssignment& other) { + return expand(other, infinity()); + } + VariableAssignment expand(const VariableAssignment& other, const T& value) { + VariableAssignment 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; -- cgit v1.2.3