Ocean
Ocean::HashMap< TKey, T > Class Template Reference

This class implements a hash map. More...

Public Member Functions

 HashMap (const HashMap< TKey, T > &hashMap)
 Copy constructor. More...
 
 HashMap (HashMap< TKey, T > &&hashMap) noexcept
 Move constructor. More...
 
 HashMap (const size_t capacity, const ValueFunction &function=defaultHashFunction)
 Creates a new hash map object by a given capacity. More...
 
bool insert (const TKey &key, const T &element, const bool oneOnly=true, const bool extendCapacity=true)
 Adds a new element to this hash map. More...
 
bool insert (TKey &&key, T &&element, const bool oneOnly=true, const bool extendCapacity=true)
 Adds (moves) a new element to this hash map. More...
 
bool remove (const TKey &key)
 Removes an element from this hash map. More...
 
bool find (const TKey &key) const
 Returns whether this hash map holds a given element. More...
 
bool find (const TKey &key, const T *&element) const
 Returns whether this hash map holds a given element. More...
 
bool find (const TKey &key, T *&element)
 Returns whether this hash map holds a given element. More...
 
const T & element (const TKey &key) const
 Returns a specific element of this map. More...
 
void clear ()
 Removes all elements from this has map. More...
 
size_t size () const
 Returns the number of elements this hash map currently holds. More...
 
size_t capacity () const
 Returns the capacity of this hash map. More...
 
bool isEmpty () const
 Returns whether this hash map is empty. More...
 
HashMap< TKey, T > & operator= (const HashMap< TKey, T > &hashMap)
 Assign operator. More...
 
HashMap< TKey, T > & operator= (HashMap< TKey, T > &&hashMap) noexcept
 Move operator. More...
 

Protected Types

typedef std::pair< std::pair< size_t, size_t >, std::pair< TKey, T > > Element
 Definition of a pair combining a counter states and an object. More...
 
typedef std::vector< ElementElements
 Definition of a vector holding the map objects. More...
 
typedef size_t(* ValueFunction) (const TKey &key)
 Definition of a function pointer returning a hash map value. More...
 

Protected Member Functions

 HashMap (size_t capacity, HashMap< TKey, T > &&hashMap)
 Creates a new hash map by a given hash map. More...
 
bool isConsistent () const
 Returns whether this hash map is still consistent. More...
 

Static Protected Member Functions

static size_t defaultHashFunction (const TKey &key)
 Default hash function for elements supporting an cast size_t cast. More...
 

Protected Attributes

Elements mapElements
 Hash map elements. More...
 
size_t mapSize
 Number of elements this has map holds. More...
 
ValueFunction mapFunction
 Value function. More...
 

Detailed Description

template<typename TKey, typename T>
class Ocean::HashMap< TKey, T >

This class implements a hash map.

Template Parameters
TKeyThe data type of the key that is associated with the data element
TThe data type of the data elements that are stored in the hash map

Member Typedef Documentation

◆ Element

template<typename TKey , typename T >
typedef std::pair< std::pair<size_t, size_t>, std::pair<TKey, T> > Ocean::HashMap< TKey, T >::Element
protected

Definition of a pair combining a counter states and an object.

◆ Elements

template<typename TKey , typename T >
typedef std::vector<Element> Ocean::HashMap< TKey, T >::Elements
protected

Definition of a vector holding the map objects.

◆ ValueFunction

template<typename TKey , typename T >
typedef size_t(* Ocean::HashMap< TKey, T >::ValueFunction) (const TKey &key)
protected

Definition of a function pointer returning a hash map value.

Constructor & Destructor Documentation

◆ HashMap() [1/4]

template<typename TKey , typename T >
Ocean::HashMap< TKey, T >::HashMap ( const HashMap< TKey, T > &  hashMap)
inline

Copy constructor.

Parameters
hashMapThe hash map to copy

◆ HashMap() [2/4]

template<typename TKey , typename T >
Ocean::HashMap< TKey, T >::HashMap ( HashMap< TKey, T > &&  hashMap)
inlinenoexcept

Move constructor.

Parameters
hashMapThe hash map to move

◆ HashMap() [3/4]

template<typename TKey , typename T >
Ocean::HashMap< TKey, T >::HashMap ( const size_t  capacity,
const ValueFunction function = defaultHashFunction 
)
explicit

Creates a new hash map object by a given capacity.

Parameters
capacityMaximal capacity the hash map will support
functionHash function to be used

◆ HashMap() [4/4]

template<typename TKey , typename T >
Ocean::HashMap< TKey, T >::HashMap ( size_t  capacity,
HashMap< TKey, T > &&  hashMap 
)
protected

Creates a new hash map by a given hash map.

Parameters
capacityThe capacity of the new has map, with range [hashMap.size(), infinity)
hashMapThe hash map which defines the initial values of this hash map, will be moved

Member Function Documentation

◆ capacity()

template<typename TKey , typename T >
size_t Ocean::HashMap< TKey, T >::capacity
inline

Returns the capacity of this hash map.

Returns
Maximal capacity this hash map supports

◆ clear()

template<typename TKey , typename T >
void Ocean::HashMap< TKey, T >::clear

Removes all elements from this has map.

◆ defaultHashFunction()

template<typename TKey , typename T >
size_t Ocean::HashMap< TKey, T >::defaultHashFunction ( const TKey &  key)
inlinestaticprotected

Default hash function for elements supporting an cast size_t cast.

Parameters
keyKey to return the hash value for
Returns
Resulting hash value

◆ element()

template<typename TKey , typename T >
const T & Ocean::HashMap< TKey, T >::element ( const TKey &  key) const

Returns a specific element of this map.

Beware: The element must exist!

Parameters
keyThe key which belongs to the element
Returns
The element of the defined key

◆ find() [1/3]

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::find ( const TKey &  key) const

Returns whether this hash map holds a given element.

Parameters
keyKey to be found
Returns
True, if succeeded

◆ find() [2/3]

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::find ( const TKey &  key,
const T *&  element 
) const

Returns whether this hash map holds a given element.

Parameters
keyKey to be found
elementResulting element corresponding to the requested key
Returns
True, if succeeded

◆ find() [3/3]

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::find ( const TKey &  key,
T *&  element 
)

Returns whether this hash map holds a given element.

Parameters
keyKey to be found
elementResulting element corresponding to the requested key
Returns
True, if succeeded

◆ insert() [1/2]

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::insert ( const TKey &  key,
const T &  element,
const bool  oneOnly = true,
const bool  extendCapacity = true 
)

Adds a new element to this hash map.

Parameters
keyKey to be added
elementElement to be added
oneOnlyTrue, to add the element only if it does not exist already
extendCapacityTrue, to extend the capacity if necessary
Returns
True, if the element has been added

◆ insert() [2/2]

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::insert ( TKey &&  key,
T &&  element,
const bool  oneOnly = true,
const bool  extendCapacity = true 
)

Adds (moves) a new element to this hash map.

Parameters
keyKey to be moved
elementElement to be moved
oneOnlyTrue, to add the element only if it does not exist already
extendCapacityTrue, to extend the capacity if necessary
Returns
True, if the element has been added

◆ isConsistent()

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::isConsistent
protected

Returns whether this hash map is still consistent.

Returns
True, if so

◆ isEmpty()

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::isEmpty
inline

Returns whether this hash map is empty.

Returns
True, if so

◆ operator=() [1/2]

template<typename TKey , typename T >
HashMap< TKey, T > & Ocean::HashMap< TKey, T >::operator= ( const HashMap< TKey, T > &  hashMap)
inline

Assign operator.

Parameters
hashMapThe hash map to assign
Returns
The reference to this object

◆ operator=() [2/2]

template<typename TKey , typename T >
HashMap< TKey, T > & Ocean::HashMap< TKey, T >::operator= ( HashMap< TKey, T > &&  hashMap)
inlinenoexcept

Move operator.

Parameters
hashMapThe hash map to move
Returns
The reference to this object

◆ remove()

template<typename TKey , typename T >
bool Ocean::HashMap< TKey, T >::remove ( const TKey &  key)

Removes an element from this hash map.

Parameters
keyKey to be removed
Returns
True, if succeeded

◆ size()

template<typename TKey , typename T >
size_t Ocean::HashMap< TKey, T >::size
inline

Returns the number of elements this hash map currently holds.

Returns
Number of elements

Field Documentation

◆ mapElements

template<typename TKey , typename T >
Elements Ocean::HashMap< TKey, T >::mapElements
protected

Hash map elements.

◆ mapFunction

template<typename TKey , typename T >
ValueFunction Ocean::HashMap< TKey, T >::mapFunction
protected

Value function.

◆ mapSize

template<typename TKey , typename T >
size_t Ocean::HashMap< TKey, T >::mapSize
protected

Number of elements this has map holds.


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