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

#include <vec.h>

Inheritance diagram for vec< T, A, vl_embed >:
Collaboration diagram for vec< T, A, vl_embed >:

Public Types

using pop_ret_type
 

Public Member Functions

unsigned allocated (void) const
 
unsigned length (void) const
 
bool is_empty (void) const
 
Taddress (void)
 
const Taddress (void) const
 
Tbegin ()
 
const Tbegin () const
 
Tend ()
 
const Tend () const
 
const Toperator[] (unsigned) const
 
Toperator[] (unsigned)
 
const Tlast (void) const
 
Tlast (void)
 
bool space (unsigned) const
 
bool iterate (unsigned, T *) const
 
bool iterate (unsigned, T **) const
 
veccopy (ALONE_CXX_MEM_STAT_INFO) const
 
void splice (const vec &)
 
void splice (const vec *src)
 
Tquick_push (const T &)
 
pop_ret_type pop (void)
 
void truncate (unsigned)
 
void quick_insert (unsigned, const T &)
 
void ordered_remove (unsigned)
 
void unordered_remove (unsigned)
 
void block_remove (unsigned, unsigned)
 
void qsort (int(*)(const void *, const void *))
 
void sort (int(*)(const void *, const void *, void *), void *)
 
void stablesort (int(*)(const void *, const void *, void *), void *)
 
Tbsearch (const void *key, int(*compar)(const void *, const void *))
 
Tbsearch (const void *key, int(*compar)(const void *, const void *, void *), void *)
 
unsigned lower_bound (const T &, bool(*)(const T &, const T &)) const
 
bool contains (const T &search) const
 
void embedded_init (unsigned, unsigned=0, unsigned=0)
 
void quick_grow (unsigned len)
 
void quick_grow_cleared (unsigned len)
 

Static Public Member Functions

static size_t embedded_size (unsigned)
 

Data Fields

vec_prefix m_vecpfx
 

Friends

template<typename, typename, typename>
struct vec
 
struct va_gc
 
struct va_gc_atomic
 
struct va_heap
 

Detailed Description

template<typename T, typename A>
struct vec< T, A, vl_embed >
Embeddable vector.  These vectors are suitable to be embedded
in other data structures so that they can be pre-allocated in a
contiguous memory block.

Embeddable vectors are implemented using the trailing array idiom,
thus they are not resizeable without changing the address of the
vector object itself.  This means you cannot have variables or
fields of embeddable vector type -- always use a pointer to a
vector.  The one exception is the final field of a structure, which
could be a vector type.

You will have to use the embedded_size & embedded_init calls to
create such objects, and they will not be resizeable (so the 'safe'
allocation variants are not available).

Properties:

     - The whole vector and control data are allocated in a single
       contiguous block.  It uses the trailing-vector idiom, so
       allocation must reserve enough space for all the elements
       in the vector plus its control data.
     - The vector cannot be re-allocated.
     - The vector cannot grow nor shrink.
     - No indirections needed for access/manipulation.
     - It requires 2 words of storage (prior to vector allocation).   

Member Typedef Documentation

◆ pop_ret_type

template<typename T, typename A>
using vec< T, A, vl_embed >::pop_ret_type
Initial value:
typename std::conditional <std::is_trivially_destructible <T>::value,
T &, void>::type
static struct token T
Definition gengtype-parse.cc:45
Definition gengtype.h:252

Member Function Documentation

◆ address() [1/2]

◆ address() [2/2]

template<typename T, typename A>
const T * vec< T, A, vl_embed >::address ( void ) const
inline

References T.

◆ allocated()

template<typename T, typename A>
unsigned vec< T, A, vl_embed >::allocated ( void ) const
inline

References m_vecpfx.

Referenced by quick_insert().

◆ begin() [1/2]

template<typename T, typename A>
T * vec< T, A, vl_embed >::begin ( )
inline

References address(), and T.

◆ begin() [2/2]

template<typename T, typename A>
const T * vec< T, A, vl_embed >::begin ( ) const
inline

References address(), and T.

◆ block_remove()

template<typename T, typename A>
void vec< T, A, vl_embed >::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.   

References address(), gcc_checking_assert, length(), m_vecpfx, T, and vec.

◆ bsearch() [1/2]

template<typename T, typename A>
T * vec< T, A, vl_embed >::bsearch ( const void * key,
int(* compar )(const void *, const void *) )
inline
Search the contents of the sorted vector with a binary search.
CMP is the comparison function to pass to bsearch.   

