abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Minisat::vec< T > Class Template Reference

#include <Vec.h>

Public Member Functions

 vec ()
 
 vec (int size)
 
 vec (int size, const T &pad)
 
 ~vec ()
 
 operator T * (void)
 
int size (void) const
 
void shrink (int nelems)
 
void shrink_ (int nelems)
 
int capacity (void) const
 
void capacity (int min_cap)
 
void growTo (int size)
 
void growTo (int size, const T &pad)
 
void clear (bool dealloc=false)
 
void push (void)
 
void push (const T &elem)
 
void push_ (const T &elem)
 
void pop (void)
 
const T & last (void) const
 
T & last (void)
 
const T & operator[] (int index) const
 
T & operator[] (int index)
 
void copyTo (vec< T > &copy) const
 
void moveTo (vec< T > &dest)
 

Private Member Functions

vec< T > & operator= (vec< T > &other)
 
 vec (vec< T > &other)
 

Static Private Member Functions

static int imax (int x, int y)
 
static void nextCap (int &cap)
 

Private Attributes

T * data
 
int sz
 
int cap
 

Detailed Description

template<class T>
class Minisat::vec< T >

Definition at line 38 of file Vec.h.

Constructor & Destructor Documentation

template<class T>
Minisat::vec< T >::vec ( vec< T > &  other)
inlineprivate

Definition at line 45 of file Vec.h.

45 { assert(0); }
#define assert(ex)
Definition: util_old.h:213
template<class T>
Minisat::vec< T >::vec ( )
inline

Definition at line 54 of file Vec.h.

54 : data(NULL) , sz(0) , cap(0) { }
int cap
Definition: Vec.h:41
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
Minisat::vec< T >::vec ( int  size)
inlineexplicit

Definition at line 55 of file Vec.h.

55 : data(NULL) , sz(0) , cap(0) { growTo(size); }
int size(void) const
Definition: Vec.h:63
int cap
Definition: Vec.h:41
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
void growTo(int size)
Definition: Vec.h:113
template<class T>
Minisat::vec< T >::vec ( int  size,
const T &  pad 
)
inline

Definition at line 56 of file Vec.h.

56 : data(NULL) , sz(0) , cap(0) { growTo(size, pad); }
int size(void) const
Definition: Vec.h:63
int cap
Definition: Vec.h:41
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
void growTo(int size)
Definition: Vec.h:113
template<class T>
Minisat::vec< T >::~vec ( )
inline

Definition at line 57 of file Vec.h.

57 { clear(true); }
void clear(bool dealloc=false)
Definition: Vec.h:121

Member Function Documentation

template<class T>
int Minisat::vec< T >::capacity ( void  ) const
inline

Definition at line 66 of file Vec.h.

66 { return cap; }
int cap
Definition: Vec.h:41
template<class T >
void Minisat::vec< T >::capacity ( int  min_cap)

Definition at line 96 of file Vec.h.

96  {
97  if (cap >= min_cap) return;
98  int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2
99  if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM))
100  throw OutOfMemoryException();
101  }
static int imax(int x, int y)
Definition: Vec.h:48
char * realloc()
int cap
Definition: Vec.h:41
T * data
Definition: Vec.h:39
template<class T >
void Minisat::vec< T >::clear ( bool  dealloc = false)

Definition at line 121 of file Vec.h.

121  {
122  if (data != NULL){
123  for (int i = 0; i < sz; i++) data[i].~T();
124  sz = 0;
125  if (dealloc) free(data), data = NULL, cap = 0; } }
VOID_HACK free()
int cap
Definition: Vec.h:41
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
void Minisat::vec< T >::copyTo ( vec< T > &  copy) const
inline

Definition at line 90 of file Vec.h.

