ORIGINAL
Loading...
Searching...
No Matches
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC > Class Template Referencefinal

Hash table based implementation of the map interface. More...

#include <maps.h>

Inheritance diagram for original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >:
Inheritance graph
Collaboration diagram for original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >:
Collaboration graph

Classes

class  Iterator
 Bidirectional iterator for hashMap. More...
 

Public Member Functions

 hashMap (HASH hash=HASH{}, ALLOC alloc=ALLOC{})
 Constructs empty hashMap.
 
 hashMap (const hashMap &other)
 Copy constructor.
 
hashMapoperator= (const hashMap &other)
 Copy assignment operator.
 
 hashMap (hashMap &&other) noexcept
 Move constructor.
 
hashMapoperator= (hashMap &&other) noexcept
 Move assignment operator.
 
u_integer size () const override
 Gets number of elements.
 
bool contains (const couple< const K_TYPE, V_TYPE > &e) const override
 Checks if key-value pair exists.
 
bool add (const K_TYPE &k, const V_TYPE &v) override
 Adds new key-value pair.
 
bool remove (const K_TYPE &k) override
 Removes key-value pair.
 
bool containsKey (const K_TYPE &k) const override
 Checks if key exists.
 
V_TYPE get (const K_TYPE &k) const override
 Gets value for key.
 
bool update (const K_TYPE &key, const V_TYPE &value) override
 Updates value for existing key.
 
const V_TYPE & operator[] (const K_TYPE &k) const override
 Const element access.
 
V_TYPE & operator[] (const K_TYPE &k) override
 Non-const element access.
 
Iteratorbegins () const override
 Gets begin iterator.
 
Iteratorends () const override
 Gets end iterator.
 
std::string className () const override
 Gets class name.
 
std::string toString (bool enter) const override
 Converts to string representation.
 
- Public Member Functions inherited from original::iterable< couple< const K_TYPE, V_TYPE > >
auto forEach (Callback operation) -> void
 
auto forEach (const Callback &operation) const -> void
 
iterAdaptor begin ()
 Returns an iterator adapter pointing to the beginning of the container.
 
iterAdaptor begin () const
 Returns a const iterator adapter pointing to the beginning of the container.
 
iterAdaptor end ()
 Returns an iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor end () const
 Returns a const iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor first ()
 Returns an iterator adapter pointing to the first element.
 
iterAdaptor first () const
 Returns a const iterator adapter pointing to the first element.
 
iterAdaptor last ()
 Returns an iterator adapter pointing to the last element.
 
iterAdaptor last () const
 Returns a const iterator adapter pointing to the last element.
 
void forEach (Callback operation=Callback{})
 Applies a given operation to each element in the iterable container.
 
void forEach (const Callback &operation=Callback{}) const
 Applies a given operation to each element in the iterable container (const version).
 
auto forEach (Callback operation) -> void
 
auto forEach (const Callback &operation) const -> void
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const char * toCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE>
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE>
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE>
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE>
auto formatString (TYPE *const &ptr) -> std::string
 

Additional Inherited Members

- Static Public Member Functions inherited from original::printable
template<typename TYPE>
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion.
 
template<typename TYPE>
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting.
 
template<typename TYPE>
static const char * formatCString (const TYPE &t)
 C-string cache for temporary usage.
 
template<typename TYPE>
static std::string formatEnum (const TYPE &t)
 Enum formatting utility.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 

Detailed Description

template<typename K_TYPE, typename V_TYPE, typename HASH = hash<K_TYPE>, typename ALLOC = allocator<couple<const K_TYPE, V_TYPE>>>
class original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >

Hash table based implementation of the map interface.

Template Parameters
K_TYPEKey type (must be hashable)
V_TYPEValue type
HASHHash function type (default: hash<K_TYPE>)
ALLOCAllocator type (default: allocator)

This class provides a concrete implementation of the map interface using a hash table with separate chaining. It combines the functionality of:

  • map (interface)
  • hashTable (storage)
  • iterable (iteration support)

Performance Characteristics:

  • Insertion: Average O(1), Worst O(n)
  • Lookup: Average O(1), Worst O(n)
  • Deletion: Average O(1), Worst O(n)

The implementation guarantees:

  • Unique keys (no duplicates)
  • Type safety
  • Exception safety (basic guarantee)
  • Iterator validity unless modified

Constructor & Destructor Documentation

◆ hashMap() [1/3]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::hashMap ( HASH hash = HASH{},
ALLOC alloc = ALLOC{} )
explicit

Constructs empty hashMap.

Parameters
hashHash function to use
allocAllocator to use

◆ hashMap() [2/3]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::hashMap ( const hashMap< K_TYPE, V_TYPE, HASH, ALLOC > & other)

Copy constructor.

Parameters
otherhashMap to copy

Performs deep copy of all elements and buckets

Note
Allocator is copied if propagate_on_container_copy_assignment is true

◆ hashMap() [3/3]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::hashMap ( hashMap< K_TYPE, V_TYPE, HASH, ALLOC > && other)
noexcept

Move constructor.

Parameters
otherhashMap to move from

Transfers ownership of resources from other

Note
Leaves other in valid but unspecified state

Member Function Documentation

◆ add()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
bool original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::add ( const K_TYPE & k,
const V_TYPE & v )
override

Adds new key-value pair.

Parameters
kKey to add
vValue to associate
Returns
true if added, false if key existed

◆ begins()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::Iterator * original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::begins ( ) const
overridevirtual

Gets begin iterator.

Returns
New iterator at first element

Implements original::iterable< couple< const K_TYPE, V_TYPE > >.

◆ className()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
std::string original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::className ( ) const
nodiscardoverridevirtual

Gets class name.

Returns
"hashMap"

Reimplemented from original::printable.

◆ contains()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
bool original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::contains ( const couple< const K_TYPE, V_TYPE > & e) const
override

Checks if key-value pair exists.

Parameters
ePair to check
Returns
true if both key exists and value matches

◆ containsKey()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
bool original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::containsKey ( const K_TYPE & k) const
nodiscardoverride

Checks if key exists.

Parameters
kKey to check
Returns
true if key exists

◆ ends()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::Iterator * original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::ends ( ) const
overridevirtual

Gets end iterator.

Returns
New iterator at position past last element

Implements original::iterable< couple< const K_TYPE, V_TYPE > >.

◆ get()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
V_TYPE original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::get ( const K_TYPE & k) const
override

Gets value for key.

Parameters
kKey to lookup
Returns
Associated value
Exceptions
noElementErrorif key doesn't exist

◆ operator=() [1/2]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC > & original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::operator= ( const hashMap< K_TYPE, V_TYPE, HASH, ALLOC > & other)

Copy assignment operator.

Parameters
otherhashMap to copy
Returns
Reference to this hashMap

Performs deep copy of all elements and buckets

Note
Allocator is copied if propagate_on_container_copy_assignment is true

◆ operator=() [2/2]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC > & original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::operator= ( hashMap< K_TYPE, V_TYPE, HASH, ALLOC > && other)
noexcept

Move assignment operator.

Parameters
otherhashMap to move from
Returns
Reference to this hashMap

Transfers ownership of resources from other

Note
Leaves other in valid but unspecified state
Allocator is moved if propagate_on_container_move_assignment is true

◆ operator[]() [1/2]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
const V_TYPE & original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::operator[] ( const K_TYPE & k) const
override

Const element access.

Parameters
kKey to access
Returns
const reference to value
Exceptions
noElementErrorif key doesn't exist

◆ operator[]() [2/2]

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
V_TYPE & original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::operator[] ( const K_TYPE & k)
override

Non-const element access.

Parameters
kKey to access
Returns
reference to value
Note
Inserts default-constructed value if key doesn't exist

◆ remove()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
bool original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::remove ( const K_TYPE & k)
override

Removes key-value pair.

Parameters
kKey to remove
Returns
true if removed, false if key didn't exist

◆ size()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
original::u_integer original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::size ( ) const
nodiscardoverride

Gets number of elements.

Returns
Current size

◆ toString()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
std::string original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::toString ( bool enter) const
nodiscardoverridevirtual

Converts to string representation.

Parameters
enterAdd newline if true
Returns
String representation

Reimplemented from original::printable.

◆ update()

template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
bool original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::update ( const K_TYPE & key,
const V_TYPE & value )
override

Updates value for existing key.

Parameters
keyKey to update
valueNew value
Returns
true if updated, false if key didn't exist

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