References address(), length(), NULL, T, and vec.

◆ bsearch() [2/2]

template<typename T, typename A>
T * vec< T, A, vl_embed >::bsearch ( const void * key,
int(* compar )(const void *, const void *, void *),
void * data )
inline
Search the contents of the sorted vector with a binary search.
CMP is the comparison function to pass to bsearch.   

References address(), length(), NULL, T, and vec.

◆ contains()

template<typename T, typename A>
bool vec< T, A, vl_embed >::contains ( const T & search) const
inline
Return true if SEARCH is an element of V.  Note that this is O(N) in the
size of the vector and so should be used with care.   

References address(), i, length(), T, and vec.

◆ copy()

template<typename T, typename A>
vec< T, A, vl_embed > * vec< T, A, vl_embed >::copy ( ALONE_CXX_MEM_STAT_INFO ) const
inline
Return a pointer to a copy of this vector.   

References address(), ALONE_MEM_STAT_DECL, length(), NULL, PASS_MEM_STAT, vec, vec_alloc(), and vec_copy_construct().

Referenced by vec_safe_copy().

◆ embedded_init()

template<typename T, typename A>
void vec< T, A, vl_embed >::embedded_init ( unsigned alloc,
unsigned num = 0,
unsigned aut = 0 )
inline
Initialize the vector to contain room for ALLOC elements and
NUM active elements.   

References m_vecpfx, and vec.

◆ embedded_size()

template<typename T, typename A>
size_t vec< T, A, vl_embed >::embedded_size ( unsigned alloc)
inlinestatic
Return the number of bytes needed to embed an instance of an
embeddable vec inside another data structure.

Use these methods to determine the required size and initialization
of a vector V of type T embedded within another structure (as the
final member):

size_t vec<T, A, vl_embed>::embedded_size (unsigned alloc);
void v->embedded_init (unsigned alloc, unsigned num);

These allow the caller to perform the memory allocation.   

References T, and vec.

◆ end() [1/2]

template<typename T, typename A>
T * vec< T, A, vl_embed >::end ( )
inline

References address(), length(), and T.

◆ end() [2/2]

template<typename T, typename A>
const T * vec< T, A, vl_embed >::end ( ) const
inline

References address(), length(), and T.

◆ is_empty()

template<typename T, typename A>
bool vec< T, A, vl_embed >::is_empty ( void ) const
inline

References m_vecpfx.

◆ iterate() [1/2]

template<typename T, typename A>
bool vec< T, A, vl_embed >::iterate ( unsigned ix,
T * ptr ) const
inline
Return iteration condition and update *PTR to (a copy of) 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, &val); ix++)
    continue;   

References address(), m_vecpfx, T, and vec.

◆ iterate() [2/2]

template<typename T, typename A>
bool vec< T, A, vl_embed >::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.   

References address(), CONST_CAST, m_vecpfx, T, and vec.

◆ last() [1/2]

template<typename T, typename A>
T & vec< T, A, vl_embed >::last ( void )
inline

References gcc_checking_assert, m_vecpfx, and vec.

◆ last() [2/2]

template<typename T, typename A>
const T & vec< T, A, vl_embed >::last ( void ) const
inline
Get the final element of the vector, which must not be empty.   

References gcc_checking_assert, m_vecpfx, and vec.

Referenced by pop().

◆ length()

template<typename T, typename A>
unsigned vec< T, A, vl_embed >::length ( void ) const
inline

◆ lower_bound()

template<typename T, typename A>
unsigned vec< T, A, vl_embed >::lower_bound ( const T & obj,
bool(* lessthan )(const T &, const T &) ) const
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.   

References address(), length(), T, and vec.

◆ operator[]() [1/2]

template<typename T, typename A>
T & vec< T, A, vl_embed >::operator[] ( unsigned ix)
inline

◆ operator[]() [2/2]

template<typename T, typename A>
const T & vec< T, A, vl_embed >::operator[] ( unsigned ix) const
inline
Index into vector.  Return the IX'th element.  IX must be in the
domain of the vector.   

References address(), gcc_checking_assert, m_vecpfx, and vec.

◆ ordered_remove()

template<typename T, typename A>
void vec< T, A, vl_embed >::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
memmove.  Not suitable for non-trivially copyable types.   

References address(), gcc_checking_assert, length(), m_vecpfx, T, and vec.

