mirror of
https://github.com/Z3Prover/z3
synced 2025-05-01 21:05:52 +00:00
Reorganizing source code. Created util dir
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
630ba0c675
commit
2c464d413d
153 changed files with 0 additions and 0 deletions
96
src/util/list.h
Normal file
96
src/util/list.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
list.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Simple list data structure. It is meant to be used with region allocators.
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2007-07-10.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef _LIST_H_
|
||||
#define _LIST_H_
|
||||
|
||||
#include"buffer.h"
|
||||
#include"region.h"
|
||||
|
||||
template<typename T>
|
||||
class list {
|
||||
T m_head;
|
||||
list * m_tail;
|
||||
|
||||
public:
|
||||
list(T const & h, list * t = 0):
|
||||
m_head(h),
|
||||
m_tail(t) {
|
||||
}
|
||||
|
||||
T const & head() const { return m_head; }
|
||||
list * tail() const { return m_tail; }
|
||||
T & head() { return m_head; }
|
||||
list * & tail() { return m_tail; }
|
||||
|
||||
class iterator {
|
||||
list const * m_curr;
|
||||
public:
|
||||
iterator(list const * c = 0):m_curr(c) {}
|
||||
T const & operator*() const { return m_curr->head(); }
|
||||
iterator & operator++() { m_curr = m_curr->tail(); return *this; }
|
||||
iterator operator++(int) { iterator tmp = *this; ++*this; return tmp; }
|
||||
bool operator==(iterator const & it) { return m_curr == it.m_curr; }
|
||||
bool operator!=(iterator const & it) { return m_curr != it.m_curr; }
|
||||
};
|
||||
|
||||
typedef iterator const_iterator;
|
||||
iterator begin() const { return iterator(this); }
|
||||
iterator end() const { return iterator(0); }
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Return the list length.
|
||||
*/
|
||||
template<typename T>
|
||||
unsigned length(list<T> * l) {
|
||||
unsigned r = 0;
|
||||
while(l) {
|
||||
l = l->tail();
|
||||
r++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Non destructive apppend operation. The new nodes are allocated
|
||||
using the given region allocator.
|
||||
*/
|
||||
template<typename T>
|
||||
list<T> * append(region & r, list<T> * l1, list<T> * l2) {
|
||||
if (l2 == 0) {
|
||||
return l1;
|
||||
}
|
||||
ptr_buffer<list<T> > buffer;
|
||||
while (l1) {
|
||||
buffer.push_back(l1);
|
||||
l1 = l1->tail();
|
||||
}
|
||||
list<T> * result = l2;
|
||||
typename ptr_buffer<list<T> >::const_iterator it = buffer.end();
|
||||
typename ptr_buffer<list<T> >::const_iterator begin = buffer.begin();
|
||||
while (it != begin) {
|
||||
--it;
|
||||
list<T> * curr = *it;
|
||||
result = new (r) list<T>(curr->head(), result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* _LIST_H_ */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue