ORIGINAL
|
Hash table based implementation of the map interface. More...
#include <maps.h>
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. | |
hashMap & | operator= (const hashMap &other) |
Copy assignment operator. | |
hashMap (hashMap &&other) noexcept | |
Move constructor. | |
hashMap & | operator= (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_TYPE & | operator[] (const K_TYPE &k) const override |
Const element access. | |
V_TYPE & | operator[] (const K_TYPE &k) override |
Non-const element access. | |
Iterator * | begins () const override |
Gets begin iterator. | |
Iterator * | ends () const override |
Gets end iterator. | |
std::string | className () const override |
Gets class name. | |
std::string | toString (bool enter) const override |
Converts to string representation. | |
![]() | |
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. | |
![]() | |
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 | |
![]() | |
using | T = std::remove_const_t< couple< const K_TYPE, V_TYPE > > |
![]() | |
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 char * | formatCString (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 |
Hash table based implementation of the map interface.
K_TYPE | Key type (must be hashable) |
V_TYPE | Value type |
HASH | Hash function type (default: hash<K_TYPE>) |
ALLOC | Allocator 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:
|
explicit |
Constructs empty hashMap.
hash | Hash function to use |
alloc | Allocator to use |
original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >::hashMap | ( | const hashMap< K_TYPE, V_TYPE, HASH, ALLOC > & | other | ) |
Copy constructor.
other | hashMap to copy |
Performs deep copy of all elements and buckets
|
noexcept |
Move constructor.
other | hashMap to move from |
Transfers ownership of resources from other
|
override |
Adds new key-value pair.
k | Key to add |
v | Value to associate |
|
overridevirtual |
Gets begin iterator.
Implements original::iterable< couple< const K_TYPE, V_TYPE > >.
|
overridevirtual |
|
override |
Checks if key-value pair exists.
e | Pair to check |
|
override |
Checks if key exists.
k | Key to check |
|
overridevirtual |
Gets end iterator.
Implements original::iterable< couple< const K_TYPE, V_TYPE > >.
Gets value for key.
k | Key to lookup |
noElementError | if key doesn't exist |
|
override |
Const element access.
k | Key to access |
noElementError | if key doesn't exist |
Non-const element access.
k | Key to access |
Removes key-value pair.
k | Key to remove |
|
override |
Gets number of elements.
|
noexcept |
Swaps contents with another hashMap.
other | hashMap to swap with |
Efficiently exchanges all internal resources between two hashMaps:
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:
|
overridevirtual |
Converts to string representation.
enter | Add newline if true |
Reimplemented from original::printable.
|
override |
Updates value for existing key.
key | Key to update |
value | New value |