Base Framework
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
HashTable< KEY, VALUE > Class Template Reference

Hash table collection. More...

#include <base/collection/HashTable.h>

Inherits Collection.

Classes

class  Element
 
class  HashTableEnumerator
 Hash set enumerator. More...
 
class  HashTableImpl
 
class  HashTableValueEnumerator
 Hash table value enumerator. More...
 
class  Node
 

Public Types

typedef KEY Key
 
typedef VALUE Value
 
typedef Association< Key, ValueHashTableAssociation
 
typedef HashTableEnumerator< ReadEnumeratorTraits< Association< Key, Value > > > ReadEnumerator
 
typedef HashTableValueEnumerator< EnumeratorTraits< Value > > ValueEnumerator
 
typedef HashTableValueEnumerator< ReadEnumeratorTraits< Value > > ReadValueEnumerator
 

Public Member Functions

void copyOnWrite ()
 
 HashTable ()
 
 HashTable (MemorySize capacity)
 
 HashTable (std::initializer_list< HashTableAssociation > values)
 
 HashTable (const HashTable &copy) noexcept
 
HashTableoperator= (const HashTable &assign) noexcept
 
void dump () noexcept
 
MemorySize getCapacity () const noexcept
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
bool hasKey (const Key &key) const noexcept
 
Valuefind (const Key &key)
 
const Valuefind (const Key &key) const
 
const ValuegetValue (const Key &key) const
 
void add (const Key &key, const Value &value)
 
void add (const Key &key, Value &&value)
 
void add (Key &&key, Value &&value)
 
void add (const HashTableAssociation &node)
 
void add (HashTableAssociation &&node)
 
void remove (const Key &key)
 
void removeAll () noexcept
 
ReadEnumerator getReadEnumerator () const noexcept
 
ValueEnumerator getValueEnumerator () noexcept
 
ReadValueEnumerator getReadValueEnumerator () const noexcept
 
Element operator[] (const Key &key)
 
const Valueoperator[] (const Key &key) const
 
 operator bool () const noexcept
 
HashTableoperator<< (const HashTableAssociation &value)
 
HashTableoperator<< (HashTableAssociation &&value)
 

Public Attributes

Reference< HashTableImplimpl
 

Static Public Attributes

static constexpr MemorySize MINIMUM_CAPACITY = 16
 
static constexpr MemorySize MAXIMUM_CAPACITY = PrimitiveTraits<unsigned int>::MAXIMUM/2
 
static constexpr MemorySize DEFAULT_CAPACITY = 16
 

Detailed Description

template<class KEY, class VALUE>
class HashTable< KEY, VALUE >

Hash table collection.

A hash table implementation.

Version
1.2
Examples
testsuite/eval.cpp, testsuite/HashTable.cpp, and testsuite/ls.cpp.

Member Typedef Documentation

◆ HashTableAssociation

template<class KEY , class VALUE >
typedef Association<Key, Value> HashTable< KEY, VALUE >::HashTableAssociation

The type of an association in the hash table.

◆ Key

template<class KEY , class VALUE >
typedef KEY HashTable< KEY, VALUE >::Key

The type of the key.

◆ ReadEnumerator

template<class KEY , class VALUE >
typedef HashTableEnumerator<ReadEnumeratorTraits<Association<Key, Value> > > HashTable< KEY, VALUE >::ReadEnumerator

Non-modifying enumerator.

◆ ReadValueEnumerator

template<class KEY , class VALUE >
typedef HashTableValueEnumerator<ReadEnumeratorTraits<Value> > HashTable< KEY, VALUE >::ReadValueEnumerator

Non-modifying value enumerator.

◆ Value

template<class KEY , class VALUE >
typedef VALUE HashTable< KEY, VALUE >::Value

The type of the value.

◆ ValueEnumerator

template<class KEY , class VALUE >
typedef HashTableValueEnumerator<EnumeratorTraits<Value> > HashTable< KEY, VALUE >::ValueEnumerator

Modifying value enumerator.

Constructor & Destructor Documentation

◆ HashTable() [1/3]

template<class KEY , class VALUE >
HashTable< KEY, VALUE >::HashTable ( )
inline

Initializes an hash table.

◆ HashTable() [2/3]

template<class KEY , class VALUE >
HashTable< KEY, VALUE >::HashTable ( MemorySize  capacity)
inline

Initializes the hash table with the specified initial capacity.

◆ HashTable() [3/3]

template<class KEY , class VALUE >
HashTable< KEY, VALUE >::HashTable ( const HashTable< KEY, VALUE > &  copy)
inlinenoexcept

Initializes hash table from other hash table.

Member Function Documentation

◆ add() [1/5]

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::add ( const HashTableAssociation node)
inline

Adds the key and value to the table.

◆ add() [2/5]

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::add ( const Key key,
const Value value 
)
inline

Adds the key and value to the table.

◆ add() [3/5]

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::add ( const Key key,
Value &&  value 
)
inline

Adds the key and value to the table.

◆ add() [4/5]

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::add ( HashTableAssociation &&  node)
inline

