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

#include <vec.h>

Collaboration diagram for vec< T, va_heap, 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
bool using_auto_storage () const

Data Fields

vec< T, va_heap, vl_embed > * m_vec

Detailed Description

template<typename T>
struct vec< T, va_heap, 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 >
T* vec< T, va_heap, vl_ptr >::address ( void  )
inline
template<typename T >
const T* vec< T, va_heap, vl_ptr >::address ( void  ) const
inline
template<typename T >
void vec< T, va_heap, 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 >
vec< T, va_heap, vl_ptr > vec< T, va_heap, vl_ptr >::copy ( ALONE_CXX_MEM_STAT_INFO  ) const
inline
   Return a copy of this vector.  
template<typename T >
void vec< T, va_heap, vl_ptr >::create ( unsigned nelems  MEM_STAT_DECL)
inline
     Memory allocation and deallocation for the embedded vector.
     Needed because we cannot have proper ctors/dtors defined.  
   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 >
bool vec< T, va_heap, vl_ptr >::exists ( void  ) const
inline
     Vector operations.  
template<typename T >
bool vec< T, va_heap, vl_ptr >::is_empty ( void  ) const
inline
template<typename T >
bool vec< T, va_heap, 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;  

References va_heap::reserve().

template<typename T >
bool vec< T, va_heap, 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 >
T& vec< T, va_heap, vl_ptr >::last ( void  )
inline
template<typename T >
unsigned vec< T, va_heap, vl_ptr >::length ( void  ) const
inline
template<typename T >
unsigned vec< T, va_heap, 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 >
bool vec< T, va_heap, vl_ptr >::operator!= ( const vec< T, va_heap, vl_ptr > &  other) const
inline
template<typename T >
bool vec< T, va_heap, vl_ptr >::operator== ( const vec< T, va_heap, vl_ptr > &  other) const
inline
template<typename T >
const T& vec< T, va_heap, vl_ptr >::operator[] ( unsigned  ix) const
inline
template<typename T >
T& vec< T, va_heap, vl_ptr >::operator[] ( unsigned  ix)
inline
template<typename T >
void vec< T, va_heap, 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 >
T & vec< T, va_heap, vl_ptr >::pop ( void  )
inline
   Pop and return the last element off the end of the vector.  
template<typename T >
void vec< T, va_heap, 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 >
void vec< T, va_heap, 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 >
void vec< T, va_heap, 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 >
void vec< T, va_heap, 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 >
T * vec< T, va_heap, 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 >
void vec< T, va_heap, vl_ptr >::release ( void  )
inline
   Free the memory occupied by the embedded vector.  
template<typename T >
bool vec< T, va_heap, 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.  
     For now play a game with va_heap::reserve to hide our auto storage if any,
     this is necessary because it doesn't have enough information to know the
     embedded vector is in auto storage, and so should not be freed.  
template<typename T >
bool vec< T, va_heap, 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 >
void vec< T, va_heap, 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 >
void vec< T, va_heap, 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.  
template<typename T >
void vec< T, va_heap, 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 >
T * vec< T, va_heap, 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 >
void vec< T, va_heap, vl_ptr >::safe_splice ( vec< T, va_heap, 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.  
template<typename T >
bool vec< T, va_heap, vl_ptr >::space ( int  nelems) const
inline

References vec_alloc().

template<typename T >
void vec< T, va_heap, vl_ptr >::splice ( vec< T, va_heap, 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 memset(), and T.

template<typename T >
void vec< T, va_heap, 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 >
void vec< T, va_heap, 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.  
template<typename T >
bool vec< T, va_heap, vl_ptr >::using_auto_storage ( ) const
inline

Field Documentation

template<typename T >
vec<T, va_heap, vl_embed>* vec< T, va_heap, vl_ptr >::m_vec
     FIXME - This field should be private, but we need to cater to
             compilers that have stricter notions of PODness for types.  

Referenced by vec_free().


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