◆ pop()

template<typename T, typename A>
vec< T, A, vl_embed >::pop_ret_type vec< T, A, vl_embed >::pop ( void )
inline
Pop and return a reference to the last element off the end of the
vector.  If T has non-trivial destructor, this method just pops
the element and returns void type.   

References address(), gcc_checking_assert, last(), length(), m_vecpfx, T, and vec.

◆ qsort()

template<typename T, typename A>
void vec< T, A, vl_embed >::qsort ( int(* cmp )(const void *, const void *))
inline
Sort the contents of this vector with qsort.  CMP is the comparison
function to pass to qsort.   

References address(), gcc_qsort(), length(), T, and vec.

◆ quick_grow()

template<typename T, typename A>
void vec< T, A, vl_embed >::quick_grow ( unsigned len)
inline
Grow the vector to a specific length.  LEN must be as long or longer than
the current length.  The new elements are uninitialized.   

References gcc_checking_assert, length(), m_vecpfx, and vec.

◆ quick_grow_cleared()

template<typename T, typename A>
void vec< T, A, vl_embed >::quick_grow_cleared ( unsigned len)
inline
Grow the vector to a specific length.  LEN must be as long or longer than
the current length.  The new elements are initialized to zero.   

References address(), gcc_checking_assert, length(), m_vecpfx, vec, and vec_default_construct().

◆ quick_insert()

template<typename T, typename A>
void vec< T, A, vl_embed >::quick_insert ( unsigned ix,
const T & obj )
inline
Insert an element, OBJ, at the IXth position of this vector.  There
must be sufficient space.  This operation is not suitable for non-trivially
copyable types.   

References address(), allocated(), gcc_checking_assert, length(), m_vecpfx, T, and vec.

◆ quick_push()

template<typename T, typename A>
T * vec< T, A, vl_embed >::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.   

References address(), gcc_checking_assert, m_vecpfx, space(), T, and vec.

Referenced by splice().

◆ sort()

template<typename T, typename A>
void vec< T, A, vl_embed >::sort ( int(* cmp )(const void *, const void *, void *),
void * data )
inline
Sort the contents of this vector with qsort.  CMP is the comparison
function to pass to qsort.   

References address(), gcc_sort_r(), length(), T, and vec.

◆ space()

template<typename T, typename A>
bool vec< T, A, vl_embed >::space ( unsigned nelems) const
inline
If this vector has space for NELEMS additional entries, return
true.  You usually only need to use this if you are doing your
own vector reallocation, for instance on an embedded vector.  This
returns true in exactly the same circumstances that vec::reserve
will.   

References m_vecpfx, and vec.

Referenced by quick_push().

◆ splice() [1/2]

template<typename T, typename A>
void vec< T, A, vl_embed >::splice ( const vec< T, A, vl_embed > & )

References vec.

◆ splice() [2/2]

template<typename T, typename A>
void vec< T, A, vl_embed >::splice ( const vec< T, A, vl_embed > * src)

References quick_push(), T, and vec.

◆ stablesort()

template<typename T, typename A>
void vec< T, A, vl_embed >::stablesort ( int(* cmp )(const void *, const void *, void *),
void * data )
inline
Sort the contents of this vector with gcc_stablesort_r.  CMP is the
comparison function to pass to qsort.   

References address(), gcc_stablesort_r(), length(), T, and vec.

◆ truncate()

template<typename T, typename A>
void vec< T, A, vl_embed >::truncate ( unsigned size)
inline
Set the length of the vector to SIZE.  The new length must be less
than or equal to the current length.  This is an O(1) operation.   

References address(), gcc_checking_assert, length(), m_vecpfx, vec, and vec_destruct().

◆ unordered_remove()

template<typename T, typename A>
void vec< T, A, vl_embed >::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.   

References address(), gcc_checking_assert, length(), m_vecpfx, T, and vec.

Friends And Related Symbol Documentation

◆ va_gc

template<typename T, typename A>
friend struct va_gc
friend

Referenced by va_gc_atomic.

◆ va_gc_atomic

template<typename T, typename A>
friend struct va_gc_atomic
friend

References va_gc.

Referenced by va_heap.

◆ va_heap

template<typename T, typename A>
friend struct va_heap
friend

References va_gc_atomic, and va_heap.

Referenced by va_heap.

◆ vec

Field Documentation

◆ m_vecpfx


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