Radium Engine
1.5.20
|
Bijective association between two sets {keys} and {values} having the same cardinality. The bijection \(f\) is constructed by giving all the pairs <key, value> such that \(f(key) = value\). More...
#include <Core/Utils/BijectiveAssociation.hpp>
Public Types | |
using | key_type = T1 |
using | value_type = T2 |
using | key_to_value_map = std::map<key_type, value_type> |
using | value_to_key_map = std::map<value_type, key_type> |
Public Member Functions | |
BijectiveAssociation (std::initializer_list< std::pair< key_type, value_type > > pairs) | |
Constructor from { <T1, T2> } pairs. | |
BijectiveAssociation ()=default | |
Creates an empty association. | |
bool | insert (std::pair< key_type, value_type > p) |
Insert a pair into the association. | |
bool | insert (key_type key, value_type value) |
Convenient alias for insert({key, value}) . | |
void | replace (std::pair< key_type, value_type > p) |
void | replace (key_type key, value_type value) |
Convenient alias of replace({key, value}) . | |
bool | remove (std::pair< key_type, value_type > p) |
Remove a pair from the association. | |
bool | remove (key_type key, value_type value) |
Convenient alias for remove({key, value}) . | |
value_type | operator() (const key_type &key) const |
Gets the value associated to the key. | |
value_type | value (const key_type &key) const |
Gets the value associated to key. | |
optional< value_type > | valueIfExists (const key_type &key) const |
Gets the value associated to key if it exists. | |
key_type | key (const value_type &value) const |
Gets the key associated to a value. | |
optional< key_type > | keyIfExists (const value_type &value) const |
Gets the key associated to value if it exists. | |
std::map< key_type, value_type >::const_iterator | begin () const noexcept |
Gets a const iterator at beginning of the key to value map. | |
std::map< key_type, value_type >::const_iterator | cbegin () const noexcept |
Gets a const iterator at beginning of the key to value map. | |
std::map< key_type, value_type >::const_iterator | end () const noexcept |
Gets a const iterator at the end of the key to value map. | |
std::map< key_type, value_type >::const_iterator | cend () const noexcept |
Gets a const iterator at the end of the key to value map. | |
size_t | size () const |
Gets the size of the association, i.e. the numer of <Key, Value> pairs. | |
Bijective association between two sets {keys} and {values} having the same cardinality. The bijection \(f\) is constructed by giving all the pairs <key, value> such that \(f(key) = value\).
T1 | Type of the keys |
T2 | Type of the values |
Definition at line 20 of file BijectiveAssociation.hpp.
using Ra::Core::Utils::BijectiveAssociation< T1, T2 >::key_to_value_map = std::map<key_type, value_type> |
Definition at line 25 of file BijectiveAssociation.hpp.
using Ra::Core::Utils::BijectiveAssociation< T1, T2 >::key_type = T1 |
Definition at line 23 of file BijectiveAssociation.hpp.
using Ra::Core::Utils::BijectiveAssociation< T1, T2 >::value_to_key_map = std::map<value_type, key_type> |
Definition at line 26 of file BijectiveAssociation.hpp.
using Ra::Core::Utils::BijectiveAssociation< T1, T2 >::value_type = T2 |
Definition at line 24 of file BijectiveAssociation.hpp.
|
explicit |
Constructor from { <T1, T2> } pairs.
Definition at line 146 of file BijectiveAssociation.hpp.
|
noexcept |
Gets a const iterator at beginning of the key to value map.
Definition at line 259 of file BijectiveAssociation.hpp.
|
noexcept |
Gets a const iterator at beginning of the key to value map.
Definition at line 249 of file BijectiveAssociation.hpp.
|
noexcept |
Gets a const iterator at the end of the key to value map.
Definition at line 254 of file BijectiveAssociation.hpp.
|
noexcept |
Gets a const iterator at the end of the key to value map.
Definition at line 264 of file BijectiveAssociation.hpp.
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::insert | ( | key_type | key, |
value_type | value ) |
Convenient alias for insert({key, value})
.
Definition at line 165 of file BijectiveAssociation.hpp.
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::insert | ( | std::pair< key_type, value_type > | p | ) |
Insert a pair into the association.
Definition at line 155 of file BijectiveAssociation.hpp.
BijectiveAssociation< T1, T2 >::key_type Ra::Core::Utils::BijectiveAssociation< T1, T2 >::key | ( | const value_type & | value | ) | const |
Gets the key associated to a value.
std::out_of_range | if value is not present in the association as a value. |
Definition at line 222 of file BijectiveAssociation.hpp.
std::optional< typename BijectiveAssociation< T1, T2 >::key_type > Ra::Core::Utils::BijectiveAssociation< T1, T2 >::keyIfExists | ( | const value_type & | value | ) | const |
Gets the key associated to value if it exists.
Otherwise the optional doesn't contain anything, and evaluate to false.
Definition at line 228 of file BijectiveAssociation.hpp.
BijectiveAssociation< T1, T2 >::value_type Ra::Core::Utils::BijectiveAssociation< T1, T2 >::operator() | ( | const key_type & | key | ) | const |
Gets the value associated to the key.
std::out_of_range | if key is not present in the association as a key. |
Definition at line 216 of file BijectiveAssociation.hpp.
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::remove | ( | key_type | key, |
value_type | value ) |
Convenient alias for remove({key, value})
.
Definition at line 196 of file BijectiveAssociation.hpp.
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::remove | ( | std::pair< key_type, value_type > | p | ) |
Remove a pair from the association.
Remove the {key, value}
pair. If key (resp. value) is present but associated with a value (resp. key) != value (resp. key), the association stay unchanged.
Definition at line 210 of file BijectiveAssociation.hpp.
void Ra::Core::Utils::BijectiveAssociation< T1, T2 >::replace | ( | key_type | key, |
value_type | value ) |
Convenient alias of replace({key, value})
.
Definition at line 170 of file BijectiveAssociation.hpp.
void Ra::Core::Utils::BijectiveAssociation< T1, T2 >::replace | ( | std::pair< key_type, value_type > | p | ) |
\brief Replace a pair in the association. Remove the associations `{p.first, old_value}` and `{old_key, p.second}` and insert
{p.first, p.second}
. Faster version of
Definition at line 191 of file BijectiveAssociation.hpp.
size_t Ra::Core::Utils::BijectiveAssociation< T1, T2 >::size | ( | ) | const |
Gets the size of the association, i.e. the numer of <Key, Value> pairs.
Definition at line 269 of file BijectiveAssociation.hpp.
BijectiveAssociation< T1, T2 >::value_type Ra::Core::Utils::BijectiveAssociation< T1, T2 >::value | ( | const key_type & | key | ) | const |
Gets the value associated to key.
std::out_of_range | if key is not present in the association as a key. |
Definition at line 236 of file BijectiveAssociation.hpp.
std::optional< typename BijectiveAssociation< T1, T2 >::value_type > Ra::Core::Utils::BijectiveAssociation< T1, T2 >::valueIfExists | ( | const key_type & | key | ) | const |
Gets the value associated to key if it exists.
Otherwise the optional doesn't contain anything, and evaluate to false.
Definition at line 242 of file BijectiveAssociation.hpp.