mixedbag 0.0.1
Loading...
Searching...
No Matches
ARo::sparse_vector< T, SizeT, Checked > Class Template Referencefinal

#include <sparse_vector.hxx>

Public Types

using allocator_type = std::pmr::polymorphic_allocator<>
 
using iterator = typename std::pmr::vector< T >::iterator
 
using const_iterator = typename std::pmr::vector< T >::const_iterator
 
using value_type = typename std::pmr::vector< T >::value_type
 
using reference = typename std::pmr::vector< T >::reference
 
using pointer = typename std::pmr::vector< T >::pointer
 
using difference_type = typename std::pmr::vector< T >::difference_type
 
using size_type = SizeT
 

Public Member Functions

 sparse_vector (const sparse_vector &other)=default
 
 sparse_vector (sparse_vector &&other) noexcept=default
 
 sparse_vector (const allocator_type &allocator)
 
 sparse_vector (const sparse_vector &other, const allocator_type &allocator)
 
 sparse_vector (sparse_vector &&other, allocator_type &allocator) noexcept
 
allocator_type get_allocator () const
 
size_type size () const noexcept
 
bool empty () const noexcept
 
sparse_vectoroperator= (const sparse_vector &other)
 
sparse_vectoroperator= (sparse_vector &&other) noexcept
 
template<typename... Args>
reference emplace (size_type index, Args... args)
 
reference insert (size_type index, const value_type &val)
 
void erase (size_type index)
 
void reserve_index (size_type size)
 
void reserve_data (size_type size)
 
const value_type & operator[] (size_type index) const
 
value_type & operator[] (size_type index)
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
auto operator<=> (const sparse_vector &other) const noexcept -> std::compare_three_way_result_t< value_type >
 
bool operator== (const sparse_vector &other) const noexcept
 

Detailed Description

template<typename T, typename SizeT = std::size_t, bool Checked = true>
class ARo::sparse_vector< T, SizeT, Checked >

sparse_vector is a container for storing index value pairs, intended for fast unordered iteration of the values.

The power of this kind of container is that you get very fast unordered iteration over the values, since they are stored in a contiguous vector.

Note
This is really an associative container, so the name is a bit misleading, but it is what this kind of container is referred to if you search for it.
Template Parameters
TThe type of elements to store in the sparse_vector
SizeTThe size type - it defaults to std::size_t, but if you know the upper bounds on the index it might make sense to use a smaller type that fits (since you can never have more elements than you can index).
CheckedEnable bounds checking if true.

Member Function Documentation

◆ begin()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
iterator ARo::sparse_vector< T, SizeT, Checked >::begin ( )
inlinenoexcept

Iteration

◆ cbegin()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
const_iterator ARo::sparse_vector< T, SizeT, Checked >::cbegin ( ) const
inlinenoexcept

Iteration

◆ cend()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
const_iterator ARo::sparse_vector< T, SizeT, Checked >::cend ( ) const
inlinenoexcept

Iteration

◆ emplace()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
template<typename... Args>
reference ARo::sparse_vector< T, SizeT, Checked >::emplace ( size_type  index,
Args...  args 
)
inline

Inserts an element at the specified index by constructing it in place, and returns it by reference

◆ empty()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
bool ARo::sparse_vector< T, SizeT, Checked >::empty ( ) const
inlinenoexcept

Check for emptiness

◆ end()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
iterator ARo::sparse_vector< T, SizeT, Checked >::end ( )
inlinenoexcept

Iteration

◆ erase()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
void ARo::sparse_vector< T, SizeT, Checked >::erase ( size_type  index)
inline

Removes the element at the specified index

◆ get_allocator()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
allocator_type ARo::sparse_vector< T, SizeT, Checked >::get_allocator ( ) const
inline

Returns the allocator in use

◆ insert()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
reference ARo::sparse_vector< T, SizeT, Checked >::insert ( size_type  index,
const value_type &  val 
)
inline

Inserts an element at the specified index by copy, and returns it by reference

◆ operator<=>()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
auto ARo::sparse_vector< T, SizeT, Checked >::operator<=> ( const sparse_vector< T, SizeT, Checked > &  other) const -> std::compare_three_way_result_t<value_type>
inlinenoexcept

Comparison

Warning
Comparing sparse_vectors is slow, and should be avoided

◆ operator=() [1/2]

template<typename T , typename SizeT = std::size_t, bool Checked = true>
sparse_vector & ARo::sparse_vector< T, SizeT, Checked >::operator= ( const sparse_vector< T, SizeT, Checked > &  other)
inline

Assignment

◆ operator=() [2/2]

template<typename T , typename SizeT = std::size_t, bool Checked = true>
sparse_vector & ARo::sparse_vector< T, SizeT, Checked >::operator= ( sparse_vector< T, SizeT, Checked > &&  other)
inlinenoexcept

Assignment

◆ operator==()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
bool ARo::sparse_vector< T, SizeT, Checked >::operator== ( const sparse_vector< T, SizeT, Checked > &  other) const
inlinenoexcept

Comparison

Warning
Comparing sparse_vectors is slow, and should be avoided

◆ operator[]() [1/2]

template<typename T , typename SizeT = std::size_t, bool Checked = true>
value_type & ARo::sparse_vector< T, SizeT, Checked >::operator[] ( size_type  index)
inline

Element access

◆ operator[]() [2/2]

template<typename T , typename SizeT = std::size_t, bool Checked = true>
const value_type & ARo::sparse_vector< T, SizeT, Checked >::operator[] ( size_type  index) const
inline

Element access

◆ reserve_data()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
void ARo::sparse_vector< T, SizeT, Checked >::reserve_data ( size_type  size)
inline

Allows increasing the capacity of the internal storage, to prevent unnecessary allocation

◆ reserve_index()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
void ARo::sparse_vector< T, SizeT, Checked >::reserve_index ( size_type  size)
inline

Allows increasing the capacity of the internal storage, to prevent unnecessary allocation

◆ size()

template<typename T , typename SizeT = std::size_t, bool Checked = true>
size_type ARo::sparse_vector< T, SizeT, Checked >::size ( ) const
inlinenoexcept

Returns the number of elements


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