|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Open addressing hash map for key-value pairs. More...
#include <tpl_dynMapOhash.H>
Public Types | |
| 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. | |
Public Member Functions | |
| MapOpenHash (size_t len=Primes::DefaultPrime, Hash_Fct_Ptr first_hash_fct=dft_hash_fct< Key >, Hash_Fct_Ptr second_hash_fct=snd_hash_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) const noexcept |
| Search for a key in the map. | |
| Pair * | search (Key &&key) const noexcept |
| Search for a key in the map (move semantics). | |
| bool | has (const Key &key) const noexcept |
| Check if a key exists in the map. | |
| bool | has (Key &&key) const noexcept |
| Check if a key exists in the map (move semantics). | |
| bool | contains (const Key &key) const noexcept |
| Check if a key exists in the map. | |
| bool | contains (Key &&key) const noexcept |
| 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. | |
Static Public Member Functions | |
| 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 |
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.
This class is not thread-safe. External synchronization is required for concurrent access from multiple threads.
| 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). |
Definition at line 116 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Base = HashTable<std::pair<Key, Data>, Dft_Pair_Cmp<Key, Data, Cmp> > |
The base hash table type.
Definition at line 123 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Data_Type = Data |
The type of mapped values.
Definition at line 138 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Hash_Fct = std::function<size_t(const Key &)> |
Function type for hash functions.
Definition at line 129 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Hash_Fct_Ptr = size_t (*) (const Key &) |
Function pointer type for hash functions.
Definition at line 132 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Item_Type = Pair |
The item type stored in the map (key-value pair).
Definition at line 144 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Iterator = typename Base::Iterator |
Iterator type for traversing the map.
Definition at line 524 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Key_Type = Key |
The type of keys in the map.
Definition at line 135 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Pair = std::pair<Key, Data> |
The key-value pair type stored in the map.
Definition at line 120 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Set_Type = MapOpenHash |
Self-reference type for generic programming.
Definition at line 147 of file tpl_dynMapOhash.H.
| using Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::Value_Type = Data |
Alias for Data_Type (compatibility with other containers).
Definition at line 141 of file tpl_dynMapOhash.H.
|
inline |
Construct a map with specified parameters.
| [in] | len | Initial table size (default: DefaultPrime). |
| [in] | first_hash_fct | Primary hash function. |
| [in] | second_hash_fct | Secondary hash function (for double hashing). |
| [in] | cmp | Equality comparator for keys. |
| [in] | lower_alpha | Lower load factor threshold for shrinking. |
| [in] | upper_alpha | Upper load factor threshold for growing. |
| [in] | with_resize | Enable automatic resizing. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 161 of file tpl_dynMapOhash.H.
|
inlinenoexcept |
Check if a key exists in the map.
Alias for has().
| [in] | key | The key to check. |
Definition at line 359 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::has().
|
inlinenoexcept |
Check if a key exists in the map (move semantics).
| [in] | key | The key to check. |
Definition at line 369 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::has().
|
inlinestaticnoexcept |
Definition at line 212 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inlinestaticnoexcept |
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.
| [in] | ptr | Pointer to data within a pair. |
Definition at line 206 of file tpl_dynMapOhash.H.
References Aleph::maps().
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().
|
inline |
Find and return the value for a key.
| [in] | key | The key to find. |
| std::domain_error | If the key is not found. |
Definition at line 381 of file tpl_dynMapOhash.H.
References Aleph::maps().
Referenced by Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::operator[](), and Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::operator[]().
|
inline |
Find and return the value for a key (const).
| [in] | key | The key to find. |
| std::domain_error | If the key is not found. |
Definition at line 409 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Find and return the value for a key (move semantics).
| [in] | key | The key to find. |
| std::domain_error | If the key is not found. |
Definition at line 395 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Find and return the value for a key (const, move).
| [in] | key | The key to find. |
| std::domain_error | If the key is not found. |
Definition at line 423 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inlinestaticnoexcept |
Definition at line 233 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::key_to_pair().
|
inlinestaticnoexcept |
Get the data associated with a key by reference.
Given a reference to a key that is stored in the map, returns a reference to its associated data.
| [in] | key | Reference to a key within a stored pair. |
Definition at line 228 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::key_to_pair().
|
inlinestaticnoexcept |
Definition at line 253 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::data_to_pair().
|
inlinestaticnoexcept |
Get the key associated with a data pointer.
Given a pointer to data stored in the map, returns a reference to its associated key.
| [in] | data_ptr | Pointer to data within a stored pair. |
Definition at line 248 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::data_to_pair().
|
inlinenoexcept |
Check if a key exists in the map.
| [in] | key | The key to check. |
Definition at line 337 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(), and TEST().
|
inlinenoexcept |
Check if a key exists in the map (move semantics).
| [in] | key | The key to check. |
Definition at line 347 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::search().
|
inline |
Insert a key-value pair (copy semantics).
Inserts a new key-value pair into the map. If the key already exists, no insertion occurs.
| [in] | key | The key to insert. |
| [in] | data | The value to associate with the key. |
| std::bad_alloc | If memory allocation fails during resize. |
Definition at line 269 of file tpl_dynMapOhash.H.
Referenced by MapODhashTest::populate_int_map(), MapODhashTest::populate_map(), MapOLhashTest::populate_map(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Insert a key-value pair (move data).
| [in] | key | The key to insert. |
| [in] | data | The value to move into the map. |
Definition at line 280 of file tpl_dynMapOhash.H.
|
inline |
Insert a key-value pair (move key, copy data).
| [in] | key | The key to move into the map. |
| [in] | data | The value to copy into the map. |
Definition at line 303 of file tpl_dynMapOhash.H.
|
inline |
Insert a key-value pair (move both).
| [in] | key | The key to move into the map. |
| [in] | data | The value to move into the map. |
Definition at line 291 of file tpl_dynMapOhash.H.
|
inline |
Get a list of pointers to all pairs.
Definition at line 564 of file tpl_dynMapOhash.H.
References Aleph::DynList< T >::append(), and Aleph::maps().
|
inlinestaticnoexcept |
Definition at line 191 of file tpl_dynMapOhash.H.
|
inlinestaticnoexcept |
Convert a key pointer to its containing pair pointer.
Given a pointer to the key member of a pair, returns a pointer to the enclosing pair. This relies on the fact that the key is the first member of std::pair.
| [in] | ptr | Pointer to a key within a pair. |
Definition at line 186 of file tpl_dynMapOhash.H.
Referenced by Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::get_data(), and Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::get_data().
|
inline |
Get a list of all keys in the map.
Definition at line 530 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Access or insert a value by key.
If the key exists, returns a reference to its value. If not, inserts a new pair with default-constructed value and returns a reference to it.
| [in] | key | The key to access or insert. |
| std::bad_alloc | If insertion requires memory allocation. |
Definition at line 441 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Access value by key (const version).
| [in] | key | The key to access. |
| std::domain_error | If the key is not found. |
Definition at line 455 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::find().
|
inline |
Access or insert a value by key (move semantics).
| [in] | key | The key to access or insert. |
Definition at line 465 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Access value by key (const, move).
| [in] | key | The key to access. |
| std::domain_error | If the key is not found. |
Definition at line 479 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::find().
|
inline |
Remove an entry by key.
| [in] | key | The key to remove. |
| std::domain_error | If the key is not found. |
Definition at line 503 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Remove an entry by key (move semantics).
| [in] | key | The key to remove. |
| std::domain_error | If the key is not found. |
Definition at line 516 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Remove an entry by its data pointer.
Removes the key-value pair that contains the given data pointer.
| [in] | data | Reference to data within a stored pair. |
Definition at line 492 of file tpl_dynMapOhash.H.
References Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::data_to_pair().
|
inlinenoexcept |
Search for a key in the map.
| [in] | key | The key to search for. |
Definition at line 313 of file tpl_dynMapOhash.H.
References Aleph::maps().
Referenced by Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::has(), and Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::has().
|
inlinenoexcept |
Search for a key in the map (move semantics).
| [in] | key | The key to search for. |
Definition at line 325 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Get a list of all values in the map.
Definition at line 539 of file tpl_dynMapOhash.H.
References Aleph::maps().
|
inline |
Get a list of pointers to all values.
Definition at line 550 of file tpl_dynMapOhash.H.
References Aleph::DynList< T >::append(), and Aleph::maps().