NDEVR
API Documentation
Dictionary< t_key, t_value, t_hash >

A hash-based key-value store, useful for quick associative lookups. More...

Inherits .

Collaboration diagram for Dictionary< t_key, t_value, t_hash >:
[legend]

Public Member Functions

 Dictionary ()
 Constructs an empty Dictionary.
void add (const t_key &key)
 Inserts a key with a default-constructed value if the key does not already exist.
void add (const t_key &key, const t_value &value)
 Inserts a key-value pair if the key does not already exist.
template<class t_key_type>
void add (const t_key_type &key, const t_value &value)
 Inserts a key-value pair using a convertible key type, if the key does not already exist.
void add (t_key &&key)
 Inserts a key with a default-constructed value using move semantics, if the key does not already exist.
decltype(auto) first () const
 Retrieves an iterator to the first entry in the dictionary.
template<class t_key_type>
t_value & get (const t_key_type &key)
 Retrieves a mutable reference to the value associated with the given key.
template<class t_key_type>
const t_value & get (const t_key_type &key) const
 Retrieves a const reference to the value associated with the given key.
decltype(auto) getFromIndex (uint04 index) const
 Retrieves an iterator to the entry at the given iteration index.
template<class t_key_type>
bool hasKey (const t_key_type &key) const
 Checks whether the dictionary contains the given key.
uint04 indexOf (const t_key &key) const
 Finds the iteration index of the given key within the dictionary.
template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_key, DetermineAlignment<sizeof(t_key)>(), ObjectInfo<t_key>::Primitive, t_index_type, false>>
Buffer< t_key, t_memory_manager > keys () const
 Collects all keys in the dictionary into a Buffer.
template<class t_key_type>
t_value & operator[] (const t_key_type &key)
 Subscript operator that retrieves or inserts the value associated with the given key.
template<class t_key_type>
const t_value & operator[] (const t_key_type &key) const
 Const subscript operator that retrieves the value associated with the given key.
void removeIndex (uint04 index)
 Removes the entry at the given iteration index.
template<class t_key_type>
void set (const t_key_type &key, const t_value &value)
 Sets the value for an existing key, replacing the previous value.
uint04 size () const
 Returns the number of entries in the dictionary.
template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_value, DetermineAlignment<sizeof(t_value)>(), ObjectInfo<t_value>::Primitive, t_index_type, false>>
Buffer< t_value, t_memory_manager > values () const
 Collects all values in the dictionary into a Buffer.

Detailed Description

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
class Dictionary< t_key, t_value, t_hash >

A hash-based key-value store, useful for quick associative lookups.


Key features include:

  • Uses tsl robin library as backing logic and hashmap. Proven to be significantly faster in almost all metrics over std::unordered_set on modern architecture
  • Easy functions for converting to other NDEVR containers
See also
Buffer, Set

Definition at line 63 of file Dictionary.h.

Member Function Documentation

◆ add() [1/4]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
void Dictionary< t_key, t_value, t_hash >::add ( const t_key & key)
inline

Inserts a key with a default-constructed value if the key does not already exist.

Parameters
[in]keyThe key to insert.

Definition at line 106 of file Dictionary.h.

◆ add() [2/4]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
void Dictionary< t_key, t_value, t_hash >::add ( const t_key & key,
const t_value & value )
inline

Inserts a key-value pair if the key does not already exist.

Parameters
[in]keyThe key to insert.
[in]valueThe value to associate with the key.

Definition at line 87 of file Dictionary.h.

◆ add() [3/4]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
void Dictionary< t_key, t_value, t_hash >::add ( const t_key_type & key,
const t_value & value )
inline

Inserts a key-value pair using a convertible key type, if the key does not already exist.

Parameters
[in]keyThe key to insert, which will be converted to t_key.
[in]valueThe value to associate with the key.

Definition at line 97 of file Dictionary.h.

◆ add() [4/4]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
void Dictionary< t_key, t_value, t_hash >::add ( t_key && key)
inline

Inserts a key with a default-constructed value using move semantics, if the key does not already exist.

Parameters
[in]keyThe key to insert via move.

Definition at line 114 of file Dictionary.h.

◆ first()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
decltype(auto) Dictionary< t_key, t_value, t_hash >::first ( ) const
inlinenodiscard

Retrieves an iterator to the first entry in the dictionary.

Returns
An iterator pointing to the first entry.

Definition at line 204 of file Dictionary.h.

◆ get() [1/2]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
t_value & Dictionary< t_key, t_value, t_hash >::get ( const t_key_type & key)
inlinenodiscard

Retrieves a mutable reference to the value associated with the given key.

Parameters
[in]keyThe key to look up.
Returns
A mutable reference to the value associated with the key.

Definition at line 134 of file Dictionary.h.

◆ get() [2/2]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
const t_value & Dictionary< t_key, t_value, t_hash >::get ( const t_key_type & key) const
inlinenodiscard

Retrieves a const reference to the value associated with the given key.

Parameters
[in]keyThe key to look up.
Returns
A const reference to the value associated with the key.

Definition at line 124 of file Dictionary.h.

Referenced by TranslationTools::convertFromBrackets(), and DevActionTree::init().

◆ getFromIndex()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
decltype(auto) Dictionary< t_key, t_value, t_hash >::getFromIndex ( uint04 index) const
inlinenodiscard

Retrieves an iterator to the entry at the given iteration index.

Parameters
[in]indexThe zero-based iteration index.
Returns
An iterator pointing to the entry at the specified index.

Definition at line 196 of file Dictionary.h.

◆ hasKey()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
bool Dictionary< t_key, t_value, t_hash >::hasKey ( const t_key_type & key) const
inlinenodiscard

Checks whether the dictionary contains the given key.

Parameters
[in]keyThe key to search for.
Returns
True if the key exists in the dictionary, false otherwise.

Definition at line 78 of file Dictionary.h.

Referenced by Dictionary< uint04, Vertex< 2, fltp08 > >::get(), and Dictionary< uint04, Vertex< 2, fltp08 > >::operator[]().

◆ indexOf()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
uint04 Dictionary< t_key, t_value, t_hash >::indexOf ( const t_key & key) const
inlinenodiscard

Finds the iteration index of the given key within the dictionary.

Parameters
[in]keyThe key to search for.
Returns
The zero-based index of the key, or Constant<uint04>::Invalid if not found.

Definition at line 172 of file Dictionary.h.

◆ keys()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_key, DetermineAlignment<sizeof(t_key)>(), ObjectInfo<t_key>::Primitive, t_index_type, false>>
Buffer< t_key, t_memory_manager > Dictionary< t_key, t_value, t_hash >::keys ( ) const
inlinenodiscard

Collects all keys in the dictionary into a Buffer.

Returns
A Buffer containing all keys in the dictionary.

Definition at line 144 of file Dictionary.h.

Referenced by Dictionary< uint04, Vertex< 2, fltp08 > >::keys().

◆ operator[]() [1/2]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
t_value & Dictionary< t_key, t_value, t_hash >::operator[] ( const t_key_type & key)
inlinenodiscard

Subscript operator that retrieves or inserts the value associated with the given key.

Parameters
[in]keyThe key to look up or insert.
Returns
A mutable reference to the value associated with the key.

Definition at line 235 of file Dictionary.h.

◆ operator[]() [2/2]

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
const t_value & Dictionary< t_key, t_value, t_hash >::operator[] ( const t_key_type & key) const
inlinenodiscard

Const subscript operator that retrieves the value associated with the given key.

Parameters
[in]keyThe key to look up.
Returns
A const reference to the value associated with the key.

Definition at line 224 of file Dictionary.h.

◆ removeIndex()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
void Dictionary< t_key, t_value, t_hash >::removeIndex ( uint04 index)
inline

Removes the entry at the given iteration index.

Parameters
[in]indexThe zero-based iteration index of the entry to remove.

Definition at line 187 of file Dictionary.h.

◆ set()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_key_type>
void Dictionary< t_key, t_value, t_hash >::set ( const t_key_type & key,
const t_value & value )
inline

Sets the value for an existing key, replacing the previous value.

Parameters
[in]keyThe key whose value to update.
[in]valueThe new value to assign.

Definition at line 214 of file Dictionary.h.

◆ size()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
uint04 Dictionary< t_key, t_value, t_hash >::size ( ) const
inlinenodiscard

Returns the number of entries in the dictionary.

Returns
The number of key-value pairs stored.

Definition at line 243 of file Dictionary.h.

Referenced by Dictionary< uint04, Vertex< 2, fltp08 > >::keys(), and Dictionary< uint04, Vertex< 2, fltp08 > >::values().

◆ values()

template<class t_key, class t_value, class t_hash = std::hash<t_key>>
template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_value, DetermineAlignment<sizeof(t_value)>(), ObjectInfo<t_value>::Primitive, t_index_type, false>>
Buffer< t_value, t_memory_manager > Dictionary< t_key, t_value, t_hash >::values ( ) const
inlinenodiscard

Collects all values in the dictionary into a Buffer.

Returns
A Buffer containing all values in the dictionary.

Definition at line 158 of file Dictionary.h.

Referenced by Dictionary< uint04, Vertex< 2, fltp08 > >::values().


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