Stride Reference Manual  - generated for commit 9643b11
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
stride::util::SegmentedVector< T, N, Safe > Class Template Reference

Container that stores objects "almost contiguously" (in a chain of blocks) and guarantees that pointers/iterators are not invalidated when the container grows. More...

#include <SegmentedVector.h>

Inheritance diagram for stride::util::SegmentedVector< T, N, Safe >:
Inheritance graph
Collaboration diagram for stride::util::SegmentedVector< T, N, Safe >:
Collaboration graph

Public Types

using value_type = T
 
using size_type = std::size_t
 
using self_type = SegmentedVector< T, N >
 
using iterator = SVIterator< T, N, Safe, T *, T &, false >
 
using const_iterator = SVIterator< T, N, Safe >
 

Public Member Functions

 SegmentedVector ()
 Construct empty SegmentedVector. More...
 
 SegmentedVector (size_type i)
 Construct with given number of elements but DO NOT INITIALIZE them. More...
 
 SegmentedVector (size_type i, const value_type &value)
 Construct with given number of elements and INITIALIZE them with value. More...
 
 SegmentedVector (const self_type &other)
 Copy constructor. More...
 
 SegmentedVector (self_type &&other) noexcept
 Move constructor. More...
 
SegmentedVectoroperator= (const self_type &other)
 Copy assignment. More...
 
SegmentedVectoroperator= (self_type &&other) noexcept
 Move assignment. More...
 
 ~SegmentedVector ()
 Destructor. More...
 
T & at (std::size_t pos)
 Access specified element with bounds checking. More...
 
const T & at (std::size_t pos) const
 Access specified element with bounds checking. More...
 
T & back ()
 Access the last element. More...
 
const T & back () const
 Access the last element. More...
 
T & operator[] (size_t pos)
 Access specified element (no bounds checking). More...
 
const T & operator[] (size_t pos) const
 Access specified element (no bounds checking). More...
 
iterator begin ()
 Returns an iterator to the beginning of the container. More...
 
const_iterator begin () const
 Returns a const_iterator to the beginning of the container. More...
 
const_iterator cbegin () const
 Returns a const_iterator to the beginning of the container. More...
 
iterator end ()
 Returns an iterator to the end of the container. More...
 
const_iterator end () const
 Returns a const_iterator to the end of the container. More...
 
const_iterator cend () const
 Returns a const_iterator to the end. More...
 
std::size_t capacity () const
 Returns number of elements that can be stored without allocating additional blocks. More...
 
bool empty () const
 Checks whether container is empty. More...
 
std::size_t get_block_count () const
 Returns number of currently allocated blocks. More...
 
std::size_t get_elements_per_block () const
 Returns number of elements block (template parameter 'N'). More...
 
std::size_t size () const
 Returns the number of elements. More...
 
