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

#include <hxhandle_table.hpp>

Public Types

using value_t = T

Public Member Functions

 hxhandle_table (deleter_t_ deleter_=deleter_t_())
 ~hxhandle_table (void)
hxsize_t capacity (void) const
template<typename deleter_u_>
void clear (deleter_u_ &&deleter_) noexcept
void clear (void) noexcept
bool empty (void) const
template<typename deleter_u_>
bool erase (hxhandle_t handle_, deleter_u_ &&deleter_) noexcept
bool erase (hxhandle_t handle_) noexcept
template<typename callable_t_>
hxsize_t erase_if (callable_t_ &&callable_) noexcept
hxptr< T, deleter_t_ > extract (hxhandle_t handle_) noexcept
bool full (void) const
T * get (hxhandle_t handle_) noexcept
const T * get (hxhandle_t handle_) const noexcept
const deleter_t_ & deleter (void) const
deleter_t_ & deleter (void)
hxhandle_t insert (T *ptr_) noexcept
template<typename deleter_u_>
hxhandle_t insert (hxptr< T, deleter_u_ > &&ptr_) noexcept
hxsize_t max_size (void) const
void release_all (void) noexcept
void set_size_bits (uint32_t bits_)
hxsize_t size (void) const

Detailed Description

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
class hxhandle_table< T, deleter_t_, table_size_bits_ >

hxhandle_table - A table that maps 64-bit handles to owned pointers without reallocating memory or moving values.

The table is a fixed 2^table_size_bits - 1 array of handles. Use set_size_bits to configure the size dynamically.

  • T : The pointed-to type stored in the table.
  • deleter_t : A class type invoked as deleter(T*) to free the owned pointer. See also hxdo_not_delete.
  • table_size_bits : If non-zero, fixes the table to 2^table_size_bits slots. Otherwise the size is dynamic.

Member Typedef Documentation

◆ value_t

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
using hxhandle_table< T, deleter_t_, table_size_bits_ >::value_t = T

Constructor & Destructor Documentation

◆ hxhandle_table()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxhandle_table< T, deleter_t_, table_size_bits_ >::hxhandle_table ( deleter_t_ deleter_ = deleter_t_())
explicit

Constructs an empty table with a capacity of 2^table_size_bits slots and an optional deleter instance.

  • deleter : Callable with signature bool deleter(T*).

◆ ~hxhandle_table()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxhandle_table< T, deleter_t_, table_size_bits_ >::~hxhandle_table ( void )

Destructs the table and deletes all owned values.

Member Function Documentation

◆ capacity()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxsize_t hxhandle_table< T, deleter_t_, table_size_bits_ >::capacity ( void ) const
inline

Returns the number of slots in the table.

◆ clear() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename deleter_u_>
void hxhandle_table< T, deleter_t_, table_size_bits_ >::clear ( deleter_u_ && deleter_)
noexcept

Removes all values and if deleter is true then calls deleter() on every value.

  • deleter : Callable with signature bool deleter(T*).

◆ clear() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
void hxhandle_table< T, deleter_t_, table_size_bits_ >::clear ( void )
inlinenoexcept

Removes all values and calls the stored deleter on every value.

◆ deleter() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
deleter_t_ & hxhandle_table< T, deleter_t_, table_size_bits_ >::deleter ( void )

Returns a reference to the stored deleter.

◆ deleter() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const deleter_t_ & hxhandle_table< T, deleter_t_, table_size_bits_ >::deleter ( void ) const

Returns a const reference to the stored deleter.

◆ empty()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
bool hxhandle_table< T, deleter_t_, table_size_bits_ >::empty ( void ) const
inline

Checks if the table is empty.

◆ erase() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
bool hxhandle_table< T, deleter_t_, table_size_bits_ >::erase ( hxhandle_t handle_)
inlinenoexcept

Removes and calls the stored deleter on the value referenced by handle.

  • handle : The handle identifying the value to remove.

◆ erase() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename deleter_u_>
bool hxhandle_table< T, deleter_t_, table_size_bits_ >::erase ( hxhandle_t handle_,
deleter_u_ && deleter_ )
noexcept

Releases the value referenced by handle if deleter is true then calls deleter on it.

  • handle : The handle identifying the value to remove.
  • deleter : Callable with signature bool deleter(T*).

◆ erase_if()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
hxsize_t hxhandle_table< T, deleter_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 calls the stored deleter on those for which it returns true.

  • callable : Returns true for values to erase.

◆ extract()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxptr< T, deleter_t_ > hxhandle_table< T, deleter_t_, table_size_bits_ >::extract ( hxhandle_t handle_)
noexcept

Returns an hxptr owning the value referenced by handle, or an empty hxptr if handle does not resolve.

The slot is freed.

  • handle : The handle identifying the value to extract.

◆ full()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
bool hxhandle_table< T, deleter_t_, table_size_bits_ >::full ( void ) const
inline

Checks if the table is full.

◆ get() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
const T * hxhandle_table< T, deleter_t_, table_size_bits_ >::get ( hxhandle_t handle_) const
noexcept

const version of get.

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

◆ get() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
T * hxhandle_table< T, deleter_t_, table_size_bits_ >::get ( hxhandle_t handle_)
noexcept

Returns the value referenced by handle if it resolves, otherwise hxnull.

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

◆ insert() [1/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename deleter_u_>
hxhandle_t hxhandle_table< T, deleter_t_, table_size_bits_ >::insert ( hxptr< T, deleter_u_ > && ptr_)
noexcept

Takes ownership of the value owned by ptr and returns a non-zero handle referencing it.

The table must not be full and ptr must not be null.

  • ptr : The hxptr owning the value to insert.

◆ insert() [2/2]

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxhandle_t hxhandle_table< T, deleter_t_, table_size_bits_ >::insert ( T * ptr_)
noexcept

Takes ownership of ptr and returns a non-zero handle referencing it.

The table must not be full and ptr must not be null.

  • ptr : The value to insert.

◆ max_size()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxsize_t hxhandle_table< T, deleter_t_, table_size_bits_ >::max_size ( void ) const
inline

Returns the maximum number of values that can be stored.

◆ release_all()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
void hxhandle_table< T, deleter_t_, table_size_bits_ >::release_all ( void )
inlinenoexcept

Clears the table without deleting any values.

◆ set_size_bits()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
void hxhandle_table< T, deleter_t_, table_size_bits_ >::set_size_bits ( uint32_t bits_)

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

  • bits : The number of index bits to set for the table.

◆ size()

template<typename T, typename deleter_t_ = hxdefault_delete, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
hxsize_t hxhandle_table< T, deleter_t_, table_size_bits_ >::size ( void ) const
inline

Returns the number of values in the table.


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