12#if HX_USE_MACROS_WITH_MODULE
13#error Header does not provide macros alone.
21#include "detail/hxpow2_allocator.hpp"
23#if HX_CPLUSPLUS >= 202002L
26concept hxhandle_table_concept_ =
requires(T_& x_) {
32#define hxhandle_table_concept_ typename
44template<hxhandle_table_concept_ T_,
50 static_assert(table_size_bits_ <= 30u,
"hxhandle_table is designed for 2^30 or less slots");
62#if HX_CPLUSPLUS >= 202302L
68 template<
typename self_t_,
typename callable_t_>
70 this self_t_&& self_,
hxhandle_t handle_, callable_t_&& callable_)
78 return static_cast<hxsize_t>(m_table_.get_mask_());
84 template<
typename deleter_u_>
85 void clear(deleter_u_&& deleter_)
noexcept;
102 template<
typename callable_t_>
113 return m_free_head_ == m_table_.data();
125 template<
typename deleter_u_>
131 return static_cast<hxsize_t>(m_table_.get_mask_());
134#if HX_CPLUSPLUS >= 202302L
140 template<
typename self_t_,
typename callable_t_>
142 this self_t_&& self_,
hxhandle_t handle_, callable_t_&& callable_)
143 ->
decltype(self_.value(handle_));
153 template<
typename deleter_u_>
177#if HX_CPLUSPLUS >= 202302L
182 template<
typename self_t_,
typename... args_t_>
184 this self_t_&& self_,
hxhandle_t handle_, args_t_&&... args_);
197 void build_free_list_(
void);
199 hxdetail_::hxpow2_allocator_<slot_t_, table_size_bits_, false> m_table_;
201 slot_t_* m_free_head_;
204#include "detail/hxhandle_table.inl"
hxdefault_delete - A callable that deletes objects of type T using hxdelete.
Definition hxmemory_manager.h:265
hxdo_not_delete - A version of hxdefault_delete that does not delete the object.
Definition hxmemory_manager.h:278
const T * value(hxhandle_t handle_) const noexcept
Returns the value referenced by handle if it resolves, otherwise hxnull.
hxsize_t max_size(void) const
Returns the maximum number of values that can be stored.
Definition hxhandle_table.hpp:130
hxsize_t capacity(void) const
Returns the number of slots in the table.
Definition hxhandle_table.hpp:77
deleter_t_ & deleter(void)
hxhandle_t insert(hxptr< T, deleter_u_ > &&ptr_) noexcept
Takes ownership of the value owned by ptr and returns a non-zero handle referencing it,...
hxhandle_t insert(T *ptr_) noexcept
Takes ownership of ptr and returns a non-zero handle referencing it, or hxnull_handle if ptr is null.
T 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 do...
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 & >())))>
Returns the result of calling callable with the value referenced by handle, otherwise returns hxnil.
bool full(void) const
Checks if the table is full.
Definition hxhandle_table.hpp:112
hxptr< T, deleter_t_ > extract(hxhandle_t handle_) noexcept
Returns an hxptr owning the value referenced by handle, or an empty hxptr if handle does not resolve.
auto or_else(this self_t_ &&self_, hxhandle_t handle_, callable_t_ &&callable_) -> decltype(self_.value(handle_))
Returns a pointer to the value referenced by handle, or the result of calling callable when the handl...
bool empty(void) const
Checks if the table is empty.
Definition hxhandle_table.hpp:96
const deleter_t_ & deleter(void) const
Returns a const reference to the stored deleter.
void set_size_bits(uint32_t bits_)
Sets the number of index bits and allocates memory for the table (only for dynamic capacity).
hxhandle_table(deleter_t_ deleter_=deleter_t_())
Constructs an empty table with a capacity of 2^table_size_bits - 1 slots and an optional deleter inst...
T value_t
Definition hxhandle_table.hpp:52
void clear(deleter_u_ &&deleter_) noexcept
Removes all values and if deleter is true then calls deleter() on every value.
hxsize_t erase_if(callable_t_ &&callable_) noexcept
Returns the number of values destroyed.
bool reset(hxhandle_t handle_, deleter_u_ &&deleter_) noexcept
Releases the value referenced by handle if deleter is true then calls deleter on it.
bool reset(hxhandle_t handle_) noexcept
Removes and calls the stored deleter on the value referenced by handle.
Definition hxhandle_table.hpp:159
hxsize_t size(void) const
Returns the number of values in the table.
Definition hxhandle_table.hpp:168
void release_all(void) noexcept
Clears the table without deleting any values.
Definition hxhandle_table.hpp:147
void clear(void) noexcept
Removes all values and calls the stored deleter on every value.
Definition hxhandle_table.hpp:88
~hxhandle_table(void)
Destructs the table and deletes all owned values.
T * value(hxhandle_t handle_) noexcept
hxptr<T, deleter_t> - A unique owning pointer.
Definition hxptr.hpp:30
Similar to std::allocator.
HX_NS_BEGIN_ constexpr hxsize_t hxallocator_dynamic_capacity
hxallocator_dynamic_capacity - A capacity value that allows for dynamic allocation.
Definition hxallocator.hpp:20
#define hxinline
hxinline - Force a function to be inlined into its callers.
Definition hxsettings.h:125
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:98
#define hxattr_flatten
hxattr_flatten - Inline every call inside a function's body into it, recursively, regardless of the c...
Definition hxsettings.h:90
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:353
hxremove_cv_t< hxremove_reference_t< T > > hxremove_cvref_t
hxremove_cvref_t<T> - Returns T with const, volatile, and references removed.
Definition hxutility.h:103
T && hxdeclval(void) noexcept
hxdeclval - Implements std::declval.
constexpr hxforward_like_t_< like_t_, value_t_ > hxforward_like(value_t_ &value_)
hxforward_like<T> - Returns value with the constness and value category of T.
Definition hxutility.h:387
Provides core macros, memory management and feature detection.
uint64_t hxhandle_t
hxhandle_t - An opaque 64-bit handle.
Definition libhatchet.h:213
ptrdiff_t hxsize_t
hxsize_t - A signed size type, same as ssize_t or ptrdiff_t.
Definition libhatchet.h:207