Skip to content

Commit

Permalink
Revert "new heap invariants (#7298)" (#7303)
Browse files Browse the repository at this point in the history
This reverts commit 80ac7b3.
  • Loading branch information
NikolajBjorner authored Jul 22, 2024
1 parent 3d014f8 commit 966c9a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
24 changes: 11 additions & 13 deletions src/test/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,34 @@ static void tst1() {
for (int i = 0; i < N * 3; i++) {
int val = heap_rand() % N;
if (!h.contains(val)) {
VERIFY(!t.contains(val));
ENSURE(!t.contains(val));
h.insert(val);
t.insert(val);
}
else {
if (!t.contains(val)) {
for (int v : t) std::cout << v << "\n";
}
VERIFY(t.contains(val));
ENSURE(t.contains(val));
}
}
VERIFY(h.check_invariant());
ENSURE(h.check_invariant());
for (int v : t) {
VERIFY(h.contains(v));
ENSURE(h.contains(v));
}
while (!h.empty()) {
int m1 = h.min_value();
int m2 = h.erase_min();
(void)m1;
(void)m2;
VERIFY(m1 == m2);
VERIFY(-1 < m2);
ENSURE(m1 == m2);
ENSURE(-1 < m2);
}
}

int g_value[N];

struct lt_proc2 { bool operator()(int v1, int v2) const { VERIFY(v1 < N && v2 < N); return g_value[v1] < g_value[v2]; } };
struct lt_proc2 { bool operator()(int v1, int v2) const { ENSURE(v1 < N && v2 < N); return g_value[v1] < g_value[v2]; } };
typedef heap<lt_proc2> int_heap2;

static void init_values() {
Expand Down Expand Up @@ -98,7 +98,7 @@ static void tst2() {
TRACE("heap", tout << "inserting: " << val << "\n";);
h.insert(val);
TRACE("heap", dump_heap(h, tout););
VERIFY(h.contains(val));
ENSURE(h.contains(val));
}
}
else if (cmd <= 6) {
Expand All @@ -107,7 +107,7 @@ static void tst2() {
TRACE("heap", tout << "removing: " << val << "\n";);
h.erase(val);
TRACE("heap", dump_heap(h, tout););
VERIFY(!h.contains(val));
ENSURE(!h.contains(val));
}
}
else if (cmd <= 8) {
Expand All @@ -128,12 +128,10 @@ static void tst2() {
}
}
else {
VERIFY(h.check_invariant());
ENSURE(h.check_invariant());
}
}
VERIFY(h.check_invariant());
h.reset();
VERIFY(h.check_invariant());
ENSURE(h.check_invariant());
}

void tst_heap() {
Expand Down
13 changes: 0 additions & 13 deletions src/util/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ class heap : private LT {
}

bool check_invariant_core(int idx) const {

// Check that m_values starts with a dummy value at index 0.
if (m_values.empty() || m_values[0] != -1) {
return false;
}

// All indices in m_value2indices that are not used in m_values should be 0
for (int val = 0; val < static_cast<int>(m_value2indices.size()); ++val) {
if (std::find(m_values.begin(), m_values.end(), val) == m_values.end() && m_value2indices[val] != 0) {
return false; // Unused indices should have a 0 value
}
}

if (idx < static_cast<int>(m_values.size())) {
SASSERT(m_value2indices[m_values[idx]] == idx);
SASSERT(parent(idx) == 0 || !less_than(m_values[idx], m_values[parent(idx)]));
Expand Down

0 comments on commit 966c9a3

Please sign in to comment.