summaryrefslogtreecommitdiff
path: root/impl/VariableAssignment.hpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@carlo-laptop>2012-04-27 13:33:58 +1000
committerCarlo Zancanaro <carlo@carlo-laptop>2012-04-27 13:33:58 +1000
commit2c22cee1f8fa87c527449a8bdc668ea311fdaf64 (patch)
tree561d7cc1193765418d402c2265aeb39837c101a7 /impl/VariableAssignment.hpp
parent76a4f0fcf3a9bf54ef910cdb2c0bebea37182391 (diff)
Bit more work. maxFixpoint should be working now.
Diffstat (limited to 'impl/VariableAssignment.hpp')
-rw-r--r--impl/VariableAssignment.hpp44
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;