90 { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
static void copy(const T &from, T &to)
Definition: Alg.h:61
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T >
void Minisat::vec< T >::growTo ( int  size)

Definition at line 113 of file Vec.h.

113  {
114  if (sz >= size) return;
115  capacity(size);
116  for (int i = sz; i < size; i++) new (&data[i]) T();
117  sz = size; }
int size(void) const
Definition: Vec.h:63
int capacity(void) const
Definition: Vec.h:66
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
void Minisat::vec< T >::growTo ( int  size,
const T &  pad 
)

Definition at line 105 of file Vec.h.

105  {
106  if (sz >= size) return;
107  capacity(size);
108  for (int i = sz; i < size; i++) data[i] = pad;
109  sz = size; }
int size(void) const
Definition: Vec.h:63
int capacity(void) const
Definition: Vec.h:66
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
static int Minisat::vec< T >::imax ( int  x,
int  y 
)
inlinestaticprivate

Definition at line 48 of file Vec.h.

48 { int mask = (y-x) >> (sizeof(int)*8-1); return (x&mask) + (y&(~mask)); }
template<class T>
const T& Minisat::vec< T >::last ( void  ) const
inline

Definition at line 82 of file Vec.h.

82 { return data[sz-1]; }
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
T& Minisat::vec< T >::last ( void  )
inline

Definition at line 83 of file Vec.h.

83 { return data[sz-1]; }
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
void Minisat::vec< T >::moveTo ( vec< T > &  dest)
inline

Definition at line 91 of file Vec.h.

91 { dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; }
int cap
Definition: Vec.h:41
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
static void Minisat::vec< T >::nextCap ( int &  cap)
inlinestaticprivate

Definition at line 50 of file Vec.h.

50 { cap += ((cap >> 1) + 2) & ~1; }
int cap
Definition: Vec.h:41
template<class T>
Minisat::vec< T >::operator T * ( void  )
inline

Definition at line 60 of file Vec.h.

60 { return data; }
T * data
Definition: Vec.h:39
template<class T>
vec<T>& Minisat::vec< T >::operator= ( vec< T > &  other)
inlineprivate

Definition at line 44 of file Vec.h.

44 { assert(0); return *this; }
#define assert(ex)
Definition: util_old.h:213
template<class T>
const T& Minisat::vec< T >::operator[] ( int  index) const
inline

Definition at line 86 of file Vec.h.

86 { return data[index]; }
T * data
Definition: Vec.h:39
template<class T>
T& Minisat::vec< T >::operator[] ( int  index)
inline

Definition at line 87 of file Vec.h.

87 { return data[index]; }
T * data
Definition: Vec.h:39
template<class T>
void Minisat::vec< T >::pop ( void  )
inline

Definition at line 76 of file Vec.h.

76 { assert(sz > 0); sz--, data[sz].~T(); }
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
#define assert(ex)
Definition: util_old.h:213
template<class T>
void Minisat::vec< T >::push ( void  )
inline

Definition at line 73 of file Vec.h.

73 { if (sz == cap) capacity(sz+1); new (&data[sz]) T(); sz++; }
int cap
Definition: Vec.h:41
int capacity(void) const
Definition: Vec.h:66
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
void Minisat::vec< T >::push ( const T &  elem)
inline

Definition at line 74 of file Vec.h.

74 { if (sz == cap) capacity(sz+1); data[sz++] = elem; }
int cap
Definition: Vec.h:41
int capacity(void) const
Definition: Vec.h:66
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
template<class T>
void Minisat::vec< T >::push_ ( const T &  elem)
inline

Definition at line 75 of file Vec.h.

75 { assert(sz < cap); data[sz++] = elem; }
int cap
Definition: Vec.h:41
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
#define assert(ex)
Definition: util_old.h:213
template<class T>
void Minisat::vec< T >::shrink ( int  nelems)
inline

Definition at line 64 of file Vec.h.

64 { assert(nelems <= sz); for (int i = 0; i < nelems; i++) sz--, data[sz].~T(); }
int sz
Definition: Vec.h:40
T * data
Definition: Vec.h:39
#define assert(ex)
Definition: util_old.h:213
template<class T>
void Minisat::vec< T >::shrink_ ( int  nelems)
inline

Definition at line 65 of file Vec.h.

65 { assert(nelems <= sz); sz -= nelems; }
int sz
Definition: Vec.h:40
#define assert(ex)
Definition: util_old.h:213
template<class T>
int Minisat::vec< T >::size ( void  ) const
inline

Definition at line 63 of file Vec.h.

63 { return sz; }
int sz
Definition: Vec.h:40

Field Documentation

template<class T>
int Minisat::vec< T >::cap
private

Definition at line 41 of file Vec.h.

template<class T>
T* Minisat::vec< T >::data
private

Definition at line 39 of file Vec.h.

template<class T>
int Minisat::vec< T >::sz
private

Definition at line 40 of file Vec.h.


The documentation for this class was generated from the following file: