Gromacs  2021.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::HashedMap< T > Class Template Reference

#include <gromacs/domdec/hashedmap.h>

Description

template<typename T>
class gmx::HashedMap< T >

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...
 

Constructor & Destructor Documentation

template<typename T>
gmx::HashedMap< T >::HashedMap ( int  numElementsEstimate)
inline

Constructor.

Parameters
[in]numElementsEstimateAn 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.

Member Function Documentation

template<typename T>
void gmx::HashedMap< T >::clearAndResizeHashTable ( )
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.

template<typename T>
void gmx::HashedMap< T >::erase ( int  key)
inline

Delete the entry for key key, when present.

Parameters
[in]keyThe key
template<typename T>
T* gmx::HashedMap< T >::find ( int  key)
inline

Returns a pointer to the value for the given key or nullptr when not present.

Todo:
Use std::as_const when CUDA 11 is a requirement.
Parameters
[in]keyThe key
Returns
a pointer to value for the given key or nullptr when not present
template<typename T>
const T* gmx::HashedMap< T >::find ( int  key) const
inline

Returns a pointer to the value for the given key or nullptr when not present.

Parameters
[in]keyThe key
Returns
a pointer to value for the given key or nullptr when not present
template<typename T>
void gmx::HashedMap< T >::insert ( int  key,
const T &  value 
)
inline

Inserts entry, key should not already be present.

Parameters
[in]keyThe key for the entry
[in]valueThe value for the entry
Exceptions
InvalidInputErrorfrom a debug build when attempting to inser
template<typename T>
void gmx::HashedMap< T >::insert_or_assign ( int  key,
const T &  value 
)
inline

Inserts an entry when the key is not present, otherwise sets the value.

Parameters
[in]keyThe key for the entry
[in]valueThe value for the entry

The documentation for this class was generated from the following files: