3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 09:35:32 +00:00

experimenting with cardinalities

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-01-27 16:12:46 -08:00
parent 49d7fd4f9c
commit 0123b63f8a
4 changed files with 246 additions and 103 deletions

View file

@ -25,6 +25,7 @@ Revision History:
#include"z3_exception.h"
#include"common_msgs.h"
#include"vector.h"
#include"uint_set.h"
#include<iomanip>
namespace sat {
@ -150,79 +151,7 @@ namespace sat {
return out;
}
class uint_set {
svector<char> m_in_set;
svector<unsigned> m_set;
public:
typedef svector<unsigned>::const_iterator iterator;
void insert(unsigned v) {
m_in_set.reserve(v+1, false);
if (m_in_set[v])
return;
m_in_set[v] = true;
m_set.push_back(v);
}
void remove(unsigned v) {
if (contains(v)) {
m_in_set[v] = false;
unsigned i = 0;
for (i = 0; i < m_set.size() && m_set[i] != v; ++i)
;
SASSERT(i < m_set.size());
m_set[i] = m_set.back();
m_set.pop_back();
}
}
uint_set& operator=(uint_set const& other) {
m_in_set = other.m_in_set;
m_set = other.m_set;
return *this;
}
bool contains(unsigned v) const {
return v < m_in_set.size() && m_in_set[v] != 0;
}
bool empty() const {
return m_set.empty();
}
// erase some variable from the set
unsigned erase() {
SASSERT(!empty());
unsigned v = m_set.back();
m_set.pop_back();
m_in_set[v] = false;
return v;
}
unsigned size() const { return m_set.size(); }
iterator begin() const { return m_set.begin(); }
iterator end() const { return m_set.end(); }
void reset() { m_set.reset(); m_in_set.reset(); }
void finalize() { m_set.finalize(); m_in_set.finalize(); }
uint_set& operator&=(uint_set const& other) {
unsigned j = 0;
for (unsigned i = 0; i < m_set.size(); ++i) {
if (other.contains(m_set[i])) {
m_set[j] = m_set[i];
++j;
}
else {
m_in_set[m_set[i]] = false;
}
}
m_set.resize(j);
return *this;
}
uint_set& operator|=(uint_set const& other) {
for (unsigned i = 0; i < other.m_set.size(); ++i) {
insert(other.m_set[i]);
}
return *this;
}
};
typedef tracked_uint_set uint_set;
typedef uint_set bool_var_set;