Gromacs
2024.3
|
#include <gromacs/domdec/hashedmap.h>
Unordered key to value mapping.
Efficiently manages mapping from integer keys to values. Note that this basically implements a subset of the functionality of std::unordered_map, but is an order of magnitude faster.
Public Member Functions | |
HashedMap (int numElementsEstimate) | |
Constructor. More... | |
int | size () const |
Returns the number of elements. | |
int | bucket_count () const |
Returns the number of buckets, i.e. the number of possible hashes. | |
void | insert (int key, const T &value) |
Inserts entry, key should not already be present. More... | |
void | insert_or_assign (int key, const T &value) |
Inserts an entry when the key is not present, otherwise sets the value. More... | |
void | erase (int key) |
Delete the entry for key key , when present. More... | |
T * | find (int key) |
Returns a pointer to the value for the given key or nullptr when not present. More... | |
const T * | find (int key) const |
Returns a pointer to the value for the given key or nullptr when not present. More... | |
void | clear () |
Clear all the entries in the list. | |
void | clearAndResizeHashTable () |
Clear all the entries in the list and resizes the hash table. More... | |
|
inline |
Constructor.
[in] | numElementsEstimate | An estimate of the number of elements that will be stored, used for optimizing initial performance |
Note that the estimate of the number of elements is only relevant for the performance up until the first call to clear(), after which table size is optimized based on the actual number of elements.
|
inline |
Clear all the entries in the list and resizes the hash table.
Optimizes the size of the hash table based on the current number of elements stored.
|
inline |
Delete the entry for key key
, when present.
[in] | key | The key |
|
inline |
Returns a pointer to the value for the given key or nullptr when not present.
[in] | key | The key |
|
inline |
Returns a pointer to the value for the given key or nullptr when not present.
[in] | key | The key |
|
inline |
Inserts entry, key should not already be present.
[in] | key | The key for the entry |
[in] | value | The value for the entry |
InvalidInputError | from a debug build when attempting to inser |
|
inline |
Inserts an entry when the key is not present, otherwise sets the value.
[in] | key | The key for the entry |
[in] | value | The value for the entry |