|
| using | Pair = std::pair< Key, Data > |
| | The key-value pair type stored in the map.
|
| |
| using | Base = HashTable< std::pair< Key, Data >, Dft_Pair_Cmp< Key, Data, Cmp > > |
| | The base hash table type.
|
| |
| using | Hash_Fct = std::function< size_t(const Key &)> |
| | Function type for hash functions.
|
| |
| using | Hash_Fct_Ptr = size_t(*)(const Key &) |
| | Function pointer type for hash functions.
|
| |
| using | Key_Type = Key |
| | The type of keys in the map.
|
| |
| using | Data_Type = Data |
| | The type of mapped values.
|
| |
| using | Value_Type = Data |
| | Alias for Data_Type (compatibility with other containers).
|
| |
| using | Item_Type = Pair |
| | The item type stored in the map (key-value pair).
|
| |
| using | Set_Type = MapOpenHash |
| | Self-reference type for generic programming.
|
| |
| using | Iterator = typename Base::Iterator |
| | Iterator type for traversing the map.
|
| |
|
| | MapOpenHash (size_t len=Primes::DefaultPrime, Hash_Fct_Ptr first_hash_fct=dft_hash_ptr_fct< Key >, Hash_Fct_Ptr second_hash_fct=snd_hash_ptr_fct< Key >, Cmp cmp=Cmp(), float lower_alpha=hash_default_lower_alpha, float upper_alpha=hash_default_upper_alpha, bool with_resize=true) |
| | Construct a map with specified parameters.
|
| |
| Pair * | insert (const Key &key, const Data &data) |
| | Insert a key-value pair (copy semantics).
|
| |
| Pair * | insert (const Key &key, Data &&data) |
| | Insert a key-value pair (move data).
|
| |
| Pair * | insert (Key &&key, Data &&data) |
| | Insert a key-value pair (move both).
|
| |
| Pair * | insert (Key &&key, const Data &data) |
| | Insert a key-value pair (move key, copy data).
|
| |
| Pair * | search (const Key &key) noexcept(nothrow_search< const Key & >) |
| | Search for a key in the map.
|
| |
| const Pair * | search (const Key &key) const noexcept(nothrow_search< const Key & >) |
| | This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A pointer to const.
|
| |
| Pair * | search (Key &&key) noexcept(nothrow_search< Key >) |
| | Search for a key in the map (move semantics).
|
| |
| const Pair * | search (Key &&key) const noexcept(nothrow_search< Key >) |
| | This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A pointer to const.
|
| |
| bool | has (const Key &key) const noexcept(nothrow_search< const Key & >) |
| | Check if a key exists in the map.
|
| |
| bool | has (Key &&key) const noexcept(nothrow_search< Key >) |
| | Check if a key exists in the map (move semantics).
|
| |
| bool | contains (const Key &key) const noexcept(nothrow_search< const Key & >) |
| | Check if a key exists in the map.
|
| |
| bool | contains (Key &&key) const noexcept(nothrow_search< Key >) |
| | Check if a key exists in the map (move semantics).
|
| |
| Data & | find (const Key &key) |
| | Find and return the value for a key.
|
| |
| Data & | find (Key &&key) |
| | Find and return the value for a key (move semantics).
|
| |
| const Data & | find (const Key &key) const |
| | Find and return the value for a key (const).
|
| |
| const Data & | find (Key &&key) const |
| | Find and return the value for a key (const, move).
|
| |
| Data & | operator[] (const Key &key) |
| | Access or insert a value by key.
|
| |
| const Data & | operator[] (const Key &key) const |
| | Access value by key (const version).
|
| |
| Data & | operator[] (Key &&key) |
| | Access or insert a value by key (move semantics).
|
| |
| const Data & | operator[] (Key &&key) const |
| | Access value by key (const, move).
|
| |
| void | remove_by_data (Data &data) |
| | Remove an entry by its data pointer.
|
| |
| void | remove (const Key &key) |
| | Remove an entry by key.
|
| |
| void | remove (Key &&key) |
| | Remove an entry by key (move semantics).
|
| |
| DynList< Key > | keys () const |
| | Get a list of all keys in the map.
|
| |
| DynList< Data > | values () const |
| | Get a list of all values in the map.
|
| |
| DynList< Data * > | values_ptr () |
| | Get a list of pointers to all values.
|
| |
| DynList< Pair * > | items_ptr () |
| | Get a list of pointers to all pairs.
|
| |
|
template<typename... Items>
requires requires (Items &&... items) { MapOpenHash ::template build_as< MapOpenHash >(std::forward<Items>(items)...); } |
| static MapOpenHash | build (Items &&... items) |
| |
| static Pair * | key_to_pair (Key *ptr) noexcept |
| | Convert a key pointer to its containing pair pointer.
|
| |
| static const Pair * | key_to_pair (const Key *ptr) noexcept |
| |
| static Pair * | data_to_pair (Data *ptr) noexcept |
| | Convert a data pointer to its containing pair pointer.
|
| |
| static const Pair * | data_to_pair (const Data *ptr) noexcept |
| |
| static Data & | get_data (Key &key) noexcept |
| | Get the data associated with a key by reference.
|
| |
| static const Data & | get_data (const Key &key) noexcept |
| |
| static const Key & | get_key (Data *data_ptr) noexcept |
| | Get the key associated with a data pointer.
|
| |
| static const Key & | get_key (const Data *data_ptr) noexcept |
| |
template<typename Key, typename Data, class
Cmp = Aleph::equal_to<Key>, template< typename, class > class HashTable = ODhashTable>
requires EqualityComparator<
Cmp, Key>
struct Aleph::MapOpenHash< Key, Data, Cmp, HashTable >
Open addressing hash map for key-value pairs.
MapOpenHash<Key, Data, Cmp, HashTable> implements an associative container that maps keys to values using open addressing hash tables. It provides O(1) average-case complexity for insert, search, and delete operations.
Features
Example Usage
ages["Bob"] = 25;
std::cout << "Alice's age: " << ages["Alice"] << '\n';
ages.traverse([](
auto&
pair) {
std::cout <<
pair.first <<
": " <<
pair.second <<
'\n';
return true;
});
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
Open addressing hash map using double hashing.
void remove(const Key &key)
Remove an entry by key.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair (copy semantics).
bool has(const Key &key) const noexcept(nothrow_search< const Key & >)
Check if a key exists in the map.
Hash Table Variants
- MapODhash: Uses double hashing (better distribution, more complex)
- MapOLhash: Uses linear probing (simpler, better cache locality)
Thread Safety
This class is not thread-safe. External synchronization is required for concurrent access from multiple threads.
- Template Parameters
-
| Key | Type of keys. Must be hashable and equality-comparable. |
| Data | Type of mapped values. |
| Cmp | Equality comparator for keys (default: Aleph::equal_to<Key>). |
| HashTable | Underlying hash table type (default: ODhashTable). |
- See also
- MapODhash Double hashing variant
-
MapOLhash Linear probing variant
-
ODhashTable Underlying double hashing table
-
OLhashTable Underlying linear probing table
Definition at line 117 of file tpl_dynMapOhash.H.
template<typename Key , typename Data , class
Cmp = Aleph::equal_to<Key>, template< typename, class > class HashTable = ODhashTable>
Convert a data pointer to its containing pair pointer.
Given a pointer to the data (second) member of a pair, returns a pointer to the enclosing pair.
- Parameters
-
| [in] | ptr | Pointer to data within a pair. |
- Returns
- Pointer to the containing pair.
- Warning
- Only valid for pointers obtained from pairs in this map.
Definition at line 224 of file tpl_dynMapOhash.H.
Referenced by Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::get_key(), Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::get_key(), and Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::remove_by_data().
template<typename Key , typename Data , class
Cmp = Aleph::equal_to<Key>, template< typename, class > class HashTable = ODhashTable>
Check if a key exists in the map.
- Parameters
-
- Returns
- true if the key exists, false otherwise.
- Exceptions
-
| What | building the pair that the table searches for throws: the copy of key or the default constructor of Data. As the search of the table, which is noexcept, it requires that the hash functions and the comparison do not throw. |
Definition at line 386 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::search().
Referenced by Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::contains(), Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::contains(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
template<typename Key , typename Data , class
Cmp = Aleph::equal_to<Key>, template< typename, class > class HashTable = ODhashTable>
Insert a key-value pair (copy semantics).
Inserts a new key-value pair into the map. If the key already exists, no insertion occurs.
- Parameters
-
| [in] | key | The key to insert. |
| [in] | data | The value to associate with the key. |
- Returns
- Pointer to the inserted pair, or nullptr if key exists.
- Exceptions
-
| std::bad_alloc | If memory allocation fails during resize. |
Definition at line 286 of file tpl_dynMapOhash.H.
Referenced by Aleph::Gen_Mo_On_Trees< GT, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::hld_detail::HLD_Tree_Data< GT, SA >::index_nodes(), Aleph::lca_detail::Rooted_Tree_Data< GT, SA >::index_nodes(), Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::index_nodes(), Aleph::tree_dp_detail::Tree_Topology< GT, SA >::index_nodes(), MapODhashTest::populate_int_map(), MapODhashTest::populate_map(), MapOLhashTest::populate_map(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
template<typename Key , typename Data , class
Cmp = Aleph::equal_to<Key>, template< typename, class > class HashTable = ODhashTable>
template<typename Key , typename Data , class
Cmp = Aleph::equal_to<Key>, template< typename, class > class HashTable = ODhashTable>
Search for a key in the map.
- Parameters
-
| [in] | key | The key to search for. |
- Returns
- Pointer to the pair if found, nullptr otherwise.
- Exceptions
-
| What | building the pair that the table searches for throws: the copy of key or the default constructor of Data. As the search of the table, which is noexcept, it requires that the hash functions and the comparison do not throw. |
Definition at line 334 of file tpl_dynMapOhash.H.
Referenced by Aleph::Gen_Mo_On_Trees< GT, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::tree_dp_detail::Tree_Topology< GT, SA >::build_adjacency(), Aleph::hld_detail::HLD_Tree_Data< GT, SA >::build_simple_adjacency(), Aleph::lca_detail::Rooted_Tree_Data< GT, SA >::build_simple_adjacency(), Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::build_simple_adjacency(), Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::has(), Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::has(), Aleph::hld_detail::HLD_Tree_Data< GT, SA >::id_of(), Aleph::lca_detail::Rooted_Tree_Data< GT, SA >::id_of(), Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::id_of(), Aleph::tree_dp_detail::Tree_Topology< GT, SA >::id_of(), Aleph::hld_detail::HLD_Tree_Data< GT, SA >::index_nodes(), Aleph::lca_detail::Rooted_Tree_Data< GT, SA >::index_nodes(), Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::index_nodes(), Aleph::tree_dp_detail::Tree_Topology< GT, SA >::index_nodes(), Aleph::Gen_Mo_On_Trees< GT, Policy >::path_solve(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), Aleph::Gen_Mo_On_Trees< GT, Policy >::subtree_solve(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve(), and TEST().