ORIGINAL
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
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.
 
void swap (hashMap &other) noexcept
 Swaps contents with another hashMap.
 
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_TYPEoperator[] (const K_TYPE &k) const override
 Const element access.
 
V_TYPEoperator[] (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 > >
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
 
coroutine::generator< T > generator () const
 Creates a coroutine generator that yields elements from this container.
 
- 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 chartoCString (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

- Public Types inherited from original::iterable< couple< const K_TYPE, V_TYPE > >
using T = std::remove_const_t< couple< const K_TYPE, V_TYPE > >
 
- Static Public Member Functions inherited from original::printable
template<typename TYPE >
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion with type-specific formatting.
 
template<Printable TYPE>
static std::string formatString (const TYPE &t)
 Specialization for types deriving from printable.
 
template<EnumType TYPE>
static std::string formatString (const TYPE &t)
 Specialization for enum types with type-safe formatting.
 
template<typename TYPE >
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting with null safety.
 
template<typename TYPE >
static const charformatCString (const TYPE &t)
 C-string cache for temporary usage with static storage.
 
template<typename TYPE >
static std::string formatEnum (const TYPE &t)
 Enum formatting utility with underlying value extraction.
 
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:

Performance Characteristics:

The implementation guarantees:

Constructor & Destructor Documentation

◆ hashMap() [1/3]

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]

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]

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()

Adds new key-value pair.

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

◆ begins()

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()

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

Gets class name.

Returns
"hashMap"

Reimplemented from original::printable.

◆ contains()

Checks if key-value pair exists.

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

◆ containsKey()

bool original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::containsKey ( const K_TYPE k) const
override

Checks if key exists.

Parameters
kKey to check
Returns
true if key exists

◆ ends()

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()

Gets value for key.

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

◆ operator=() [1/2]

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]

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]

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]

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()

Removes key-value pair.

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

◆ size()

Gets number of elements.

Returns
Current size

◆ swap()

Swaps contents with another hashMap.

Parameters
otherhashMap to swap with
Note
No-throw guarantee if element swap and allocator swap are noexcept

Efficiently exchanges all internal resources between two hashMaps:

  • Bucket arrays and their contents (key-value pairs)
  • Size counters
  • Hash function instances
  • Allocators (if ALLOC::propagate_on_container_swap::value is true)

Performance: O(1) - pointer and integer swaps only, no element copying Memory: No additional memory allocation during swap Iterator Invalidation: All iterators from both maps are invalidated

Allocator Handling:

  • If ALLOC::propagate_on_container_swap::value is true, allocators are swapped
  • Otherwise, allocators remain with their original containers
  • Behavior consistent with C++ standard container requirements
Warning
All existing iterators, pointers, and references to elements in both containers are invalidated by this operation
See also
std::swap For the standard swap algorithm
hashMap::operator= For copy and move assignment alternatives

◆ toString()

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

Converts to string representation.

Parameters
enterAdd newline if true
Returns
String representation

Reimplemented from original::printable.

◆ update()

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: