AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
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  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.
 
const_iterator begin () const
 Iterator to first element in hash table.
 
size_t capacity () const
 
void clear (int policy=SHRINK_BUFFER_AVERAGED)
 Remove all elements.
 
void clearResize (size_t num_elems)
 Resize the table to fit at least num_elems elements and clear all existing entries.
 
bool contains (const KeyT &k) const
 Check if the hash table contains a key/value pair for the given key.
 
size_t count (const KeyT &k) const
 Count the number of key/value pairs matching the given key.
 
bool empty () const
 
iterator end ()
 Iterator marking end of hash table.
 
const_iterator end () const
 Iterator marking end of hash table.
 
bool erase (const KeyT &key)
 Erase an element from the hash table.
 
iterator erase (iterator it)
 Erase an element from the hash table.
 
iterator find (const KeyT &key)
 Find a key/value pair in the hash table given a key.
 
const_iterator find (const KeyT &key) const
 Find a key/value pair in the hash table given a key.
 
const ValueT get_or_return_default (const KeyT &k) const
 
iterator insert (const KeyT &key, const ValueT value)
 Insert a key/value pair into the hash table.
 
iterator insert (const std::pair< KeyT, ValueT > &p)
 
void insert (const_iterator begin, const_iterator end)
 Insert all elements in the given range.
 
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.
 
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.
 
const void * ptr () const
 
void reserve (size_t num_elems)
 Make room for this many elements in the hash table.
 
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.
 
const ValueT * try_get (const KeyT &k) const
 Find the value associated with the given key.
 

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 48 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 69 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 71 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 66 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 70 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 67 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 68 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 78 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]

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

◆ 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 293 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 316 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 357 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 391 of file LinearProbingHashTable.h.

◆ clear()

◆ clearResize()

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

Resize the table to fit at least num_elems elements and clear all existing entries.

Definition at line 744 of file LinearProbingHashTable.h.

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

◆ 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

◆ 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 451 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

◆ 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 377 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 425 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>
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>
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 548 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 590 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 783 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 564 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 461 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 476 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: