mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
* fixing #4670 Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * init Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * arrays Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * arrays Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * arrays Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * na Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
ee00542e76
commit
cfa7c733db
48 changed files with 1591 additions and 359 deletions
138
src/util/dlist.h
138
src/util/dlist.h
|
@ -7,7 +7,7 @@ Module Name:
|
|||
|
||||
Abstract:
|
||||
|
||||
Templates for manipulating doubly linked lists.
|
||||
Templates for manipulating circular doubly linked lists.
|
||||
|
||||
Author:
|
||||
|
||||
|
@ -18,123 +18,6 @@ Revision History:
|
|||
--*/
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
-- unused
|
||||
|
||||
/**
|
||||
Add element \c elem to the list headed by \c head.
|
||||
NextProc and PrevProc must have the methods:
|
||||
T * & operator()(T *);
|
||||
T * & operator()(T *);
|
||||
They should return the next and prev fields of the given object.
|
||||
*/
|
||||
template<typename T, typename NextProc, typename PrevProc>
|
||||
void dlist_add(T * & head, T * elem, NextProc const & next = NextProc(), PrevProc const & prev = PrevProc()) {
|
||||
SASSERT(prev(elem) == 0);
|
||||
SASSERT(next(elem) == 0);
|
||||
if (head == 0) {
|
||||
head = elem;
|
||||
}
|
||||
else {
|
||||
next(elem) = head;
|
||||
prev(head) = elem;
|
||||
head = elem;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename NextProc, typename PrevProc>
|
||||
void dlist_del(T * & head, T * elem, NextProc const & next = NextProc(), PrevProc const & prev = PrevProc()) {
|
||||
T * & prev_elem = prev(elem);
|
||||
T * & next_elem = next(elem);
|
||||
if (head == elem) {
|
||||
SASSERT(prev_elem == 0);
|
||||
if (next_elem != 0)
|
||||
prev(next_elem) = 0;
|
||||
head = next_elem;
|
||||
}
|
||||
else {
|
||||
SASSERT(prev_elem != 0);
|
||||
next(prev_elem) = next_elem;
|
||||
if (next_elem != 0)
|
||||
prev(next_elem) = prev_elem;
|
||||
}
|
||||
prev_elem = 0;
|
||||
next_elem = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Remove the head of the list. Return the old head.
|
||||
*/
|
||||
template<typename T, typename NextProc, typename PrevProc>
|
||||
T * dlist_pop(T * & head, NextProc const & next = NextProc(), PrevProc const & prev = PrevProc()) {
|
||||
if (head == 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
SASSERT(prev(head) == 0);
|
||||
T * r = head;
|
||||
head = next(head);
|
||||
if (head)
|
||||
prev(head) = 0;
|
||||
next(r) = 0;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Insert new element after elem.
|
||||
*/
|
||||
template<typename T, typename NextProc, typename PrevProc>
|
||||
void dlist_insert_after(T * elem, T * new_elem, NextProc const & next = NextProc(), PrevProc const & prev = PrevProc()) {
|
||||
SASSERT(elem);
|
||||
SASSERT(new_elem);
|
||||
T * & old_next_elem = next(elem);
|
||||
prev(new_elem) = elem;
|
||||
next(new_elem) = old_next_elem;
|
||||
if (old_next_elem)
|
||||
prev(old_next_elem) = new_elem;
|
||||
// next(elem) = new_elem;
|
||||
old_next_elem = new_elem;
|
||||
}
|
||||
|
||||
template<typename T, typename NextProc>
|
||||
bool dlist_contains(T * head, T const * elem, NextProc const & next = NextProc()) {
|
||||
T * curr = head;
|
||||
while (curr != 0) {
|
||||
if (curr == elem)
|
||||
return true;
|
||||
curr = next(curr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T, typename NextProc>
|
||||
unsigned dlist_length(T * head, NextProc const & next = NextProc()) {
|
||||
unsigned r = 0;
|
||||
T * curr = head;
|
||||
while (curr != 0) {
|
||||
r++;
|
||||
curr = next(curr);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
template<typename T, typename NextProc, typename PrevProc>
|
||||
bool dlist_check_invariant(T * head, NextProc const & next = NextProc(), PrevProc const & prev = PrevProc()) {
|
||||
if (head == 0)
|
||||
return true;
|
||||
SASSERT(prev(head) == 0);
|
||||
T * old = head;
|
||||
T * curr = next(head);
|
||||
while (curr != 0) {
|
||||
SASSERT(prev(curr) == old);
|
||||
old = curr;
|
||||
curr = next(curr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
class dll_base {
|
||||
|
@ -149,6 +32,14 @@ public:
|
|||
m_next = t;
|
||||
m_prev = t;
|
||||
}
|
||||
|
||||
static T* pop(T*& list) {
|
||||
if (!list)
|
||||
return list;
|
||||
T* head = list;
|
||||
remove_from(list, head);
|
||||
return head;
|
||||
}
|
||||
|
||||
static void remove_from(T*& list, T* elem) {
|
||||
if (list->m_next == list) {
|
||||
|
@ -182,6 +73,17 @@ public:
|
|||
list = elem;
|
||||
}
|
||||
}
|
||||
|
||||
bool invariant() const {
|
||||
auto* e = this;
|
||||
do {
|
||||
if (e->m_next->m_prev != e)
|
||||
return false;
|
||||
e = e->m_next;
|
||||
}
|
||||
while (e != this);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -43,12 +43,12 @@ typedef enum { HT_FREE,
|
|||
|
||||
template<typename T>
|
||||
class default_hash_entry {
|
||||
unsigned m_hash; //!< cached hash code
|
||||
unsigned m_hash{ 0 }; //!< cached hash code
|
||||
hash_entry_state m_state;
|
||||
T m_data;
|
||||
public:
|
||||
typedef T data;
|
||||
default_hash_entry():m_state(HT_FREE) {}
|
||||
default_hash_entry():m_state(HT_FREE), m_data() {}
|
||||
unsigned get_hash() const { return m_hash; }
|
||||
bool is_free() const { return m_state == HT_FREE; }
|
||||
bool is_deleted() const { return m_state == HT_DELETED; }
|
||||
|
|
|
@ -59,10 +59,10 @@ public:
|
|||
struct key_data {
|
||||
Key * m_key;
|
||||
Value m_value;
|
||||
key_data():m_key(nullptr) {
|
||||
key_data():m_key(nullptr), m_value() {
|
||||
}
|
||||
key_data(Key * k):
|
||||
m_key(k) {
|
||||
m_key(k), m_value() {
|
||||
}
|
||||
key_data(Key * k, Value const & v):
|
||||
m_key(k),
|
||||
|
|
|
@ -27,8 +27,8 @@ class small_object_allocator {
|
|||
static const unsigned SMALL_OBJ_SIZE = 256;
|
||||
static const unsigned NUM_SLOTS = (SMALL_OBJ_SIZE >> PTR_ALIGNMENT);
|
||||
struct chunk {
|
||||
chunk * m_next;
|
||||
char * m_curr;
|
||||
chunk* m_next{ nullptr };
|
||||
char* m_curr{ nullptr };
|
||||
char m_data[CHUNK_SIZE];
|
||||
chunk():m_curr(m_data) {}
|
||||
};
|
||||
|
|
|
@ -99,9 +99,9 @@ public:
|
|||
T_set* tb = nullptr;
|
||||
if (!m_deps.find(t, tb)) {
|
||||
tb = alloc(T_set);
|
||||
insert(s, tb);
|
||||
insert(t, tb);
|
||||
}
|
||||
t->insert(s);
|
||||
tb->insert(s);
|
||||
}
|
||||
|
||||
ptr_vector<T> const& top_sorted() const { return m_top_sorted; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue