AGX Dynamics  2.35.0.1
agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT > Class Template Reference

A cache-friendly hash table with open addressing, linear probing and power-of-two capacity. More...

#include <LinearProbingHashTable.h>

+ Inheritance diagram for agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >:

Classes

class  const_iterator
 
class  insert_iterator
 
class  iterator
 

Public Types

using bucket_type = PairT
 
enum  ClearPolicy { SHRINK_BUFFER , SHRINK_BUFFER_AVERAGED , MAINTAIN_BUFFER }
 
using const_reference = const PairT &
 
using key_type = KeyT
 
using reference = PairT &
 
using size_type = size_t
 
using value_type = ValueT
 

Public Member Functions

 LinearProbingHashTableImplementation ()=default
 
 LinearProbingHashTableImplementation (const LinearProbingHashTableImplementation &other)
 
 LinearProbingHashTableImplementation (LinearProbingHashTableImplementation &&other)
 
 ~LinearProbingHashTableImplementation ()
 
iterator begin ()
 Iterator to first element in hash table. More...
 
const_iterator begin () const
 Iterator to first element in hash table. More...
 
size_t capacity () const
 
void clear (int=0)
 Remove all elements, keeping full capacity. More...
 
bool contains (const KeyT &k) const
 Check if the hash table contains a key/value pair for the given key. More...
 
size_t count (const KeyT &k) const
 Count the number of key/value pairs matching the given key. More...
 
bool empty () const
 
iterator end ()
 Iterator marking end of hash table. More...
 
const_iterator end () const
 Iterator marking end of hash table. More...
 
bool erase (const KeyT &key)
 Erase an element from the hash table. More...
 
iterator erase (iterator it)
 Erase an element from the hash table. More...
 
iterator find (const KeyT &key)
 Find a key/value pair in the hash table given a key. More...
 
const_iterator find (const KeyT &key) const
 Find a key/value pair in the hash table given a key. More...
 
const ValueT get_or_return_default (const KeyT &k) const
 
insert_iterator insert (const KeyT &key, const ValueT value)
 Insert a key/value pair into the hash table. More...
 
insert_iterator insert (const std::pair< KeyT, ValueT > &p)
 
void insert (const_iterator begin, const_iterator end)
 Insert all elements in the given range. More...
 
void insert_unique (KeyT &&key, ValueT &&value)
 Insert a key/value pair into the hash table assuming that the given key does not already exist in the hash table. More...
 
void insert_unique (std::pair< KeyT, ValueT > &&p)
 
LinearProbingHashTableImplementation & operator= (const LinearProbingHashTableImplementation &other)
 
LinearProbingHashTableImplementation & operator= (LinearProbingHashTableImplementation &&other)
 
ValueT & operator[] (const KeyT &key)
 Return the value associated with the given key. More...
 
const void * ptr () const
 
void reserve (size_t num_elems)
 Make room for this many elements in the hash table. More...
 
ValueT set_get (const KeyT &key, const ValueT &new_value)
 
size_t size () const
 
void swap (LinearProbingHashTableImplementation &other)
 
ValueT * try_get (const KeyT &k)
 Find the value associated with the given key. More...
 
const ValueT * try_get (const KeyT &k) const
 Find the value associated with the given key. More...
 

Protected Member Functions

void erase_bucket (size_t bucket)
 
template<typename T2 >
size_t find_filled_bucket (const T2 &key) const
 

Detailed Description

template<typename KeyT, typename ValueT, typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
class agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >

A cache-friendly hash table with open addressing, linear probing and power-of-two capacity.

Definition at line 47 of file LinearProbingHashTable.h.

Member Typedef Documentation

◆ bucket_type

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
using agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::bucket_type = PairT

Definition at line 64 of file LinearProbingHashTable.h.

◆ const_reference

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
using agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::const_reference = const PairT&

Definition at line 66 of file LinearProbingHashTable.h.

◆ key_type

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
using agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::key_type = KeyT

Definition at line 61 of file LinearProbingHashTable.h.

◆ reference

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
using agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::reference = PairT&

Definition at line 65 of file LinearProbingHashTable.h.

◆ size_type

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
using agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::size_type = size_t

Definition at line 62 of file LinearProbingHashTable.h.

◆ value_type

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
using agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::value_type = ValueT

Definition at line 63 of file LinearProbingHashTable.h.

Member Enumeration Documentation

◆ ClearPolicy

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
enum agx::LinearProbingHashTableImplementation::ClearPolicy
Enumerator
SHRINK_BUFFER 

Buffer is deallocated and replaced by an newly allocated empty buffer.

SHRINK_BUFFER_AVERAGED 

Buffer is shrunk if a smoothing average (which is updated each clear call) goes below a threshold.

MAINTAIN_BUFFER 

Buffer is maintained (normal stl behavior).

Definition at line 73 of file LinearProbingHashTable.h.

Constructor & Destructor Documentation

◆ LinearProbingHashTableImplementation() [1/3]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::LinearProbingHashTableImplementation ( )
default

◆ LinearProbingHashTableImplementation() [2/3]

◆ LinearProbingHashTableImplementation() [3/3]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::LinearProbingHashTableImplementation ( LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT > &&  other)
inline

Definition at line 312 of file LinearProbingHashTable.h.

◆ ~LinearProbingHashTableImplementation()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::~LinearProbingHashTableImplementation ( )
inline

Definition at line 331 of file LinearProbingHashTable.h.

Member Function Documentation

◆ begin() [1/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::begin ( )
inline

◆ begin() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
const_iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::begin ( ) const
inline

Iterator to first element in hash table.

Definition at line 372 of file LinearProbingHashTable.h.

◆ capacity()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
size_t agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::capacity ( ) const
inline
Returns
The total number of buckets in the hash table.

Definition at line 406 of file LinearProbingHashTable.h.

◆ clear()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::clear ( int  = 0)
inline

◆ contains()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
bool agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::contains ( const KeyT &  k) const
inline

Check if the hash table contains a key/value pair for the given key.

Parameters
kKey to look for.
Returns
True if the key exists in the hash table. False otherwise.

Definition at line 455 of file LinearProbingHashTable.h.

References agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find_filled_bucket().

Referenced by agx::HashVector< KeyT, DataT, HashT >::contains(), agx::SetVector< DataT, HashT >::contains(), and agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert_unique().

◆ count()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
size_t agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::count ( const KeyT &  k) const
inline

Count the number of key/value pairs matching the given key.

Will always be either 0 or 1.

Parameters
kThe key to count.
Returns
1 if the key exists in the hash table, 0 otherwise.

Definition at line 466 of file LinearProbingHashTable.h.

References agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find_filled_bucket().

◆ empty()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
bool agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::empty ( ) const
inline
Returns
True if the hash table contains no key/value pairs. False otherwise.

Definition at line 414 of file LinearProbingHashTable.h.

Referenced by agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find_filled_bucket().

◆ end() [1/2]

◆ end() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
const_iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::end ( ) const
inline

Iterator marking end of hash table.

Definition at line 392 of file LinearProbingHashTable.h.

◆ erase() [1/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
bool agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::erase ( const KeyT &  key)
inline

◆ erase() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::erase ( iterator  it)
inline

◆ erase_bucket()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::erase_bucket ( size_t  bucket)
inlineprotected

◆ find() [1/2]

◆ find() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
const_iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find ( const KeyT &  key) const
inline

Find a key/value pair in the hash table given a key.

Parameters
keyThe key to look for.
Returns
Iterator to the key/value pair, or the end iterator if no such key exists.

Definition at line 440 of file LinearProbingHashTable.h.

References agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::end(), and agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find_filled_bucket().

◆ find_filled_bucket()

◆ get_or_return_default()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
const ValueT agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::get_or_return_default ( const KeyT &  k) const
inline

◆ insert() [1/3]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
insert_iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert ( const KeyT &  key,
const ValueT  value 
)
inline

◆ insert() [2/3]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
insert_iterator agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert ( const std::pair< KeyT, ValueT > &  p)
inline

◆ insert() [3/3]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert ( const_iterator  begin,
const_iterator  end 
)
inline

◆ insert_unique() [1/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert_unique ( KeyT &&  key,
ValueT &&  value 
)
inline

Insert a key/value pair into the hash table assuming that the given key does not already exist in the hash table.

It is undefined behavior to call this method with a key that does already exist in the hash table.

Parameters
keyThe key to insert.
valueThe value to associate with the key.

Definition at line 566 of file LinearProbingHashTable.h.

References agxAssert, and agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::contains().

Referenced by agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert_unique().

◆ insert_unique() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::insert_unique ( std::pair< KeyT, ValueT > &&  p)
inline

◆ operator=() [1/2]

◆ operator=() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
LinearProbingHashTableImplementation& agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::operator= ( LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT > &&  other)
inline

◆ operator[]()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
ValueT& agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::operator[] ( const KeyT &  key)
inline

Return the value associated with the given key.

A new value is default created, inserted and then returned if the given key does not yet exist in the hash table.

Parameters
keyThe key to find.
Returns
The value associated with the given key. A default constructed one if no prior value existed.

Definition at line 608 of file LinearProbingHashTable.h.

◆ ptr()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
const void* agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::ptr ( ) const
inline
Returns
Raw memory access to the key/value buckets.

Definition at line 729 of file LinearProbingHashTable.h.

◆ reserve()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::reserve ( size_t  num_elems)
inline

◆ set_get()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
ValueT agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::set_get ( const KeyT &  key,
const ValueT &  new_value 
)
inline

Definition at line 582 of file LinearProbingHashTable.h.

◆ size()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
size_t agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::size ( ) const
inline

◆ swap()

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
void agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::swap ( LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT > &  other)
inline

◆ try_get() [1/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
ValueT* agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::try_get ( const KeyT &  k)
inline

Find the value associated with the given key.

Returns nullptr if no such value exists.

Parameters
kThe key to look for.
Returns
Pointer to the corresponding value, or nullptr.

Definition at line 476 of file LinearProbingHashTable.h.

References agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find_filled_bucket().

Referenced by agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::get_or_return_default().

◆ try_get() [2/2]

template<typename KeyT , typename ValueT , typename HashT = agx::HashFn<KeyT>, typename AllocatorT = ByteAllocator>
const ValueT* agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::try_get ( const KeyT &  k) const
inline

Find the value associated with the given key.

Returns nullptr if no such value exists.

Parameters
kThe key to look for.
Returns
Pointer to the corresponding value, or nullptr.

Definition at line 491 of file LinearProbingHashTable.h.

References agx::LinearProbingHashTableImplementation< KeyT, ValueT, HashT, AllocatorT >::find_filled_bucket().


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