TPIE

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

A generic internal stack. More...

#include <tpie/internal_stack.h>

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

Public Types

typedef
internal_stack_vector_base< T,
internal_stack< T > > 
parent_t
 
typedef T value_type
 

Public Member Functions

 internal_stack (size_t size=0)
 Construct structure with given capacity. More...
 
T & top ()
 Return the topmost element on the stack. More...
 
void push (const T &val)
 Add an element to the top of the stack. More...
 
void pop ()
 Remove the topmost element from the stack. 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_stack< T >

A generic internal stack.

Template Parameters
TThe type of items stored in the structure.

Definition at line 37 of file internal_stack.h.

Constructor & Destructor Documentation

template<typename T >
tpie::internal_stack< T >::internal_stack ( size_t  size = 0)
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 45 of file internal_stack.h.

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

Member Function Documentation

void tpie::internal_stack_vector_base< T, internal_stack< T > >::clear ( )
inlineinherited

Clear the data structure of all elements.

Definition at line 92 of file internal_stack_vector_base.h.

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

92 {m_size=0;}
size_t m_size
Number of elements pushed to the structure.
bool tpie::internal_stack_vector_base< T, internal_stack< 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.

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

82 {return m_size==0;}
size_t m_size
Number of elements pushed to the structure.
static double tpie::internal_stack_vector_base< T, internal_stack< 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.

References tpie::array< T, Allocator >::memory_coefficient().

static double memory_coefficient()
Return the memory coefficient of the structure.
Definition: array.h:393
static memory_size_type tpie::linear_memory_base< internal_stack< 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_stack< 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.

References tpie::array< T, Allocator >::memory_overhead().

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_stack< 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 >
void tpie::internal_stack< T >::pop ( )
inline

Remove the topmost element from the stack.

Definition at line 67 of file internal_stack.h.

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

67 {--m_size;}
size_t m_size
Number of elements pushed to the structure.
template<typename T >
void tpie::internal_stack< T >::push ( const T &  val)
inline

Add an element to the top of the stack.

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

Parameters
valThe element to add.

Definition at line 62 of file internal_stack.h.

References tpie::internal_stack_vector_base< T, internal_stack< T > >::m_elements, and tpie::internal_stack_vector_base< T, internal_stack< T > >::m_size.

void tpie::internal_stack_vector_base< T, internal_stack< 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.

References tpie::internal_stack_vector_base< T, child_t >::m_elements, tpie::internal_stack_vector_base< T, child_t >::m_size, tpie::array< T, Allocator >::resize(), and tpie::internal_stack_vector_base< T, child_t >::size().

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_stack< T > >::size ( ) const
inlineinherited

Return the number of elements in the data structure.

Definition at line 87 of file internal_stack_vector_base.h.

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

87 {return m_size;}
size_t m_size
Number of elements pushed to the structure.
template<typename T >
T& tpie::internal_stack< T >::top ( )
inline

Member Data Documentation

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

Element storage.

Definition at line 41 of file internal_stack_vector_base.h.

Referenced by tpie::internal_stack< T >::push(), and tpie::internal_stack< T >::top().

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

Number of elements pushed to the structure.

Definition at line 44 of file internal_stack_vector_base.h.

Referenced by tpie::internal_stack< T >::pop(), tpie::internal_stack< T >::push(), and tpie::internal_stack< T >::top().


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