pstore2
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
pstore::sparse_array< ValueType, BitmapType > Class Template Reference

A sparse array type. More...

#include <sparse_array.hpp>

Classes

class  indices
 

Public Types

using bitmap_type = BitmapType
 
using value_type = ValueType
 
using size_type = std::size_t
 
using reference = value_type &
 
using const_reference = value_type const &
 
using iterator = ValueType *
 
using const_iterator = ValueType const *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

template<typename IteratorIdx , typename IteratorV >
 sparse_array (IteratorIdx first_index, IteratorIdx last_index, IteratorV first_value, IteratorV last_value)
 Constructs a sparse array whose available indices are defined by the iterator range from [first_index,last_index) and the values assigned to those indices are given by [FirstValue, LastValue). More...
 
template<typename IteratorIdx >
 sparse_array (IteratorIdx first_index, IteratorIdx last_index)
 Constructs a sparse array whose available indices are defined by the iterator range from [first_index,last_index) and whose corresponding values are default constructed. More...
 
 sparse_array (sparse_array const &)=delete
 
 sparse_array (sparse_array &&) noexcept=delete
 
sparse_arrayoperator= (sparse_array const &)=delete
 
sparse_arrayoperator= (sparse_array &&) noexcept=delete
 
void fill (ValueType const &value)
 
constexpr std::size_t size_bytes () const
 
void * operator new (std::size_t const, void *const ptr)
 
void operator delete (void *const, void *const)
 
void operator delete (void *const p)
 
Iterators

Returns an iterator to the beginning of the container.

iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator crbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
const_reverse_iterator crend () const
 
indices get_indices () const noexcept
 
Element access
ValueType * data () noexcept
 
ValueType const * data () const noexcept
 
reference operator[] (size_type pos) noexcept
 
const_reference operator[] (size_type pos) const noexcept
 
reference at (size_type pos)
 
const_reference at (size_type pos) const
 
constexpr reference front ()
 Returns a reference to the first element in the container. More...
 
constexpr const_reference front () const
 Returns a reference to the first element in the container. More...
 
constexpr reference back ()
 Returns a reference to the last element in the container. More...
 
constexpr const_reference back () const
 Returns a reference to the last element in the container. More...
 

Static Public Member Functions

template<typename IteratorIdx , typename IteratorV >
static auto make_unique (IteratorIdx first_index, IteratorIdx last_index, IteratorV first_value, IteratorV last_value) -> std::unique_ptr< sparse_array >
 Constructs a sparse_array<> instance where the indices are extracted from an iterator range [first_index, last_index) and the values at each index are given by the range [first_value,last_value). More...
 
template<typename IteratorIdx >
static auto make_unique (IteratorIdx first_index, IteratorIdx last_index, std::initializer_list< ValueType > values) -> std::unique_ptr< sparse_array >
 
template<typename Iterator >
static auto make_unique (Iterator begin, Iterator end) -> std::unique_ptr< sparse_array >
 
static auto make_unique (std::initializer_list< size_type > indices, std::initializer_list< ValueType > values={}) -> std::unique_ptr< sparse_array >
 
static auto make_unique (std::initializer_list< std::pair< size_type, ValueType >> v) -> std::unique_ptr< sparse_array >
 
static constexpr std::size_t size_bytes (std::size_t const num_entries) noexcept
 

Friends

template<typename V , typename B >
bool operator== (sparse_array< V, B > const &lhs, sparse_array< V, B > const &rhs)
 

Capacity

constexpr bool empty () const noexcept
 
constexpr size_type size () const noexcept
 
constexpr bool has_index (size_type pos) const noexcept
 Returns true if the sparse array has an index 'pos'.
 
static constexpr size_type max_size () noexcept
 Returns the maximum number of indices that could be contained by an instance of this sparse_array type. More...
 

Detailed Description

template<typename ValueType, typename BitmapType = std::uint64_t>
class pstore::sparse_array< ValueType, BitmapType >

A sparse array type.

A sparse array implementation which uses a bitmap value (whose type is given by the BitmapType template parameter) to manage the collection of members. Each position in that bitmap represents the presence or absence of a value at the corresponding index. A bitmap value of 1 would mean that a single element at index 0 is present; a bitmap value of 0b101 indices that members 0 and 2 are available. The array members are contiguous. The position of a specific index can be computed as: P(v & ((1 << x) - 1)) where P is the population count function, v is the bitmap-value, and x is the required index.

Constructor & Destructor Documentation

◆ sparse_array() [1/2]

template<typename ValueType , typename BitmapType >
template<typename IteratorIdx , typename IteratorV >
pstore::sparse_array< ValueType, BitmapType >::sparse_array ( IteratorIdx  first_index,
IteratorIdx  last_index,
IteratorV  first_value,
IteratorV  last_value 
)

Constructs a sparse array whose available indices are defined by the iterator range from [first_index,last_index) and the values assigned to those indices are given by [FirstValue, LastValue).

If the number of elements in [first_value, last_value) is less than the number of elements in [first_index,last_index), the remaining values are default-constructed; if it is greater then the remaining values are ignored.

◆ sparse_array() [2/2]

template<typename ValueType , typename BitmapType >
template<typename IteratorIdx >
pstore::sparse_array< ValueType, BitmapType >::sparse_array ( IteratorIdx  first_index,
IteratorIdx  last_index 
)

Constructs a sparse array whose available indices are defined by the iterator range from [first_index,last_index) and whose corresponding values are default constructed.

Member Function Documentation

◆ back() [1/2]

template<typename ValueType, typename BitmapType = std::uint64_t>
constexpr reference pstore::sparse_array< ValueType, BitmapType >::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 ValueType, typename BitmapType = std::uint64_t>
constexpr const_reference pstore::sparse_array< ValueType, BitmapType >::back ( ) const
inline

Returns a reference to the last element in the container.

Calling back() on an empty container is undefined.

◆ front() [1/2]

template<typename ValueType, typename BitmapType = std::uint64_t>
constexpr reference pstore::sparse_array< ValueType, BitmapType >::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 ValueType, typename BitmapType = std::uint64_t>
constexpr const_reference pstore::sparse_array< ValueType, BitmapType >::front ( ) const
inline

Returns a reference to the first element in the container.

Calling front() on an empty container is undefined.

◆ make_unique()

template<typename ValueType , typename BitmapType >
template<typename IteratorIdx , typename IteratorV >
auto pstore::sparse_array< ValueType, BitmapType >::make_unique ( IteratorIdx  first_index,
IteratorIdx  last_index,
IteratorV  first_value,
IteratorV  last_value 
) -> std::unique_ptr<sparse_array>
static

Constructs a sparse_array<> instance where the indices are extracted from an iterator range [first_index, last_index) and the values at each index are given by the range [first_value,last_value).

The number of elements in each range must be the same.

◆ max_size()

template<typename ValueType, typename BitmapType = std::uint64_t>
static constexpr size_type pstore::sparse_array< ValueType, BitmapType >::max_size ( )
inlinestaticnoexcept

Returns the maximum number of indices that could be contained by an instance of this sparse_array type.


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