TPIE

11a2c2d
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 constexpr memory_size_type memory_usage (memory_size_type size) noexcept
 Return the number of bytes required to create a data structure supporting a given number of elements. More...
 
static constexpr linear_memory_usage memory_usage () noexcept
 
static constexpr memory_size_type memory_fits (memory_size_type memory) noexcept
 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

◆ internal_vector()

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){}

Member Function Documentation

◆ back() [1/2]

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

◆ back() [2/2]

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

◆ begin() [1/2]

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

Get an iterator to the beginning of the structure.

Definition at line 115 of file internal_vector.h.

115 { return m_elements.begin();}

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

◆ begin() [2/2]

template<typename T >
const_iterator tpie::internal_vector< T >::begin ( ) const
inline

Get an iterator to the beginning of the structure.

Definition at line 120 of file internal_vector.h.

120 {return m_elements.begin();}

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

◆ clear()

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;}

◆ empty()

bool tpie::internal_stack_vector_base< T, internal_vector< T > >::empty
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;}

◆ end() [1/2]

template<typename T >
iterator tpie::internal_vector< T >::end ( )
inline

◆ end() [2/2]

template<typename T >
const_iterator tpie::internal_vector< T >::end ( ) const
inline

◆ front() [1/2]

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.

68 {return m_elements[0];}

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

◆ front() [2/2]

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.

73 {return m_elements[0];}

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

◆ memory_coefficient()

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.

◆ memory_fits()

static constexpr memory_size_type tpie::linear_memory_base< internal_vector< T > >::memory_fits ( memory_size_type  memory)
inlinestaticconstexprnoexceptinherited

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 118 of file util.h.

118  {
119  return static_cast<memory_size_type>(
120  floor((memory - child_t::memory_overhead()) / child_t::memory_coefficient()));
121  }

◆ memory_overhead()

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  }

◆ memory_usage()

static constexpr memory_size_type tpie::linear_memory_base< internal_vector< T > >::memory_usage ( memory_size_type  size)
inlinestaticconstexprnoexceptinherited

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 106 of file util.h.

106  {
107  return static_cast<memory_size_type>(
108  floor(static_cast<double>(size) * child_t::memory_coefficient() + child_t::memory_overhead()));
109  }

◆ operator[]() [1/2]

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.

58 {return m_elements[s];}

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

◆ operator[]() [2/2]

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.

63 {return m_elements[s];}

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

◆ pop_back()

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 110 of file internal_vector.h.

110 {--m_size;}

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

◆ push_back() [1/2]

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.

Definition at line 103 of file internal_vector.h.

103 {++m_size; return back();}

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

◆ push_back() [2/2]

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.

94 {m_elements[m_size++] = val; return back();}

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.

◆ resize()

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()

size_t tpie::internal_stack_vector_base< T, internal_vector< T > >::size
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;}

Member Data Documentation

◆ m_elements

array<T> tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements
protectedinherited

Element storage.

Definition at line 41 of file internal_stack_vector_base.h.

◆ m_size

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

Number of elements pushed to the structure.

Definition at line 44 of file internal_stack_vector_base.h.


The documentation for this class was generated from the following file:
tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size
size_t m_size
Number of elements pushed to the structure.
Definition: internal_stack_vector_base.h:44
tpie::array::begin
iterator begin()
Return an iterator to the beginning of the array.
Definition: array.h:312
tpie::array< T >::memory_overhead
static constexpr double memory_overhead() noexcept
Return the memory overhead of the structure.
Definition: array.h:405
tpie::internal_vector::back
T & back()
Get the last item pushed. Requires !empty().
Definition: internal_vector.h:78
tpie::array::find
iterator find(size_t idx)
Return an iterator to the i'th element of the array.
Definition: array.h:172
tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements
array< T > m_elements
Element storage.
Definition: internal_stack_vector_base.h:41
tpie::array< T >::memory_coefficient
static constexpr double memory_coefficient() noexcept
Return the memory coefficient of the structure.
Definition: array.h:398
tpie::array::resize
void resize(size_t size, const T &elm)
Change the size of the array.
Definition: array.h:490
tpie::internal_stack_vector_base< T, internal_vector< T > >::size
size_t size() const
Return the number of elements in the data structure.
Definition: internal_stack_vector_base.h:87