libhatchet
Loading...
Searching...
No Matches
hxslot_map< T, table_size_bits_ > Class Template Reference

#include <hxslot_map.hpp>

Public Types

using iterator = T*
using const_iterator = const T*
using value_t = T

Public Member Functions

 hxslot_map (void)
 ~hxslot_map ()
template<typename self_t_, typename callable_t_>
auto and_then (this self_t_ &&self_, hxhandle_t handle_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>
const T * begin (void) const
T * begin (void)
hxsize_t capacity (void) const
const T * cbegin (void) const
const T * cend (void) const
void clear (void) noexcept
const T * data (void) const
T * data (void)
template<typename... args_t_>
hxhandle_t emplace (args_t_ &&... args_) noexcept
bool empty (void) const
const T * end (void) const
T * end (void)
template<typename callable_t_>
hxsize_t erase_if (callable_t_ &&callable_) noexcept
bool full (void) const
hxhandle_t handle_at (hxsize_t index_) const noexcept
template<typename... args_t_>
hxhandle_t insert (args_t_ &&... args_) noexcept
hxsize_t max_size (void) const
template<typename self_t_, typename callable_t_>
auto or_else (this self_t_ &&self_, hxhandle_t handle_, callable_t_ &&callable_) -> decltype(self_.end())
bool reset (hxhandle_t handle_) noexcept
void set_size_bits (uint32_t bits_)
hxsize_t size (void) const
T * value (hxhandle_t handle_) noexcept
const T * value (hxhandle_t handle_) const noexcept
template<typename self_t_, typename... args_t_>
T value_or (this self_t_ &&self_, hxhandle_t handle_, args_t_ &&... args_)

Detailed Description

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
class hxslot_map< T, table_size_bits_ >

hxslot_map - A table that maps 64-bit generational handles to values kept in a contiguous array of size 2^table_size_bits - 1 without reallocating memory.

data() always references size() contiguous values. Pointers into data are invalidated by reset while handles are not. Handle 0 is never valid. If non-zero, the template parameter table_size_bits configures the capacity to 2^table_size_bits - 1 values. Otherwise use set_size_bits to configure the size dynamically.

  • T : The value type stored in the map.
  • table_size_bits : If non-zero, sets the capacity to 2^table_size_bits - 1 values. Otherwise the size is dynamic.

Member Typedef Documentation

◆ const_iterator

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
using hxslot_map< T, table_size_bits_ >::const_iterator = const T*

const_iterator - Const random access iterator.

◆ iterator

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
using hxslot_map< T, table_size_bits_ >::iterator = T*

iterator - Random access iterator.

◆ value_t

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
using hxslot_map< T, table_size_bits_ >::value_t = T

Constructor & Destructor Documentation

◆ hxslot_map()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxslot_map< T, table_size_bits_ >::hxslot_map ( void )

Constructs an empty map with a capacity of 2^table_size_bits - 1.

◆ ~hxslot_map()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxslot_map< T, table_size_bits_ >::~hxslot_map ( )

Destructs the map and destroys all values.

Member Function Documentation

◆ and_then()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
auto hxslot_map< T, table_size_bits_ >::and_then ( this self_t_ && self_,
hxhandle_t handle_,
callable_t_ && callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>

Returns the result of calling callable with the value referenced by handle, otherwise returns hxnil.

Use and_then to return hxptr, hxref or hxexpected.

  • handle : The handle identifying the value to look up.
  • callable : The function to call with the value.

◆ begin() [1/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
T * hxslot_map< T, table_size_bits_ >::begin ( void )
inline

◆ begin() [2/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxslot_map< T, table_size_bits_ >::begin ( void ) const
inline

Returns a const T* to the beginning of the values (alias for data).

Iterators are invalidated by modification of the table.

◆ capacity()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxsize_t hxslot_map< T, table_size_bits_ >::capacity ( void ) const

Returns the number of values that can be stored.

◆ cbegin()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxslot_map< T, table_size_bits_ >::cbegin ( void ) const
inline

Returns a const T* to the beginning of the values (alias for begin).

Iterators are invalidated by modification of the table.

◆ cend()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxslot_map< T, table_size_bits_ >::cend ( void ) const

Returns a const T* to the end of the values.

Iterators are invalidated by modification of the table.

◆ clear()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
void hxslot_map< T, table_size_bits_ >::clear ( void )
noexcept

Destroys all values and invalidates their handles.

◆ data() [1/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
T * hxslot_map< T, table_size_bits_ >::data ( void )
inline

◆ data() [2/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxslot_map< T, table_size_bits_ >::data ( void ) const
inline

Returns a const pointer to the first of size contiguous values.

◆ emplace()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename... args_t_>
hxhandle_t hxslot_map< T, table_size_bits_ >::emplace ( args_t_ &&... args_)
noexcept

Returns a non-zero handle referencing a value constructed at the end of data from args.

The map must not be full.

  • args : Arguments forwarded to T's constructor.

◆ empty()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
bool hxslot_map< T, table_size_bits_ >::empty ( void ) const
inline

Checks if the map is empty.

◆ end() [1/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
T * hxslot_map< T, table_size_bits_ >::end ( void )
inline

◆ end() [2/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxslot_map< T, table_size_bits_ >::end ( void ) const

Returns a const T* to the end of the values.

Iterators are invalidated by modification of the table.

◆ erase_if()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
hxsize_t hxslot_map< T, table_size_bits_ >::erase_if ( callable_t_ && callable_)
noexcept

Returns the number of values destroyed.

Calls callable with a T& for every value and destroys those for which it returns true.

  • callable : Returns true for values to erase.

◆ full()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
bool hxslot_map< T, table_size_bits_ >::full ( void ) const

Checks if the map is full.

◆ handle_at()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxhandle_t hxslot_map< T, table_size_bits_ >::handle_at ( hxsize_t index_) const
noexcept

Returns the handle for the value at begin() + index.

  • index : The offset of the value in [0, size()) to get a handle for.

◆ insert()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename... args_t_>
hxhandle_t hxslot_map< T, table_size_bits_ >::insert ( args_t_ &&... args_)
noexcept

Returns a non-zero handle referencing a value constructed at the end of data from args.

The map must not be full.

  • args : Arguments forwarded to T's constructor.

◆ max_size()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxsize_t hxslot_map< T, table_size_bits_ >::max_size ( void ) const
inline

Returns the maximum number of values that can be stored.

◆ or_else()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
auto hxslot_map< T, table_size_bits_ >::or_else ( this self_t_ && self_,
hxhandle_t handle_,
callable_t_ && callable_ )->decltype(self_.end())

Returns a pointer to the value referenced by handle, or the result of calling callable when the handle does not resolve.

  • handle : The handle identifying the value to look up.
  • callable : The function to call when lookup fails. Must return an iterator.

◆ reset()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
bool hxslot_map< T, table_size_bits_ >::reset ( hxhandle_t handle_)
noexcept

Returns true if handle resolved and its value was destroyed.

The last value is move-assigned into the hole to keep the values contiguous.

  • handle : The handle identifying the value to remove.

◆ set_size_bits()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
void hxslot_map< T, table_size_bits_ >::set_size_bits ( uint32_t bits_)

Sets the number of index bits and allocates memory for the map (only for dynamic capacity).

  • bits : The number of index bits to set for the map, in the range [1, 30].

◆ size()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxsize_t hxslot_map< T, table_size_bits_ >::size ( void ) const
inline

Returns the number of values in the map.

◆ value() [1/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxslot_map< T, table_size_bits_ >::value ( hxhandle_t handle_) const
noexcept

◆ value() [2/2]

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
T * hxslot_map< T, table_size_bits_ >::value ( hxhandle_t handle_)
noexcept

Returns a pointer to the value referenced by handle if it resolves, otherwise end().

  • handle : The handle identifying the value to look up.

◆ value_or()

template<hxslot_map_concept_ T, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename... args_t_>
T hxslot_map< T, table_size_bits_ >::value_or ( this self_t_ && self_,
hxhandle_t handle_,
args_t_ &&... args_ )

Returns a copy of the value referenced by handle, or a value constructed from args when the handle does not resolve.

  • handle : The handle identifying the value to look up.
  • args : The arguments used to construct the value when lookup fails.

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