Skip to content

Commit

Permalink
new hashtable.h invariants (#7296)
Browse files Browse the repository at this point in the history
* add copyright for dlist unit test

* new hashtable invariants

* add copyright
  • Loading branch information
ChuyueSun committed Jul 19, 2024
1 parent 08b6338 commit bc636d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/dlist.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*++
Copyright (c) 2024 Microsoft Corporation

Module Name:

tst_dlist.cpp

Abstract:

Test dlist module

Author:

Chuyue Sun 2024-07-18.

--*/

#include <cassert>
#include <iostream>
#include "util/dlist.h"
Expand Down
14 changes: 14 additions & 0 deletions src/util/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Module Name:
Author:

Leonardo de Moura (leonardo) 2006-09-11.
Chuyue Sun (liviasun) 2024-07-18.

Revision History:

Expand Down Expand Up @@ -639,6 +640,19 @@ class core_hashtable : private HashProc, private EqProc {

#ifdef Z3DEBUG
bool check_invariant() {
// The capacity must always be a power of two.
if (!is_power_of_two(m_capacity))
return false;

// The number of deleted plus the size must not exceed the capacity.
if (m_num_deleted + m_size > m_capacity)
return false;

// Checking that m_num_deleted is less than or equal to m_size.
if (m_num_deleted > m_size) {
return false;
}

entry * curr = m_table;
entry * end = m_table + m_capacity;
unsigned num_deleted = 0;
Expand Down

0 comments on commit bc636d7

Please sign in to comment.