mirror of
https://github.com/Z3Prover/z3
synced 2025-08-26 13:06:05 +00:00
clause_iterator
This commit is contained in:
parent
342774eff8
commit
bf92fa4882
3 changed files with 93 additions and 46 deletions
|
@ -126,9 +126,65 @@ namespace polysat {
|
|||
constraint* const* begin() const { return m_constraints.data(); }
|
||||
constraint* const* end() const { return m_constraints.data() + m_constraints.size(); }
|
||||
|
||||
using clause_iterator = decltype(m_clauses)::const_iterator;
|
||||
clause_iterator clauses_begin() const { return m_clauses.begin(); }
|
||||
clause_iterator clauses_end() const { return m_clauses.end(); }
|
||||
class clause_iterator {
|
||||
friend class constraint_manager;
|
||||
using storage_t = decltype(constraint_manager::m_clauses);
|
||||
|
||||
using outer_iterator = storage_t::const_iterator;
|
||||
outer_iterator outer_it;
|
||||
outer_iterator outer_end;
|
||||
|
||||
using inner_iterator = storage_t::data_t::const_iterator;
|
||||
inner_iterator inner_it;
|
||||
inner_iterator inner_end;
|
||||
|
||||
clause_iterator(storage_t const& cls, bool begin) {
|
||||
if (begin) {
|
||||
outer_it = cls.begin();
|
||||
outer_end = cls.end();
|
||||
}
|
||||
else {
|
||||
outer_it = cls.end();
|
||||
outer_end = cls.end();
|
||||
}
|
||||
begin_inner();
|
||||
}
|
||||
|
||||
void begin_inner() {
|
||||
if (outer_it == outer_end) {
|
||||
inner_it = nullptr;
|
||||
inner_end = nullptr;
|
||||
}
|
||||
else {
|
||||
inner_it = outer_it->begin();
|
||||
inner_end = outer_it->end();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
clause const& operator*() const {
|
||||
return *inner_it->get();
|
||||
}
|
||||
|
||||
clause_iterator& operator++() {
|
||||
++inner_it;
|
||||
while (inner_it == inner_end && outer_it != outer_end) {
|
||||
++outer_it;
|
||||
begin_inner();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(clause_iterator const& other) const {
|
||||
return outer_it == other.outer_it && inner_it == other.inner_it;
|
||||
}
|
||||
|
||||
bool operator!=(clause_iterator const& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
};
|
||||
clause_iterator clauses_begin() const { return clause_iterator(m_clauses, true); }
|
||||
clause_iterator clauses_end() const { return clause_iterator(m_clauses, false); }
|
||||
|
||||
class clauses_t {
|
||||
constraint_manager const* m_cm;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue