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

Detailed Description

template<class T>
class Gluco::vec< T >

Definition at line 40 of file Vec.h.

Constructor & Destructor Documentation

◆ vec() [1/3]

template<class T>
Gluco::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>
Gluco::vec< T >::vec ( int size)
inlineexplicit

Definition at line 57 of file Vec.h.

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

◆ vec() [3/3]

template<class T>
Gluco::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>
Gluco::vec< T >::~vec ( )
inline

Definition at line 59 of file Vec.h.

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

Member Function Documentation

◆ capacity() [1/2]

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

Definition at line 99 of file Vec.h.

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

◆ capacity() [2/2]

template<class T>
int Gluco::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 Gluco::vec< T >::clear ( bool dealloc = false)

Definition at line 124 of file Vec.h.

124 {
125 if (data != NULL){
126 for (int i = 0; i < sz; i++) data[i].~T();
127 sz = 0;
128 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 Gluco::vec< T >::copyTo ( vec< T > & copy) const
inline

Definition at line 92 of file Vec.h.

92{ 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 Gluco::vec< T >::copyTo_ ( vec< T > & copy) const
inline

Definition at line 93 of file Vec.h.

93{ 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
Here is the caller graph for this function:

◆ growTo() [1/2]

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

Definition at line 116 of file Vec.h.

116 {
117 if (sz >= size) return;
118 capacity(size);
119 for (int i = sz; i < size; i++) new (&data[i]) T();
120 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 Gluco::vec< T >::growTo ( int size,
const T & pad )

Definition at line 108 of file Vec.h.

108 {
109 if (sz >= size) return;
110 capacity(size);
111 for (int i = sz; i < size; i++) data[i] = pad;
112 sz = size; }
Here is the call graph for this function:

◆ last() [1/2]

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

Definition at line 85 of file Vec.h.

85{ return data[sz-1]; }

◆ last() [2/2]

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

Definition at line 84 of file Vec.h.

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

◆ moveTo()

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

Definition at line 94 of file Vec.h.

94{ 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>
Gluco::vec< T >::operator T* ( void )
inline

Definition at line 62 of file Vec.h.

62{ return data; }

◆ operator[]() [1/2]

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

Definition at line 89 of file Vec.h.

89{ return data[index]; }

◆ operator[]() [2/2]

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

Definition at line 88 of file Vec.h.

88{ return data[index]; }

◆ pop()

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

Definition at line 78 of file Vec.h.

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

◆ push() [1/2]

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

Definition at line 76 of file Vec.h.

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

◆ push() [2/2]

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

Definition at line 75 of file Vec.h.

75{ 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 Gluco::vec< T >::push_ ( const T & elem)
inline

Definition at line 77 of file Vec.h.

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

◆ shrink()

template<class T>
void Gluco::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(); }
Here is the caller graph for this function:

◆ shrink_()

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

Definition at line 67 of file Vec.h.

67{ assert(nelems <= sz); sz -= nelems; }

◆ size()

template<class T>
int Gluco::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: