GCC Middle and Back End API Reference
vec< T, A, vl_ptr > Struct Template Reference

#include <vec.h>

Collaboration diagram for vec< T, A, vl_ptr >:

Public Member Functions

void create (unsigned nelems CXX_MEM_STAT_INFO)
void release (void)
bool exists (void) const
bool is_empty (void) const
unsigned length (void) const
Taddress (void)
const Taddress (void) const
const Toperator[] (unsigned ix) const
bool operator!= (const vec &other) const
bool operator== (const vec &other) const
Toperator[] (unsigned ix)
Tlast (void)
bool space (int nelems) const
bool iterate (unsigned ix, T *p) const
bool iterate (unsigned ix, T **p) const
vec copy (ALONE_CXX_MEM_STAT_INFO) const
bool reserve (unsigned, bool=false CXX_MEM_STAT_INFO)
bool reserve_exact (unsigned CXX_MEM_STAT_INFO)
void splice (vec &)
void safe_splice (vec &CXX_MEM_STAT_INFO)
Tquick_push (const T &)
Tsafe_push (const T &CXX_MEM_STAT_INFO)
Tpop (void)
void truncate (unsigned)
void safe_grow (unsigned CXX_MEM_STAT_INFO)
void safe_grow_cleared (unsigned CXX_MEM_STAT_INFO)
void quick_grow (unsigned)
void quick_grow_cleared (unsigned)
void quick_insert (unsigned, const T &)
void safe_insert (unsigned, const T &CXX_MEM_STAT_INFO)
void ordered_remove (unsigned)
void unordered_remove (unsigned)
void block_remove (unsigned, unsigned)
void qsort (int(*)(const void *, const void *))
unsigned lower_bound (T, bool(*)(const T &, const T &)) const

Data Fields

vec< T, A, vl_embed > * vec_

Friends

template<typename T1 >
void va_stack::alloc (vec< T1, va_stack, vl_ptr > &, unsigned, vec< T1, va_stack, vl_embed > *)

Detailed Description

template<typename T, typename A>
struct vec< T, A, vl_ptr >

Space efficient vector.  These vectors can grow dynamically and are
   allocated together with their control data.  They are suited to be
   included in data structures.  Prior to initial allocation, they
   only take a single word of storage.

   These vectors are implemented as a pointer to an embeddable vector.
   The semantics allow for this pointer to be NULL to represent empty
   vectors.  This way, empty vectors occupy minimal space in the
   structure containing them.

   Properties:

        - The whole vector and control data are allocated in a single
          contiguous block.
        - The whole vector may be re-allocated.
        - Vector data may grow and shrink.
        - Access and manipulation requires a pointer test and
          indirection.
        - It requires 1 word of storage (prior to vector allocation).


   Limitations:

   These vectors must be PODs because they are stored in unions.
   (http://en.wikipedia.org/wiki/Plain_old_data_structures).
   As long as we use C++03, we cannot have constructors nor
   destructors in classes that are stored in unions.   

Member Function Documentation

template<typename T , typename A >
T* vec< T, A, vl_ptr >::address ( void  )
inline
template<typename T , typename A >
const T* vec< T, A, vl_ptr >::address ( void  ) const
inline
template<typename T , typename A >
void vec< T, A, vl_ptr >::block_remove ( unsigned  ix,
unsigned  len 
)
inline
Remove LEN elements starting at the IXth.  Ordering is retained.
   This is an O(N) operation due to memmove.   
template<typename T , typename A >
vec< T, A, vl_ptr > vec< T, A, vl_ptr >::copy ( ALONE_CXX_MEM_STAT_INFO  ) const
inline
Return a copy of this vector.   

References vec< T, A, vl_embed >::copy(), vec_, and vNULL.

template<typename T , typename A >
void vec< T, A, vl_ptr >::create ( unsigned nelems  MEM_STAT_DECL)
inline
Create the internal vector and reserve NELEMS for it.  This is
   exactly like vec::reserve, but the internal vector is
   unconditionally allocated from scratch.  The old one, if it
   existed, is lost.   
template<typename T , typename A >
bool vec< T, A, vl_ptr >::exists ( void  ) const
inline
template<typename T , typename A >
bool vec< T, A, vl_ptr >::is_empty ( void  ) const
inline
template<typename T , typename A >
bool vec< T, A, vl_ptr >::iterate ( unsigned  ix,
T ptr 
) const
inline
Return iteration condition and update PTR to point to the IX'th
   element of this vector.  Use this to iterate over the elements of a
   vector as follows,

     for (ix = 0; v.iterate(ix, &ptr); ix++)
       continue;   
template<typename T , typename A >
bool vec< T, A, vl_ptr >::iterate ( unsigned  ix,
T **  ptr 
) const
inline
Return iteration condition and update *PTR to point to the
   IX'th element of this vector.  Use this to iterate over the
   elements of a vector as follows,

     for (ix = 0; v->iterate(ix, &ptr); ix++)
       continue;

   This variant is for vectors of objects.   
template<typename T , typename A >
T& vec< T, A, vl_ptr >::last ( void  )
inline
template<typename T , typename A >
unsigned vec< T, A, vl_ptr >::length ( void  ) const
inline
template<typename T , typename A >
unsigned vec< T, A, vl_ptr >::lower_bound ( T  obj,
bool(*)(const T &, const T &)  lessthan 
) const
inline
Find and return the first position in which OBJ could be inserted
   without changing the ordering of this vector.  LESSTHAN is a
   function that returns true if the first argument is strictly less
   than the second.   
template<typename T , typename A >
bool vec< T, A, vl_ptr >::operator!= ( const vec< T, A, vl_ptr > &  other) const
inline
template<typename T , typename A >
bool vec< T, A, vl_ptr >::operator== ( const vec< T, A, vl_ptr > &  other) const
inline
template<typename T , typename A >
const T& vec< T, A, vl_ptr >::operator[] ( unsigned  ix) const
inline
template<typename T , typename A >
T& vec< T, A, vl_ptr >::operator[] ( unsigned  ix)
inline
template<typename T , typename A >
void vec< T, A, vl_ptr >::ordered_remove ( unsigned  ix)
inline
Remove an element from the IXth position of this vector.  Ordering of
   remaining elements is preserved.  This is an O(N) operation due to
   a memmove.   
template<typename T , typename A >
T & vec< T, A, vl_ptr >::pop ( void  )
inline
Pop and return the last element off the end of the vector.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::qsort ( int(*)(const void *, const void *)  cmp)
inline
Sort the contents of this vector with qsort.  CMP is the comparison
   function to pass to qsort.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::quick_grow ( unsigned  len)
inline
Same as vec::safe_grow but without reallocation of the internal vector.
   If the vector cannot be extended, a runtime assertion will be triggered.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::quick_grow_cleared ( unsigned  len)
inline
Same as vec::quick_grow_cleared but without reallocation of the
   internal vector. If the vector cannot be extended, a runtime
   assertion will be triggered.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::quick_insert ( unsigned  ix,
const T obj 
)
inline
Insert an element, OBJ, at the IXth position of this vector.  There
   must be sufficient space.   
template<typename T , typename A >
T * vec< T, A, vl_ptr >::quick_push ( const T obj)
inline
Push OBJ (a new element) onto the end of the vector.  There must be
   sufficient space in the vector.  Return a pointer to the slot
   where OBJ was inserted.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::release ( void  )
inline
Free the memory occupied by the embedded vector.   
template<typename T , typename A >
bool vec< T, A, vl_ptr >::reserve ( unsigned  ,
bool  = false CXX_MEM_STAT_INFO 
)
inline
Ensure that the vector has at least RESERVE slots available (if
   EXACT is false), or exactly RESERVE slots available (if EXACT is
   true).

   This may create additional headroom if EXACT is false.

   Note that this can cause the embedded vector to be reallocated.
   Returns true iff reallocation actually occurred.   
template<typename T , typename A >
bool vec< T, A, vl_ptr >::reserve_exact ( unsigned  CXX_MEM_STAT_INFO)
inline
Ensure that this vector has exactly NELEMS slots available.  This
   will not create additional headroom.  Note this can cause the
   embedded vector to be reallocated.  Returns true iff reallocation
   actually occurred.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::safe_grow ( unsigned  CXX_MEM_STAT_INFO)
inline
Grow the vector to a specific length.  LEN must be as long or
   longer than the current length.  The new elements are
   uninitialized.  Reallocate the internal vector, if needed.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::safe_grow_cleared ( unsigned  CXX_MEM_STAT_INFO)
inline
Grow the embedded vector to a specific length.  LEN must be as
   long or longer than the current length.  The new elements are
   initialized to zero.  Reallocate the internal vector, if needed.   

References memset(), and T.

template<typename T , typename A >
void vec< T, A, vl_ptr >::safe_insert ( unsigned  ,
const T CXX_MEM_STAT_INFO 
)
inline
Insert an element, OBJ, at the IXth position of the vector.
   Reallocate the embedded vector, if necessary.   
template<typename T , typename A >
T * vec< T, A, vl_ptr >::safe_push ( const T CXX_MEM_STAT_INFO)
inline
Push a new element OBJ onto the end of this vector.  Reallocates
   the embedded vector, if needed.  Return a pointer to the slot where
   OBJ was inserted.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::safe_splice ( vec< T, A, vl_ptr > &  CXX_MEM_STAT_INFO)
inline
Copy the elements in SRC to the end of this vector as if by memcpy.
   SRC and this vector must be allocated with the same mechanism.
   If there is not enough headroom in this vector, it will be reallocated
   as needed.   

References vec< T, A, vl_embed >::length().

template<typename T , typename A >
bool vec< T, A, vl_ptr >::space ( int  nelems) const
inline
template<typename T , typename A >
void vec< T, A, vl_ptr >::splice ( vec< T, A, vl_ptr > &  )
inline
Copy the elements from SRC to the end of this vector as if by memcpy.
   SRC and this vector must be allocated with the same memory
   allocation mechanism. This vector is assumed to have sufficient
   headroom available.   

References vec_.

template<typename T , typename A >
void vec< T, A, vl_ptr >::truncate ( unsigned  size)
inline
Set the length of the vector to LEN.  The new length must be less
   than or equal to the current length.  This is an O(1) operation.   
template<typename T , typename A >
void vec< T, A, vl_ptr >::unordered_remove ( unsigned  ix)
inline
Remove an element from the IXth position of this vector.  Ordering
   of remaining elements is destroyed.  This is an O(1) operation.   

Friends And Related Function Documentation

template<typename T , typename A >
template<typename T1 >
void va_stack::alloc ( vec< T1, va_stack, vl_ptr > &  ,
unsigned  ,
vec< T1, va_stack, vl_embed > *   
)
friend

Field Documentation

template<typename T , typename A >
vec<T, A, vl_embed>* vec< T, A, vl_ptr >::vec_

Referenced by copy(), and splice().


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