|
| | hxhash_table (deleter_t_ deleter_=deleter_t_()) |
| | ~hxhash_table (void) |
| template<hxrange_concept_ range_t_, hxenable_if_t<!hxis_lvalue_reference< range_t_ >(), int > = 0> |
| void | add_range (range_t_ &&range_) noexcept |
| template<typename self_t_, typename callable_t_> |
| auto | and_then (this self_t_ &&self_, const key_t &key_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< node_t_ & >())))> |
| template<typename self_t_, typename callable_t_> |
| auto | and_then (this self_t_ &&self_, const_iterator it_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< const node_t_ & >())))> |
| const_iterator | begin (void) const |
| iterator | begin (void) |
| hxsize_t | bucket_count (void) const |
| const_iterator | cbegin (void) const |
| const_iterator | cend (void) const |
| template<typename deleter_u_> |
| void | clear (deleter_u_ &&deleter_) noexcept |
| void | clear (void) noexcept |
| hxsize_t | count (const typename node_t_::key_t &key_) const |
| const deleter_t_ & | deleter (void) const |
| deleter_t_ & | deleter (void) |
| template<hxsystem_allocator_t allocator_ = hxsystem_allocator_current, hxalignment_t align_ = hxalignment, bool multi_ = multi_t_, class... args_t_> |
| hxenable_if_t< multi_, iterator > | emplace (args_t_ &&... args_) noexcept |
| bool | empty (void) const |
| const_iterator | end (void) const |
| iterator | end (void) |
| template<typename deleter_u_> |
| hxsize_t | erase (const typename node_t_::key_t &key_, deleter_u_ &&deleter_) noexcept |
| hxsize_t | erase (const typename node_t_::key_t &key_) noexcept |
| iterator | erase (const const_iterator &it_) noexcept |
| hxptr< node_t_, deleter_t_ > | extract (const typename node_t_::key_t &key_) noexcept |
| hxptr< node_t_, deleter_t_ > | extract (const const_iterator &it_) noexcept |
| const_iterator | find (const typename node_t_::key_t &key_, const const_iterator &previous_=const_iterator()) const |
| iterator | find (const typename node_t_::key_t &key_, const const_iterator &previous_=const_iterator()) |
| bool | has_value (const key_t &key_) const |
| iterator | insert (node_t_ *ptr_) noexcept |
| template<typename deleter_u_> |
| iterator | insert (hxptr< node_t_, deleter_u_ > &&ptr_) noexcept |
| float | load_factor (void) const |
| hxsize_t | load_max (void) const |
| template<typename self_t_, typename callable_t_> |
| auto | or_else (this self_t_ &&self_, const key_t &key_, callable_t_ &&callable_) -> decltype(self_.end()) |
| template<typename self_t_, typename callable_t_> |
| auto | or_else (this self_t_ &&self_, const_iterator it_, callable_t_ &&callable_) -> decltype(self_.end()) |
| void | release_all (void) |
| hxsize_t | release_key (const typename node_t_::key_t &key_) |
| hxptr< node_t_, deleter_t_ > | replace (node_t_ *ptr_) noexcept |
| void | set_size_bits (hxhash_t bits_) |
| hxsize_t | size (void) const |
| template<hxsystem_allocator_t allocator_ = hxsystem_allocator_current, hxalignment_t align_ = hxalignment, bool multi_ = multi_t_, class... args_t_> |
| hxenable_if_t<!multi_, iterator > | try_emplace (const typename node_t_::key_t &key_, args_t_ &&... args_) noexcept |
| template<typename self_t_> |
| auto | value_or (this self_t_ &&self_, const key_t &key_, const node_t_ *default_value_) -> decltype(self_.end()) |
| template<typename self_t_> |
| auto | value_or (this self_t_ &&self_, const_iterator it_, const node_t_ *default_value_) -> decltype(self_.end()) |
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
class hxhash_table< node_t_, deleter_t_, multi_t_, table_size_bits_ >
hxhash_table - A hash table that operates without reallocating memory or copying data.
Each bucket uses an embedded singly-linked list. This design tries to use a sparse table that allocates the maximum amount of memory upfront and then uses a high quality hash instead of relying on linear probing for cache efficiency. Hash tables can act as either an unordered map or an unordered set and support operations that allow for unique or duplicate keys.
Any node T derived from hxhash_node_base and using key K will work as long as K has an operator== or an hxkey_equal_t specialization.
const key_t& hash_key()
const;
};
hxhash_node_base - Intrusive hash-chain node base.
Definition hxhash_table.hpp:47
typename node_t_::key_t key_t
Definition hxhash_table.hpp:226
hxhash_table_set_node and hxhash_table_map_node are provided and recommended as replacements for std::unordered_set and std::unordered_map. Custom key types will require either an operator== or an hxkey_equal_t specialization and will require an hxkey_hash_t specialization.
They might be used as follows:
hxdefault_delete - A callable that deletes objects of type T using hxdelete.
Definition hxmemory_manager.h:265
hxhash_table_map_node - Base class for unordered map entries.
Definition hxhash_table.hpp:110
hxhash_table(deleter_t_ deleter_=deleter_t_())
Constructs an empty hash table with a capacity of 2^table_size_bits and an optional deleter instance.
hx/hxhash_table_nodes.hpp also provides specializations of the hxhash_table::node_t template parameter for integers and strings.
- node_t : Must implement the interface/concept described above.
- deleter_t : A class type invoked as deleter(T*) to free the owned pointer. See also hxdo_not_delete.
- multi_t : When falseand a node with an equal key already exists, insertion into the list will fail when a node with the same key already exists.
- table_size_bits : If non-zero, table_size_bits configures the hash table size to 2^table_size_bits. Otherwise use set_size_bits to configure hash bits dynamically.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
| void hxhash_table< node_t_, deleter_t_, multi_t_, table_size_bits_ >::add_range |
( |
range_t_ && | range_ | ) |
|
|
noexcept |
Links each node_t from a temporary range into this hash table by address, exactly as insert(node_t*) would.
The range's nodes are threaded into the table in place and are not copied or allocated, so range must own storage it is relinquishing to the table.
- range : The range of nodes to link into the table.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
Returns the result of calling callable with the first node matching key, otherwise returns hxnil.
Use and_then to return hxptr, hxref or hxexpected.
- key : The key to search for.
- callable : The function to call with the found node.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename deleter_u_>
| hxsize_t hxhash_table< node_t_, deleter_t_, multi_t_, table_size_bits_ >::erase |
( |
const typename node_t_::key_t & | key_, |
|
|
deleter_u_ && | deleter_ ) |
|
noexcept |
Releases all nodes matching key and calls deleter on every node.
Returns the number of nodes released. Deleter can be functions with signature void deleter(node_t*) and callables supporting operator()(node_t*) and with an operator bool. e.g., a free list or a null pointer.
- key : The key to search for and remove from the hash table.
- deleter : Callable with signature bool deleter(node_t_*).
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename deleter_u_>
insert - Returns an iterator to the inserted node.
When multi_t is false and a node with an equal key already exists, returns an iterator to the existing node and ptr is destroyed, invoking its deleter.
- ptr : The hxptr owning the node to insert.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
insert - Returns an iterator to the inserted node.
When multi_t is false and a node with an equal key already exists, invokes deleter_t on ptr and returns an iterator to the existing node. ptr must not be null.
- ptr : The node to insert.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
| auto hxhash_table< node_t_, deleter_t_, multi_t_, table_size_bits_ >::or_else |
( |
this self_t_ && | self_, |
|
|
const key_t & | key_, |
|
|
callable_t_ && | callable_ )->decltype(self_.end()) |
Returns an iterator to the first node matching key, or the result of calling callable when lookup fails.
- key : The key to search for.
- callable : The function to call when lookup fails. Must return an iterator.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
| hxptr< node_t_, deleter_t_ > hxhash_table< node_t_, deleter_t_, multi_t_, table_size_bits_ >::replace |
( |
node_t_ * | ptr_ | ) |
|
|
noexcept |
replace - Replaces the first node_t matching ptr's key, if any, with ptr and returns an hxptr owning the replaced node.
Returns an empty hxptr and inserts ptr as a new node if no match is found. Avoids the extra lookup an erase followed by insert would require. ptr must not be null.
- ptr : The node to insert in place of any matching node.
template<hxhash_table_concept_ node_t_, typename deleter_t_ = hxdefault_delete, bool multi_t_ = false, uint32_t table_size_bits_ = hxallocator_dynamic_capacity>
template<typename self_t_>
| auto hxhash_table< node_t_, deleter_t_, multi_t_, table_size_bits_ >::value_or |
( |
this self_t_ && | self_, |
|
|
const key_t & | key_, |
|
|
const node_t_ * | default_value_ )->decltype(self_.end()) |
Returns an iterator to the first node matching key, or an iterator to default_value when lookup fails.
- key : The key to search for.
- default_value : The node to reference when lookup fails.