void resize (size_type new_size)
 Increases the number of elements (but DOES NOT INITIALIZE the additional elements) or pops elements (and DOES RUN those element's destructor). More...
 
void resize (size_type new_size, const value_type &value)
 
void clear ()
 Clears the content. More...
 
template<class... Args>
T * emplace (size_type pos, Args &&...args)
 Constructs element in-place at position pos. More...
 
template<class... Args>
T * emplace_back (Args &&...args)
 Constructs element in-place at the end. More...
 
void pop_back ()
 Removes the last element. More...
 
T * push_back (const T &obj)
 Adds element to end. More...
 
T * push_back (T &&obj)
 Adds element to end. More...
 

Private Types

using Chunk = typename std::aligned_storage< sizeof(T), std::alignment_of< T >::value >::type
 POD type with same alignment requirement as for T's. More...
 

Private Member Functions

T * get_chunk ()
 Get next available chunk for element construction with placement new. More...
 

Private Attributes

std::vector< Chunk * > m_blocks
 Vector registers pointers to blocks of chunks. More...
 
size_t m_size
 Index of first free chunk when indexed contiguously. More...
 

Friends

class SVIterator< T, N, Safe >
 
class SVIterator< T, N, Safe, T *, T &, false >
 

Detailed Description

template<typename T, size_t N = 512, bool Safe = true>
class stride::util::SegmentedVector< T, N, Safe >

Container that stores objects "almost contiguously" (in a chain of blocks) and guarantees that pointers/iterators are not invalidated when the container grows.

Elements are assigned to the container either sequentially through push_back and emplace_back or through direct adressing with emplace, at or the subscript operator. It supports most familiar operators except reserve (no need for advance reservation of capacity to avoid re-allocation that invalidates pointers as in std::vector) and insertion/deletion.

Template parameters: T type of elements stored in the container N block size i.e. number of elements per block

Definition at line 53 of file SegmentedVector.h.

Member Typedef Documentation

template<typename T, size_t N = 512, bool Safe = true>
using stride::util::SegmentedVector< T, N, Safe >::value_type = T

Definition at line 59 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
using stride::util::SegmentedVector< T, N, Safe >::size_type = std::size_t

Definition at line 60 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
using stride::util::SegmentedVector< T, N, Safe >::self_type = SegmentedVector<T, N>

Definition at line 61 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
using stride::util::SegmentedVector< T, N, Safe >::iterator = SVIterator<T, N, Safe, T*, T&, false>

Definition at line 62 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
using stride::util::SegmentedVector< T, N, Safe >::const_iterator = SVIterator<T, N, Safe>

Definition at line 63 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
using stride::util::SegmentedVector< T, N, Safe >::Chunk = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type
private

POD type with same alignment requirement as for T's.

Definition at line 335 of file SegmentedVector.h.

Constructor & Destructor Documentation

template<typename T, size_t N = 512, bool Safe = true>
stride::util::SegmentedVector< T, N, Safe >::SegmentedVector ( )
inlineexplicit

Construct empty SegmentedVector.

CAVEAT: if you resize itbut do not subsequently initialize all elements, the SegmentedVector destructor or a call to clear will cause a segmentation fault because of the destructor call on unitilialezed elements.

Definition at line 73 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
stride::util::SegmentedVector< T, N, Safe >::SegmentedVector ( size_type  i)
inlineexplicit

Construct with given number of elements but DO NOT INITIALIZE them.

CAVEAT: if you resize (as you do here) but do not subsequently initialize all elements, the SegmentedVector destructor or a call to clear will cause a segmentation fault because of the destructor call on unitilialezed elements.

Definition at line 79 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
stride::util::SegmentedVector< T, N, Safe >::SegmentedVector ( size_type  i,
const value_type value 
)
inlineexplicit

Construct with given number of elements and INITIALIZE them with value.

CAVEAT: if you resize (as you do here) but do not subsequently initialize all elements, the SegmentedVector destructor or a call to clear will cause a segmentation fault because of the destructor call on unitilialezed elements.

Definition at line 85 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
stride::util::SegmentedVector< T, N, Safe >::SegmentedVector ( const self_type other)
inlineexplicit

Copy constructor.

Definition at line 88 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
stride::util::SegmentedVector< T, N, Safe >::SegmentedVector ( self_type &&  other)
inlineexplicitnoexcept

Move constructor.

Definition at line 98 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
stride::util::SegmentedVector< T, N, Safe >::~SegmentedVector ( )
inline

Destructor.

Definition at line 129 of file SegmentedVector.h.

Member Function Documentation

template<typename T, size_t N = 512, bool Safe = true>
SegmentedVector& stride::util::SegmentedVector< T, N, Safe >::operator= ( const self_type other)
inline

Copy assignment.

Definition at line 104 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
SegmentedVector& stride::util::SegmentedVector< T, N, Safe >::operator= ( self_type &&  other)
inlinenoexcept

Move assignment.

Definition at line 118 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
T& stride::util::SegmentedVector< T, N, Safe >::at ( std::size_t  pos)
inline

Access specified element with bounds checking.

Definition at line 136 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::pop_back().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
const T& stride::util::SegmentedVector< T, N, Safe >::at ( std::size_t  pos) const
inline

Access specified element with bounds checking.

Definition at line 145 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
T& stride::util::SegmentedVector< T, N, Safe >::back ( )
inline

Access the last element.

Definition at line 154 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
const T& stride::util::SegmentedVector< T, N, Safe >::back ( ) const
inline

Access the last element.

Definition at line 157 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
T& stride::util::SegmentedVector< T, N, Safe >::operator[] ( size_t  pos)
inline

Access specified element (no bounds checking).

Definition at line 163 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
const T& stride::util::SegmentedVector< T, N, Safe >::operator[] ( size_t  pos) const
inline

Access specified element (no bounds checking).

Definition at line 166 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
iterator stride::util::SegmentedVector< T, N, Safe >::begin ( )
inline

Returns an iterator to the beginning of the container.

Definition at line 176 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
const_iterator stride::util::SegmentedVector< T, N, Safe >::begin ( ) const
inline

Returns a const_iterator to the beginning of the container.

Definition at line 179 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
const_iterator stride::util::SegmentedVector< T, N, Safe >::cbegin ( ) const
inline

Returns a const_iterator to the beginning of the container.

Definition at line 182 of file SegmentedVector.h.

Referenced by stride::util::operator==().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
iterator stride::util::SegmentedVector< T, N, Safe >::end ( )
inline

Returns an iterator to the end of the container.

Definition at line 185 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::begin(), and stride::util::SegmentedVector< Person, 2048 >::cbegin().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
const_iterator stride::util::SegmentedVector< T, N, Safe >::end ( ) const
inline

Returns a const_iterator to the end of the container.

Definition at line 188 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
const_iterator stride::util::SegmentedVector< T, N, Safe >::cend ( ) const
inline

Returns a const_iterator to the end.

Definition at line 191 of file SegmentedVector.h.

Referenced by stride::util::operator==().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
std::size_t stride::util::SegmentedVector< T, N, Safe >::capacity ( ) const
inline

Returns number of elements that can be stored without allocating additional blocks.

Definition at line 198 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::resize().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
bool stride::util::SegmentedVector< T, N, Safe >::empty ( ) const
inline

Checks whether container is empty.

Definition at line 201 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
std::size_t stride::util::SegmentedVector< T, N, Safe >::get_block_count ( ) const
inline

Returns number of currently allocated blocks.

Definition at line 204 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::resize().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
std::size_t stride::util::SegmentedVector< T, N, Safe >::get_elements_per_block ( ) const
inline

Returns number of elements block (template parameter 'N').

Definition at line 207 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
std::size_t stride::util::SegmentedVector< T, N, Safe >::size ( ) const
inline
template<typename T, size_t N = 512, bool Safe = true>
void stride::util::SegmentedVector< T, N, Safe >::resize ( size_type  new_size)
inline

Increases the number of elements (but DOES NOT INITIALIZE the additional elements) or pops elements (and DOES RUN those element's destructor).

CAVEAT: if you resize (as you do here) but do not subsequently initialize all elements, the SegmentedVector destructor or a call to clear will cause a segmentation fault because of the destructor call on unitilialezed elements.

Definition at line 221 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::resize(), and stride::util::SegmentedVector< Person, 2048 >::SegmentedVector().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
void stride::util::SegmentedVector< T, N, Safe >::resize ( size_type  new_size,
const value_type value 
)
inline

Definition at line 252 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
void stride::util::SegmentedVector< T, N, Safe >::clear ( )
inline

Clears the content.

Definition at line 266 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::operator=(), and stride::util::SegmentedVector< Person, 2048 >::~SegmentedVector().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
template<class... Args>
T* stride::util::SegmentedVector< T, N, Safe >::emplace ( size_type  pos,
Args &&...  args 
)
inline

Constructs element in-place at position pos.

Definition at line 284 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
template<class... Args>
T* stride::util::SegmentedVector< T, N, Safe >::emplace_back ( Args &&...  args)
inline

Constructs element in-place at the end.

Definition at line 293 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
void stride::util::SegmentedVector< T, N, Safe >::pop_back ( )
inline

Removes the last element.

Definition at line 300 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::resize().

Here is the caller graph for this function:

template<typename T, size_t N = 512, bool Safe = true>
T* stride::util::SegmentedVector< T, N, Safe >::push_back ( const T &  obj)
inline
template<typename T, size_t N = 512, bool Safe = true>
T* stride::util::SegmentedVector< T, N, Safe >::push_back ( T &&  obj)
inline

Adds element to end.

Definition at line 327 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
T* stride::util::SegmentedVector< T, N, Safe >::get_chunk ( )
inlineprivate

Get next available chunk for element construction with placement new.

Definition at line 343 of file SegmentedVector.h.

Referenced by stride::util::SegmentedVector< Person, 2048 >::emplace_back(), and stride::util::SegmentedVector< Person, 2048 >::push_back().

Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename T, size_t N = 512, bool Safe = true>
friend class SVIterator< T, N, Safe >
friend

Definition at line 338 of file SegmentedVector.h.

template<typename T, size_t N = 512, bool Safe = true>
friend class SVIterator< T, N, Safe, T *, T &, false >
friend

Definition at line 339 of file SegmentedVector.h.

Member Data Documentation


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