TPIE

2362a60
tpie::internal_vector< T > Class Template Reference

A generic internal vector. More...

#include <tpie/internal_vector.h>

Inherits tpie::internal_stack_vector_base< T, internal_vector< T > >.

Public Types

typedef
internal_stack_vector_base< T,
internal_vector< T > > 
parent_t
 
typedef array< T >::iterator iterator
 
typedef array< T >::const_iterator const_iterator
 
typedef T value_type
 

Public Member Functions

 internal_vector (size_t size=0, tpie::memory_bucket_ref bucket=memory_bucket_ref())
 Construct structure with given capacity. More...
 
 internal_vector (tpie::memory_bucket_ref bucket)
 
T & operator[] (size_t s)
 Element access. No range checking is done. More...
 
const T & operator[] (size_t s) const
 Element access. No range checking is done. More...
 
T & front ()
 Get the first item pushed. Requires !empty(). More...
 
const T & front () const
 Get the first item pushed. Requires !empty(). More...
 
T & back ()
 Get the last item pushed. Requires !empty(). More...
 
const T & back () const
 Get the last item pushed. Requires !empty(). More...
 
T & push_back (const T &val)
 Add an element to the end of the vector. More...
 
T & push_back ()
 If an item was previously popped from this point in the structure, push it to the structure again; otherwise, push the default value. More...
 
void pop_back ()
 Remove the last element from the vector. More...
 
iterator begin ()
 Get an iterator to the beginning of the structure. More...
 
const_iterator begin () const
 Get an iterator to the beginning of the structure. More...
 
iterator end ()
 Get an iterator to the end of the structure. More...
 
const_iterator end () const
 Get an iterator to the end of the structure. More...
 
void resize (size_t size=0)
 Change the capacity of the structure and clear all elements. More...
 
bool empty () const
 Check if no elements are currently pushed to the structure. More...
 
size_t size () const
 Return the number of elements in the data structure. More...
 
void clear ()
 Clear the data structure of all elements. More...
 

Static Public Member Functions

static double memory_coefficient ()
 Return the memory coefficient of the structure. More...
 
static double memory_overhead ()
 Return the memory overhead of the structure. More...
 
static memory_size_type memory_usage (memory_size_type size)
 Return the number of bytes required to create a data structure supporting a given number of elements. More...
 
static memory_size_type memory_fits (memory_size_type memory)
 Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes. More...
 

Protected Attributes

array< T > m_elements
 Element storage. More...
 
size_t m_size
 Number of elements pushed to the structure. More...
 

Detailed Description

template<typename T>
class tpie::internal_vector< T >

A generic internal vector.

Template Parameters
TThe type of items stored in the structure.

Definition at line 37 of file internal_vector.h.

Constructor & Destructor Documentation

template<typename T>
tpie::internal_vector< T >::internal_vector ( size_t  size = 0,
tpie::memory_bucket_ref  bucket = memory_bucket_ref() 
)
inline

Construct structure with given capacity.

If a zero capacity is given (the default), no elements may be pushed to the structure until the structure is resized to a different capacity.

Parameters
sizeCapacity of the structure.

Definition at line 49 of file internal_vector.h.

50  : parent_t(size, bucket){}
size_t size() const
Return the number of elements in the data structure.

Member Function Documentation

template<typename T>
T& tpie::internal_vector< T >::back ( )
inline
template<typename T>
const T& tpie::internal_vector< T >::back ( ) const
inline
template<typename T>
iterator tpie::internal_vector< T >::begin ( )
inline

Get an iterator to the beginning of the structure.

Definition at line 117 of file internal_vector.h.

References tpie::array< T, Allocator >::begin(), and tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements.

117 { return m_elements.begin();}
iterator begin()
Return an iterator to the beginning of the array.
Definition: array.h:307
template<typename T>
const_iterator tpie::internal_vector< T >::begin ( ) const
inline

Get an iterator to the beginning of the structure.

Definition at line 122 of file internal_vector.h.

References tpie::array< T, Allocator >::begin(), and tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements.

122 {return m_elements.begin();}
iterator begin()
Return an iterator to the beginning of the array.
Definition: array.h:307
void tpie::internal_stack_vector_base< T, internal_vector< T > >::clear ( )
inlineinherited

Clear the data structure of all elements.

Definition at line 92 of file internal_stack_vector_base.h.

92 {m_size=0;}
size_t m_size
Number of elements pushed to the structure.
bool tpie::internal_stack_vector_base< T, internal_vector< T > >::empty ( ) const
inlineinherited

Check if no elements are currently pushed to the structure.

Definition at line 82 of file internal_stack_vector_base.h.

82 {return m_size==0;}
size_t m_size
Number of elements pushed to the structure.
template<typename T>
iterator tpie::internal_vector< T >::end ( )
inline

Get an iterator to the end of the structure.

Definition at line 127 of file internal_vector.h.

References tpie::array< T, Allocator >::find(), tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements, and tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size.

127 {return m_elements.find(m_size);}
iterator find(size_t idx)
Return an iterator to the i'th element of the array.
Definition: array.h:167
size_t m_size
Number of elements pushed to the structure.
template<typename T>
const_iterator tpie::internal_vector< T >::end ( ) const
inline

Get an iterator to the end of the structure.