Adds the key and value to the table.

◆ add() [5/5]

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::add ( Key &&  key,
Value &&  value 
)
inline

Adds the key and value to the table.

◆ copyOnWrite()

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::copyOnWrite ( )
inline

Copies the hash set if referenced by multiple automation pointers.

◆ find() [1/2]

template<class KEY , class VALUE >
Value* HashTable< KEY, VALUE >::find ( const Key key)
inline

Returns the value associated with the specified key.

Parameters
keyThe key of the value.
Returns
nullptr is key doesn't exist.

◆ find() [2/2]

template<class KEY , class VALUE >
const Value* HashTable< KEY, VALUE >::find ( const Key key) const
inline

Returns the value associated with the specified key.

Parameters
keyThe key of the value.
Returns
nullptr is key doesn't exist.

◆ getCapacity()

template<class KEY , class VALUE >
MemorySize HashTable< KEY, VALUE >::getCapacity ( ) const
inlinenoexcept

Returns the capacity of the hash table.

◆ getReadEnumerator()

template<class KEY , class VALUE >
ReadEnumerator HashTable< KEY, VALUE >::getReadEnumerator ( ) const
inlinenoexcept

Returns a enumerator of the hash table for non-modifying access.

◆ getReadValueEnumerator()

template<class KEY , class VALUE >
ReadValueEnumerator HashTable< KEY, VALUE >::getReadValueEnumerator ( ) const
inlinenoexcept

Returns a enumerator of the values of the hash table for non-modifying access.

◆ getSize()

template<class KEY , class VALUE >
MemorySize HashTable< KEY, VALUE >::getSize ( ) const
inlinenoexcept

Returns the number of elements in the hash table.

◆ getValue()

template<class KEY , class VALUE >
const Value& HashTable< KEY, VALUE >::getValue ( const Key key) const
inline

Returns the value associated with the specified key. Raises InvalidKey if the specified key doesn't exist in this hash table.

Parameters
keyThe key of the value.

◆ getValueEnumerator()

template<class KEY , class VALUE >
ValueEnumerator HashTable< KEY, VALUE >::getValueEnumerator ( )
inlinenoexcept

Returns a enumerator of the values of the hash table for modifying access.

◆ hasKey()

template<class KEY , class VALUE >
bool HashTable< KEY, VALUE >::hasKey ( const Key key) const
inlinenoexcept

Returns true if the specified value is a key in the table.

◆ isEmpty()

template<class KEY , class VALUE >
bool HashTable< KEY, VALUE >::isEmpty ( ) const
inlinenoexcept

Returns true if the hash table is empty.

◆ operator bool()

template<class KEY , class VALUE >
HashTable< KEY, VALUE >::operator bool ( ) const
inlinenoexcept

Returns true is non-empty.

◆ operator<<() [1/2]

template<class KEY , class VALUE >
HashTable& HashTable< KEY, VALUE >::operator<< ( const HashTableAssociation value)
inline

Adds value.

◆ operator<<() [2/2]

template<class KEY , class VALUE >
HashTable& HashTable< KEY, VALUE >::operator<< ( HashTableAssociation &&  value)
inline

Adds value.

◆ operator=()

template<class KEY , class VALUE >
HashTable& HashTable< KEY, VALUE >::operator= ( const HashTable< KEY, VALUE > &  assign)
inlinenoexcept

Assignment of hash table by hash table.

◆ operator[]() [1/2]

template<class KEY , class VALUE >
Element HashTable< KEY, VALUE >::operator[] ( const Key key)
inline

Returns the value associated with the specified key when used as 'rvalue'. When used as 'lvalue' the key is associated with the specified value.

◆ operator[]() [2/2]

template<class KEY , class VALUE >
const Value& HashTable< KEY, VALUE >::operator[] ( const Key key) const
inline

Returns the value associated with the specified key.

◆ remove()

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::remove ( const Key key)
inline

Removes the specified key and its associated value from this hash table. Raises InvalidKey if the key doesn't exist in this hash table.

◆ removeAll()

template<class KEY , class VALUE >
void HashTable< KEY, VALUE >::removeAll ( )
inlinenoexcept

Removes all the keys from this hash table.

Member Data Documentation

◆ DEFAULT_CAPACITY

template<class KEY , class VALUE >
constexpr MemorySize HashTable< KEY, VALUE >::DEFAULT_CAPACITY = 16
staticconstexpr

The default capacity.

◆ impl

template<class KEY , class VALUE >
Reference<HashTableImpl> HashTable< KEY, VALUE >::impl

Hash table implementation.

◆ MAXIMUM_CAPACITY

template<class KEY , class VALUE >
constexpr MemorySize HashTable< KEY, VALUE >::MAXIMUM_CAPACITY = PrimitiveTraits<unsigned int>::MAXIMUM/2
staticconstexpr

The maximum capacity.

◆ MINIMUM_CAPACITY

template<class KEY , class VALUE >
constexpr MemorySize HashTable< KEY, VALUE >::MINIMUM_CAPACITY = 16
staticconstexpr

The minimum capacity.