3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-07-25 13:47:01 +00:00

new invariant for dlist: should be circular. avoid infinite loop

This commit is contained in:
Chuyue Sun 2024-07-18 01:41:56 +00:00
parent aa7314ecb6
commit 62df40f0a6

View file

@ -157,13 +157,23 @@ public:
bool invariant() const {
auto* e = this;
do {
if (e->m_next->m_prev != e)
const T* slow = static_cast<const T*>(this);
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;
e = e->m_next;
}
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;
}
}
while (e != this);
return true;
return true;
}
static bool contains(T const* list, T const* elem) {