mirror of
https://github.com/Z3Prover/z3
synced 2025-04-15 13:28:47 +00:00
New invariant for dlist (#7294)
* unit tests for dlist.h * new invariant for dlist: should be circular. avoid infinite loop * remove dlist test commit * format * format * Update dlist.h --------- Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
9073da4ee6
commit
cf4d0e74a5
|
@ -157,12 +157,20 @@ public:
|
||||||
|
|
||||||
bool invariant() const {
|
bool invariant() const {
|
||||||
auto* e = this;
|
auto* e = this;
|
||||||
do {
|
const T* slow = static_cast<const T*>(this);
|
||||||
if (e->m_next->m_prev != e)
|
const T* fast = m_next;
|
||||||
|
bool looped = false;
|
||||||
|
// m_next of each node should point back to m_prev of the following node,
|
||||||
|
// and m_prev of each node should point forward to m_next of the preceding node.
|
||||||
|
while (slow != fast) {
|
||||||
|
if (fast->m_prev->m_next != fast || fast->m_next->m_prev != fast)
|
||||||
|
return false;
|
||||||
|
fast = fast->m_next;
|
||||||
|
looped = looped || (fast == static_cast<const T*>(this));
|
||||||
|
if (!looped && fast == m_next)
|
||||||
|
// We should be able to traverse back to the starting node.
|
||||||
return false;
|
return false;
|
||||||
e = e->m_next;
|
|
||||||
}
|
}
|
||||||
while (e != this);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue