|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
A generic key-value mapping container with inverse operation support. More...
#include <ah-mapping.H>
Public Types | |
| using | key_type = Key |
| Type of the keys. | |
| using | mapped_type = ValueType |
| Type of the mapped values. | |
| using | value_type = std::pair< const Key, ValueType > |
| Type of the key-value pairs. | |
| using | size_type = size_t |
| Type for size-related operations. | |
Public Member Functions | |
| AHMapping ()=default | |
| Default constructor. | |
| AHMapping (const AHMapping &other)=default | |
| Copy constructor. | |
| AHMapping (AHMapping &&other) noexcept=default | |
| Move constructor. | |
| template<typename... Pairs> | |
| AHMapping (const Key &key, const ValueType &value, Pairs... pairs) | |
| Constructs a mapping from a list of key-value pairs. | |
| AHMapping & | operator= (const AHMapping &other)=default |
| Copy assignment operator. | |
| AHMapping & | operator= (AHMapping &&other) noexcept=default |
| Move assignment operator. | |
| void | insert (const Key &key, const ValueType &value) |
| Inserts or updates a key-value pair in the mapping. | |
| const ValueType & | operator[] (const Key &key) const |
| Accesses the value associated with the given key. | |
| ValueType & | operator[] (const Key &key) |
| Accesses the value associated with the given key. | |
| AHMapping< ValueType, Key > | inverse () const |
| Creates a new mapping with keys and values swapped. | |
| bool | remove (const Key &key) noexcept |
| Removes the key-value pair with the given key. | |
| bool | valid_key (const Key &key) const noexcept |
| Checks if a key exists in the mapping. | |
| DynList< Key > | keys () const |
| Gets all keys in the mapping. | |
| DynList< ValueType > | values () const |
| Gets all values in the mapping. | |
| size_t | size () const noexcept |
| Gets the number of key-value pairs in the mapping. | |
| bool | empty () const noexcept |
| Checks if the mapping is empty. | |
| void | clear () noexcept |
| Removes all key-value pairs from the mapping. | |
| bool | contains_value (const ValueType &value) const |
| Checks if the mapping contains a specific value. | |
| template<typename F > | |
| void | for_each (F f) const |
| Applies a function to each key-value pair. | |
Private Attributes | |
| DynMapTree< Key, ValueType > | tbl |
A generic key-value mapping container with inverse operation support.
This class provides a dictionary-like interface with the ability to create an inverse mapping where values become keys and vice versa. It's implemented using a balanced binary search tree (DynMapTree) internally.
| Key | The type of the keys in the mapping |
| ValueType | The type of the values in the mapping |
Definition at line 69 of file ah-mapping.H.
| using Aleph::AHMapping< Key, ValueType >::key_type = Key |
Type of the keys.
Definition at line 74 of file ah-mapping.H.
| using Aleph::AHMapping< Key, ValueType >::mapped_type = ValueType |
Type of the mapped values.
Definition at line 75 of file ah-mapping.H.
| using Aleph::AHMapping< Key, ValueType >::size_type = size_t |
Type for size-related operations.
Definition at line 77 of file ah-mapping.H.
| using Aleph::AHMapping< Key, ValueType >::value_type = std::pair<const Key, ValueType> |
Type of the key-value pairs.
Definition at line 76 of file ah-mapping.H.
|
default |
Default constructor.
Creates an empty mapping.
|
default |
Copy constructor.
| other | The mapping to copy from |
|
defaultnoexcept |
Move constructor.
| other | The mapping to move from |
|
inline |
Constructs a mapping from a list of key-value pairs.
| key | The first key |
| value | The first value |
| pairs | Additional key-value pairs (must be in pairs) |
Definition at line 106 of file ah-mapping.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), and Aleph::AHMapping< Key, ValueType >::tbl.
|
inlinenoexcept |
Removes all key-value pairs from the mapping.
Definition at line 247 of file ah-mapping.H.
References Aleph::DynSetTree< Key, Tree, Compare >::empty(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by TEST_F().
|
inline |
Checks if the mapping contains a specific value.
| value | The value to search for |
Definition at line 257 of file ah-mapping.H.
References LocateFunctions< Container, Type >::get_it(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by demo_numeric_mapping(), and TEST_F().
|
inlinenoexcept |
Checks if the mapping is empty.
Definition at line 239 of file ah-mapping.H.
References Aleph::AHMapping< Key, ValueType >::size().
|
inline |
Applies a function to each key-value pair.
| F | Function type with signature void(const Key&, const ValueType&) |
| f | The function to apply |
Definition at line 271 of file ah-mapping.H.
References LocateFunctions< Container, Type >::get_it(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by demo_numeric_mapping(), and TEST_F().
Inserts or updates a key-value pair in the mapping.
| key | The key to insert/update |
| value | The value to associate with the key |
Definition at line 131 of file ah-mapping.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by demo_numeric_mapping(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Creates a new mapping with keys and values swapped.
Definition at line 166 of file ah-mapping.H.
References LocateFunctions< Container, Type >::get_it(), Aleph::DynList< T >::insert(), Aleph::maps(), and Aleph::AHMapping< Key, ValueType >::tbl.
|
inline |
Gets all keys in the mapping.
Definition at line 209 of file ah-mapping.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::keys(), and Aleph::AHMapping< Key, ValueType >::tbl.
|
defaultnoexcept |
Move assignment operator.
| other | The mapping to move from |
|
default |
Copy assignment operator.
| other | The mapping to copy from |
|
inline |
Accesses the value associated with the given key.
| key | The key to look up |
Definition at line 155 of file ah-mapping.H.
References Aleph::AHMapping< Key, ValueType >::tbl.
|
inline |
Accesses the value associated with the given key.
| key | The key to look up |
| std::domain_error | if the key is not found |
Definition at line 142 of file ah-mapping.H.
References ah_domain_error_if, Aleph::DynMapTree< Key, Data, Tree, Compare >::search(), and Aleph::AHMapping< Key, ValueType >::tbl.
|
inlinenoexcept |
Removes the key-value pair with the given key.
| key | The key to remove |
Definition at line 182 of file ah-mapping.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::remove(), and Aleph::AHMapping< Key, ValueType >::tbl.
|
inlinenoexcept |
Gets the number of key-value pairs in the mapping.
Definition at line 230 of file ah-mapping.H.
References Aleph::DynSetTree< Key, Tree, Compare >::size(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by Aleph::AHMapping< Key, ValueType >::empty(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Checks if a key exists in the mapping.
| key | The key to check |
Definition at line 200 of file ah-mapping.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::has(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Gets all values in the mapping.
Definition at line 218 of file ah-mapping.H.
References Aleph::DynList< T >::append(), LocateFunctions< Container, Type >::get_it(), and Aleph::AHMapping< Key, ValueType >::tbl.
Referenced by demo_numeric_mapping().
|
private |
Definition at line 71 of file ah-mapping.H.
Referenced by Aleph::AHMapping< Key, ValueType >::AHMapping(), Aleph::AHMapping< Key, ValueType >::clear(), Aleph::AHMapping< Key, ValueType >::contains_value(), Aleph::AHMapping< Key, ValueType >::for_each(), Aleph::AHMapping< Key, ValueType >::insert(), Aleph::AHMapping< Key, ValueType >::inverse(), Aleph::AHMapping< Key, ValueType >::keys(), Aleph::AHMapping< Key, ValueType >::operator[](), Aleph::AHMapping< Key, ValueType >::operator[](), Aleph::AHMapping< Key, ValueType >::remove(), Aleph::AHMapping< Key, ValueType >::size(), Aleph::AHMapping< Key, ValueType >::valid_key(), and Aleph::AHMapping< Key, ValueType >::values().