ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Gluco2::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 prelocate (int ext_cap)
 
void growTo (int size)
 
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 copyTo_ (vec< T > &copy) const
 
void moveTo (vec< T > &dest)
 

Detailed Description

template<class T>
class Gluco2::vec< T >

Definition at line 40 of file Vec.h.

Constructor & Destructor Documentation

◆ vec() [1/3]

template<class T>
Gluco2::vec< T >::vec ( )
inline

Definition at line 56 of file Vec.h.

56: data(NULL) , sz(0) , cap(0) { }

◆ vec() [2/3]

template<class T>
Gluco2::vec< T >::vec ( int size)
inlineexplicit

Definition at line 57 of file Vec.h.

57: data(NULL) , sz(0) , cap(0) { growTo(size); }
void growTo(int size)
Definition Vec.h:126
int size(void) const
Definition Vec.h:65
Here is the call graph for this function:

◆ vec() [3/3]

template<class T>
Gluco2::vec< T >::vec ( int size,
const T & pad )
inline

Definition at line 58 of file Vec.h.

58: data(NULL) , sz(0) , cap(0) { growTo(size, pad); }
Here is the call graph for this function:

◆ ~vec()

template<class T>
Gluco2::vec< T >::~vec ( )
inline

Definition at line 59 of file Vec.h.

59{ clear(true); }
void clear(bool dealloc=false)
Definition Vec.h:141
Here is the call graph for this function:

Member Function Documentation

◆ capacity() [1/2]

template<class T>
void Gluco2::vec< T >::capacity ( int min_cap)

Definition at line 101 of file Vec.h.

101 {
102 if (cap >= min_cap) return;
103 int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2
104 if (add > INT_MAX - cap || (((data = (T*)::realloc((void*)data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM))
106 }
Here is the call graph for this function:

◆ capacity() [2/2]

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

Definition at line 68 of file Vec.h.

68{ return cap; }
Here is the caller graph for this function:

◆ clear()

template<class T>
void Gluco2::vec< T >::clear ( bool dealloc = false)

Definition at line 141 of file Vec.h.

141 {
142 if (data != NULL){
143 for (int i = 0; i < sz; i++) data[i].~T();
144 sz = 0;
145 if (dealloc) free(data), data = NULL, cap = 0; } }
VOID_HACK free()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyTo()

template<class T>
void Gluco2::vec< T >::copyTo ( vec< T > & copy) const
inline

Definition at line 94 of file Vec.h.

94{ copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
Here is the caller graph for this function:

◆ copyTo_()

template<class T>
void Gluco2::vec< T >::copyTo_ ( vec< T > & copy) const
inline

Definition at line 95 of file Vec.h.

95{ copy.shrink_(copy.size()); copy.growTo_(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
void shrink_(int nelems)
Definition Vec.h:67
void growTo_(int size)
Definition Vec.h:134
Here is the caller graph for this function:

◆ growTo() [1/2]

template<class T>
void Gluco2::vec< T >::growTo ( int size)

Definition at line 126 of file Vec.h.

126 {
127 if (sz >= size) return;
128 capacity(size);
129 for (int i = sz; i < size; i++) new (&data[i]) T();
130 sz = size; }
int capacity(void) const
Definition Vec.h:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ growTo() [2/2]

template<class T>
void Gluco2::vec< T >::growTo ( int size,
const T & pad )

Definition at line 118 of file Vec.h.

118 {
119 if (sz >= size) return;
120 capacity(size);
121 for (int i = sz; i < size; i++) data[i] = pad;
122 sz = size; }
Here is the call graph for this function:

◆ growTo_()

template<class T>
void Gluco2::vec< T >::growTo_ ( int size)

Definition at line 134 of file Vec.h.

134 {
135 if (sz >= size) return;
136 capacity(size);
137 sz = size; }
Here is the call graph for this function:

◆ last() [1/2]

template<class T>
T & Gluco2::vec< T >::last ( void )
inline

Definition at line 87 of file Vec.h.

87{ return data[sz-1]; }

◆ last() [2/2]

template<class T>
const T & Gluco2::vec< T >::last ( void ) const
inline

Definition at line 86 of file Vec.h.

86{ return data[sz-1]; }
Here is the caller graph for this function:

◆ moveTo()

template<class T>
void Gluco2::vec< T >::moveTo ( vec< T > & dest)
inline

Definition at line 96 of file Vec.h.

96{ dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator T*()

template<class T>
Gluco2::vec< T >::operator T* ( void )
inline

Definition at line 62 of file Vec.h.

62{ return data; }

◆ operator[]() [1/2]

template<class T>
T & Gluco2::vec< T >::operator[] ( int index)
inline

Definition at line 91 of file Vec.h.

91{ return data[index]; }

◆ operator[]() [2/2]

template<class T>
const T & Gluco2::vec< T >::operator[] ( int index) const
inline

Definition at line 90 of file Vec.h.

90{ return data[index]; }

◆ pop()

template<class T>
void Gluco2::vec< T >::pop ( void )
inline

Definition at line 80 of file Vec.h.

80{ assert(sz > 0); sz--, data[sz].~T(); }
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ prelocate()

template<class T>
void Gluco2::vec< T >::prelocate ( int ext_cap)

Definition at line 109 of file Vec.h.

109 {
110 if (cap >= ext_cap) return;
111 if (ext_cap > INT_MAX || (((data = (T*)::realloc((void*)data, ext_cap * sizeof(T))) == NULL) && errno == ENOMEM))
113 cap = ext_cap;
114 }
Here is the call graph for this function:

◆ push() [1/2]

template<class T>
void Gluco2::vec< T >::push ( const T & elem)
inline

Definition at line 78 of file Vec.h.

78{ if (sz == cap) capacity(sz+1); data[sz++] = elem; }
Here is the call graph for this function:

◆ push() [2/2]

template<class T>
void Gluco2::vec< T >::push ( void )
inline

Definition at line 77 of file Vec.h.

77{ if (sz == cap) capacity(sz+1); new (&data[sz]) T(); sz++; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_()

template<class T>
void Gluco2::vec< T >::push_ ( const T & elem)
inline

Definition at line 79 of file Vec.h.

79{ assert(sz < cap); data[sz++] = elem; }

◆ shrink()

template<class T>
void Gluco2::vec< T >::shrink ( int nelems)
inline

Definition at line 66 of file Vec.h.

66{ assert(nelems <= sz); for (int i = 0; i < nelems; i++) sz--, data[sz].~T(); }

◆ shrink_()

template<class T>
void Gluco2::vec< T >::shrink_ ( int nelems)
inline

Definition at line 67 of file Vec.h.

67{ assert(nelems <= sz); sz -= nelems; }
Here is the caller graph for this function:

◆ size()

template<class T>
int Gluco2::vec< T >::size ( void ) const
inline

Definition at line 65 of file Vec.h.

65{ return sz; }
Here is the caller graph for this function:

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