Definition at line 132 of file internal_vector.h.

References tpie::array< T, Allocator >::find(), tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements, and tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size.

132 {return m_elements.find(m_size);}
iterator find(size_t idx)
Return an iterator to the i'th element of the array.
Definition: array.h:167
size_t m_size
Number of elements pushed to the structure.
template<typename T>
T& tpie::internal_vector< T >::front ( )
inline

Get the first item pushed. Requires !empty().

Definition at line 68 of file internal_vector.h.

References tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements.

template<typename T>
const T& tpie::internal_vector< T >::front ( ) const
inline

Get the first item pushed. Requires !empty().

Definition at line 73 of file internal_vector.h.

References tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements.

static double tpie::internal_stack_vector_base< T, internal_vector< T > >::memory_coefficient ( )
inlinestaticinherited

Return the memory coefficient of the structure.

Allocating a structure with n elements will use at most $ \lfloor \mathrm{memory\_coefficient} \cdot n + \mathrm{memory\_overhead} \rfloor $ bytes. This does not include memory overhead incurred if the structure is allocated using new.

Returns
The memory coefficient of the structure.

Definition at line 51 of file internal_stack_vector_base.h.

static double memory_coefficient()
Return the memory coefficient of the structure.
Definition: array.h:393
static memory_size_type tpie::linear_memory_base< internal_vector< T > >::memory_fits ( memory_size_type  memory)
inlinestaticinherited

Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes.

Parameters
memoryThe number of bytes the structure is allowed to occupy
Returns
The number of elements that will fit in the structure

Definition at line 93 of file util.h.

93  {
94  return static_cast<memory_size_type>(
95  floor((memory - child_t::memory_overhead()) / child_t::memory_coefficient()));
96  }
static double tpie::internal_stack_vector_base< T, internal_vector< T > >::memory_overhead ( )
inlinestaticinherited

Return the memory overhead of the structure.

See also
memory_coefficient()
Returns
The memory overhead.

Definition at line 56 of file internal_stack_vector_base.h.

56  {
57  return array<T>::memory_overhead() - sizeof(array<T>) + sizeof(child_t);
58  }
static double memory_overhead()
Return the memory overhead of the structure.
Definition: array.h:400
static memory_size_type tpie::linear_memory_base< internal_vector< T > >::memory_usage ( memory_size_type  size)
inlinestaticinherited

Return the number of bytes required to create a data structure supporting a given number of elements.

Parameters
sizeThe number of elements to support
Returns
The amount of memory required in bytes

Definition at line 81 of file util.h.

81  {
82  return static_cast<memory_size_type>(
83  floor(static_cast<double>(size) * child_t::memory_coefficient() + child_t::memory_overhead()));
84  }
template<typename T>
T& tpie::internal_vector< T >::operator[] ( size_t  s)
inline

Element access. No range checking is done.

Definition at line 58 of file internal_vector.h.

References tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements.

template<typename T>
const T& tpie::internal_vector< T >::operator[] ( size_t  s) const
inline

Element access. No range checking is done.

Definition at line 63 of file internal_vector.h.

References tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements.

template<typename T>
void tpie::internal_vector< T >::pop_back ( )
inline

Remove the last element from the vector.

Iterators are invalidated by this call.

Definition at line 112 of file internal_vector.h.

References tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size.

112 {--m_size;}
size_t m_size
Number of elements pushed to the structure.
template<typename T>
T& tpie::internal_vector< T >::push_back ( const T &  val)
inline

Add an element to the end of the vector.

If size() is equal to the capacity (set in the constructor or in resize()), effects are undefined. resize() is not called implicitly.

Iterators are invalidated by this call.

Parameters
valThe element to add.

Definition at line 94 of file internal_vector.h.

References tpie::internal_vector< T >::back(), tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements, and tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size.

94 {m_elements[m_size++] = val; return back();}
size_t m_size
Number of elements pushed to the structure.
T & back()
Get the last item pushed. Requires !empty().
template<typename T>
T& tpie::internal_vector< T >::push_back ( )
inline

If an item was previously popped from this point in the structure, push it to the structure again; otherwise, push the default value.

Iterators are invalidated by this call.

Parameters
valThe element to add.

Definition at line 105 of file internal_vector.h.

References tpie::internal_vector< T >::back(), and tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size.

105 {++m_size; return back();}
size_t m_size
Number of elements pushed to the structure.
T & back()
Get the last item pushed. Requires !empty().
void tpie::internal_stack_vector_base< T, internal_vector< T > >::resize ( size_t  size = 0)
inlineinherited

Change the capacity of the structure and clear all elements.

Parameters
sizeNew capacity of the structure.

Definition at line 77 of file internal_stack_vector_base.h.

size_t m_size
Number of elements pushed to the structure.
size_t size() const
Return the number of elements in the data structure.
void resize(size_t size, const T &elm)
Change the size of the array.
Definition: array.h:485
size_t tpie::internal_stack_vector_base< T, internal_vector< T > >::size ( ) const
inlineinherited

Return the number of elements in the data structure.

Definition at line 87 of file internal_stack_vector_base.h.

87 {return m_size;}
size_t m_size
Number of elements pushed to the structure.

Member Data Documentation

size_t tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size
protectedinherited

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