diff --git a/src/test/heap.cpp b/src/test/heap.cpp index 6a5bc7b9ffe..25a509dc8cd 100644 --- a/src/test/heap.cpp +++ b/src/test/heap.cpp @@ -27,7 +27,7 @@ struct lt_proc { bool operator()(int v1, int v2) const { return v1 < v2; } }; //struct int_hash_proc { unsigned operator()(int v) const { std::cout << "hash " << v << "\n"; VERIFY(v >= 0); return v; }}; //typedef int_hashtable > int_set; typedef heap int_heap; -#define N 10000 +#define N 100 static random_gen heap_rand(1); @@ -146,4 +146,3 @@ void tst_heap() { tst2(); } } - diff --git a/src/util/heap.h b/src/util/heap.h index c080c6ebde9..71cafeeb895 100644 --- a/src/util/heap.h +++ b/src/util/heap.h @@ -55,6 +55,19 @@ 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(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(m_values.size())) { SASSERT(m_value2indices[m_values[idx]] == idx); SASSERT(parent(idx) == 0 || !less_than(m_values[idx], m_values[parent(idx)]));