pstore2
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign > Class Template Reference

Chunked-sequence is a sequence-container which uses a list of large blocks ("chunks") to ensure very fast append times at the expense of only permitting bi-directional iterators: random access is not supported, unlike std::deque<> or std::vector<>. More...

#include <chunked_sequence.hpp>

Classes

class  chunk
 

Public Types

using value_type = T
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using reference = value_type &
 
using const_reference = value_type const &
 
using pointer = T *
 
using const_pointer = T const *
 
using iterator = iterator_base< false >
 
using const_iterator = iterator_base< true >
 
using chunk_list = std::list< chunk >
 

Public Member Functions

 chunked_sequence (chunked_sequence const &)=delete
 
 chunked_sequence (chunked_sequence &&other) noexcept
 
chunked_sequenceoperator= (chunked_sequence const &other) noexcept=delete
 
chunked_sequenceoperator= (chunked_sequence &&other) noexcept
 
constexpr bool empty () const noexcept
 
constexpr size_type size () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
chunk_list::iterator chunks_begin () noexcept
 
chunk_list::const_iterator chunks_begin () const noexcept
 
chunk_list::const_iterator chunks_cbegin () noexcept
 
chunk_list::iterator chunks_end () noexcept
 
chunk_list::const_iterator chunks_end () const noexcept
 
chunk_list::const_iterator chunks_cend () noexcept
 
std::size_t chunks_size () const noexcept
 
void clear ()
 
void reserve (std::size_t const)
 
std::size_t capacity () const noexcept
 Returns the number of elements that the container has currently allocated space for. More...
 
void resize (size_type count)
 Resizes the container to contain count elements. More...
 
template<typename... Args>
reference emplace_back (Args &&... args)
 
reference push_back (T const &value)
 
reference push_back (T &&value)
 
reference front ()
 Returns a reference to the first element in the container. More...
 
const_reference front () const
 Returns a reference to the first element in the container. More...
 
reference back ()
 Returns a reference to the last element in the container. More...
 
const_reference back () const
 Returns a reference to the last element in the container. More...
 
void swap (chunked_sequence &other) noexcept
 
void splice (chunked_sequence &&other)
 
template<typename... Args>
auto emplace_back (Args &&... args) -> reference
 

Static Public Attributes

static constexpr std::size_t elements_per_chunk = ElementsPerChunk
 The number of elements in an individual chunk.
 

Detailed Description

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
class pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >

Chunked-sequence is a sequence-container which uses a list of large blocks ("chunks") to ensure very fast append times at the expense of only permitting bi-directional iterators: random access is not supported, unlike std::deque<> or std::vector<>.

Each chunk has storage for a number of objects. This number is a compile-time constant and is usually reasonably large and chosen so that the memory required is a multiple of the VM page size. Appending is performed in amortized constant time where we either bump a pointer in an existing chunk or allocate a new one. Unlike std::vector<>, no moving or copying occurs after append, and only the past-the-end iterator is invalidated.

Template Parameters
TThe type of the elements.
ElementsPerChunkThe number of elements in an individual chunk.
ActualSizeThe storage allocated to an individual element. Normally equal to sizeof(T), this can be increased to allow for dynamically-sized types.
ActualAlignThe alignment of an individual element. Normally equal to alignof(T).

Member Function Documentation

◆ back() [1/2]

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
reference pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >::back ( )
inline

Returns a reference to the last element in the container.

Calling back on an empty container is undefined.

◆ back() [2/2]

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
const_reference pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >::back ( ) const
inline

Returns a reference to the last element in the container.

Calling back on an empty container is undefined.

◆ capacity()

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
std::size_t pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >::capacity ( ) const
inlinenoexcept

Returns the number of elements that the container has currently allocated space for.

Returns
Capacity of the currently allocated storage.

◆ front() [1/2]

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
reference pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >::front ( )
inline

Returns a reference to the first element in the container.

Calling front on an empty container is undefined.

◆ front() [2/2]

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
const_reference pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >::front ( ) const
inline

Returns a reference to the first element in the container.

Calling front on an empty container is undefined.

◆ resize()

template<typename T, std::size_t ElementsPerChunk = std::max (4096 / sizeof (T), std::size_t{1}), std::size_t ActualSize = sizeof (T), std::size_t ActualAlign = alignof (T)>
void pstore::chunked_sequence< T, ElementsPerChunk, ActualSize, ActualAlign >::resize ( size_type  count)
inline

Resizes the container to contain count elements.

If the current size is greater than count, the container is reduced to its first count elements. If the current size is less than count, additional default-inserted elements are appended.

Parameters
countThe new size of the container.

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