TPIE

2362a60
tpie::internal_stack_vector_base< T, child_t > Class Template Reference

A base class for a generic internal fixed size stack and vector. More...

#include <tpie/internal_stack_vector_base.h>

Inherits tpie::linear_memory_base< child_t >.

Public Types

typedef T value_type
 

Public Member Functions

 internal_stack_vector_base (size_t size=0, tpie::memory_bucket_ref b=memory_bucket_ref())
 Construct structure with given capacity. 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, typename child_t>
class tpie::internal_stack_vector_base< T, child_t >

A base class for a generic internal fixed size stack and vector.

Template Parameters
TThe type of items stored in the container.
child_tThe subtype of the class (CRTP).

Definition at line 38 of file internal_stack_vector_base.h.

Constructor & Destructor Documentation

template<typename T, typename child_t>
tpie::internal_stack_vector_base< T, child_t >::internal_stack_vector_base ( size_t  size = 0,
tpie::memory_bucket_ref  b = 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 69 of file internal_stack_vector_base.h.

69  :
70  m_elements(size, b), m_size(0) {}
size_t m_size
Number of elements pushed to the structure.
size_t size() const
Return the number of elements in the data structure.
array< T > m_elements
Element storage.

Member Function Documentation

template<typename T, typename child_t>
void tpie::internal_stack_vector_base< T, child_t >::clear ( )
inline

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.
template<typename T, typename child_t>
bool tpie::internal_stack_vector_base< T, child_t >::empty ( ) const
inline

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, typename child_t>
static double tpie::internal_stack_vector_base< T, child_t >::memory_coefficient ( )
inlinestatic

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
template<typename child_t>
static memory_size_type tpie::linear_memory_base< child_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  }
template<typename T, typename child_t>
static double tpie::internal_stack_vector_base< T, child_t >::memory_overhead ( )
inlinestatic

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
template<typename child_t>
static memory_size_type tpie::linear_memory_base< child_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, typename child_t>
void tpie::internal_stack_vector_base< T, child_t >::resize ( size_t  size = 0)
inline

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
array< T > m_elements
Element storage.
template<typename T, typename child_t>
size_t tpie::internal_stack_vector_base< T, child_t >::size ( ) const
inline

Return the number of elements in the data structure.

Definition at line 87 of file internal_stack_vector_base.h.

Referenced by tpie::internal_stack_vector_base< T, internal_stack< T > >::resize().

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

Member Data Documentation

template<typename T, typename child_t>
array<T> tpie::internal_stack_vector_base< T, child_t >::m_elements
protected

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