cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
cppcore::THashMap< T, U, TAlloc > Class Template Reference

This class implements a hash map. More...

#include <THashMap.h>

Public Types

using Hash = THash<T>
 The alias.

Public Member Functions

 THashMap (size_t init=InitSize)
 The class constructor.
 ~THashMap ()
 The class destructor.
size_t size () const
 Returns the number of stored items in the hash-map.
size_t capacity () const
 Will return the number of possible hash items stored in the hash map.
bool isEmpty () const
 Will return true, if hash-map is empty.
void init (size_t init)
 Will init the hash-map with the given size.
void clear ()
 The hash-map will be cleared.
void insert (const T &key, const U &value)
 A new key value pair will be entered.
bool remove (const T &key)
 Will remove a given key-value pair form the hash-map.
bool hasKey (const T &key) const
 Looks for a given key and returns true, if a key-value pair is stored in the list.
bool getValue (const T &key, U &value) const
 Returns the assigned value for the given key.
U & operator[] (const T &key) const
 Returns the assigned value for the given key.
 THashMap (const THashMap< T, U > &)=delete
 Avoid copying.
THashMap< T, U, TAlloc > & operator= (const THashMap< T, U > &)=delete

Static Public Attributes

static constexpr size_t InitSize = 1024
 The initial hash size.
static constexpr unsigned int UnsetNode = 999999999
 Marker for unset node keys.

Detailed Description

template<class T, class U, class TAlloc = TDefaultAllocator<T>>
class cppcore::THashMap< T, U, TAlloc >

This class implements a hash map.

Utility class for common memory operations.

You can work with the hashmap in the following way:

using TestHashMap = THashMap<int, String>:
TestHashMap hm;
hm.insert(1, "test");
hm.hasKey(1); // will return true;
hm.remove(1);
hm.hasKey(1); // will return false;
THashMap(size_t init=InitSize)
The class constructor.
Definition THashMap.h:133

Definition at line 48 of file THashMap.h.

Member Typedef Documentation

◆ Hash

template<class T, class U, class TAlloc = TDefaultAllocator<T>>
using cppcore::THashMap< T, U, TAlloc >::Hash = THash<T>

The alias.

Definition at line 51 of file THashMap.h.

Constructor & Destructor Documentation

◆ THashMap() [1/2]

template<class T, class U, class TAlloc>
cppcore::THashMap< T, U, TAlloc >::THashMap ( size_t init = InitSize)
inlineexplicit

The class constructor.

Parameters
init[in] The initial size for the hash.

Definition at line 133 of file THashMap.h.

References init().

Referenced by operator=(), and THashMap().

◆ ~THashMap()

template<class T, class U, class TAlloc>
cppcore::THashMap< T, U, TAlloc >::~THashMap ( )
inline

The class destructor.

Definition at line 138 of file THashMap.h.

References clear().

◆ THashMap() [2/2]

template<class T, class U, class TAlloc = TDefaultAllocator<T>>
cppcore::THashMap< T, U, TAlloc >::THashMap ( const THashMap< T, U > & )
delete

Avoid copying.

References THashMap().

Member Function Documentation

◆ capacity()

template<class T, class U, class TAlloc>
size_t cppcore::THashMap< T, U, TAlloc >::capacity ( ) const
inline

Will return the number of possible hash items stored in the hash map.

Returns
The number of possible hash items.

Definition at line 148 of file THashMap.h.

◆ clear()

template<class T, class U, class TAlloc>
void cppcore::THashMap< T, U, TAlloc >::clear ( )
inline

The hash-map will be cleared.

Definition at line 167 of file THashMap.h.

Referenced by ~THashMap().

◆ getValue()

template<class T, class U, class TAlloc>
bool cppcore::THashMap< T, U, TAlloc >::getValue ( const T & key,
U & value ) const
inline

Returns the assigned value for the given key.

Parameters
[in]keyThe key to look for.
[in]valueThe value, unset when no key-value pair was found.
Returns
true, if key-value pair was found, false if not.

Definition at line 249 of file THashMap.h.

References cppcore::THash< T >::toHash().

◆ hasKey()

template<class T, class U, class TAlloc>
bool cppcore::THashMap< T, U, TAlloc >::hasKey ( const T & key) const
inline

Looks for a given key and returns true, if a key-value pair is stored in the list.

Parameters
[in]keyThe key to look for.
Returns
true, if key-value pair was found.

Definition at line 220 of file THashMap.h.

References cppcore::THash< T >::toHash().

◆ init()

template<class T, class U, class TAlloc>
void cppcore::THashMap< T, U, TAlloc >::init ( size_t init)
inline

Will init the hash-map with the given size.

Parameters
[in]initThe initial size for the hash.

Definition at line 158 of file THashMap.h.

References init().

Referenced by init(), and THashMap().

◆ insert()

template<class T, class U, class TAlloc>
void cppcore::THashMap< T, U, TAlloc >::insert ( const T & key,
const U & value )
inline

A new key value pair will be entered.

Parameters
[in]keyThe key.
[in]valueThe value to store.

Definition at line 180 of file THashMap.h.

References cppcore::THash< T >::toHash().

◆ isEmpty()

template<class T, class U, class TAlloc>
bool cppcore::THashMap< T, U, TAlloc >::isEmpty ( ) const
inline

Will return true, if hash-map is empty.

Returns
true for empty, false for not empty.

Definition at line 153 of file THashMap.h.

◆ operator=()

template<class T, class U, class TAlloc = TDefaultAllocator<T>>
THashMap< T, U, TAlloc > & cppcore::THashMap< T, U, TAlloc >::operator= ( const THashMap< T, U > & )
delete

References remove(), THashMap(), and UnsetNode.

◆ operator[]()

template<class T, class U, class TAlloc>
U & cppcore::THashMap< T, U, TAlloc >::operator[] ( const T & key) const
inline

Returns the assigned value for the given key.

Parameters
[in]keyThe key to look for.
Returns
The value, will unset when no key-value pair was found.

Definition at line 270 of file THashMap.h.

References cppcore::THash< T >::toHash().

◆ remove()

template<class T, class U, class TAlloc>
bool cppcore::THashMap< T, U, TAlloc >::remove ( const T & key)
inline

Will remove a given key-value pair form the hash-map.

Parameters
[in]keyThe key to look for.
Returns
true, if key-value pair was found and removed.

Definition at line 194 of file THashMap.h.

References cppcore::THash< T >::toHash().

Referenced by operator=().

◆ size()

template<class T, class U, class TAlloc>
size_t cppcore::THashMap< T, U, TAlloc >::size ( ) const
inline

Returns the number of stored items in the hash-map.

Returns
The number of items within the hash-map.

Definition at line 143 of file THashMap.h.

Member Data Documentation

◆ InitSize

template<class T, class U, class TAlloc = TDefaultAllocator<T>>
size_t cppcore::THashMap< T, U, TAlloc >::InitSize = 1024
staticconstexpr

The initial hash size.

Definition at line 54 of file THashMap.h.

◆ UnsetNode

template<class T, class U, class TAlloc = TDefaultAllocator<T>>
unsigned int cppcore::THashMap< T, U, TAlloc >::UnsetNode = 999999999
staticconstexpr

Marker for unset node keys.

Definition at line 56 of file THashMap.h.

Referenced by operator=().


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