Radium Engine  1.5.0
Ra::Core::Utils::BijectiveAssociation< T1, T2 > Class Template Reference

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>

+ Inheritance diagram for Ra::Core::Utils::BijectiveAssociation< T1, T2 >:
+ Collaboration diagram for Ra::Core::Utils::BijectiveAssociation< T1, T2 >:

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. More...
 
bool insert (key_type key, value_type value)
 Convenient alias for insert({key, value}). More...
 
void replace (std::pair< key_type, value_type > p)
 
void replace (key_type key, value_type value)
 Convenient alias of replace({key, value}). More...
 
bool remove (std::pair< key_type, value_type > p)
 Remove a pair from the association. More...
 
bool remove (key_type key, value_type value)
 Convenient alias for remove({key, value}). More...
 
value_type operator() (const key_type &key) const
 Gets the value associated to the key. More...
 
value_type value (const key_type &key) const
 Gets the value associated to key. More...
 
optional< value_type > valueIfExists (const key_type &key) const
 Gets the value associated to key if it exists. More...
 
key_type key (const value_type &value) const
 Gets the key associated to a value. More...
 
optional< key_type > keyIfExists (const value_type &value) const
 Gets the key associated to value if it exists. More...
 
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. More...
 
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. More...
 
size_t size () const
 Gets the size of the association, i.e. the numer of <Key, Value> pairs.
 

Detailed Description

template<typename T1, typename T2>
class Ra::Core::Utils::BijectiveAssociation< T1, T2 >

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\).

Template Parameters
T1Type of the keys
T2Type of the values

Definition at line 20 of file BijectiveAssociation.hpp.

Member Function Documentation

◆ cbegin()

template<typename T1 , typename T2 >
std::map< T1, T2 >::const_iterator Ra::Core::Utils::BijectiveAssociation< T1, T2 >::cbegin
noexcept

Gets a const iterator at beginning of the key to value map.

Definition at line 249 of file BijectiveAssociation.hpp.

◆ cend()

template<typename T1 , typename T2 >
std::map< T1, T2 >::const_iterator Ra::Core::Utils::BijectiveAssociation< T1, T2 >::cend
noexcept

Gets a const iterator at the end of the key to value map.

Definition at line 254 of file BijectiveAssociation.hpp.

◆ insert() [1/2]

template<typename T1 , typename T2 >
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::insert ( key_type  key,
value_type  value 
)

Convenient alias for insert({key, value}).

See also
Ra::Core::Utils::BijectiveAssociation::insert(std::pair<key_type, value_type>)

Definition at line 165 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ insert() [2/2]

template<typename T1 , typename T2 >
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::insert ( std::pair< key_type, value_type >  p)

Insert a pair into the association.

Returns
false if the pair was not added due to collision with an already inserted pair.

Definition at line 155 of file BijectiveAssociation.hpp.

◆ key()

template<typename T1 , typename T2 >
BijectiveAssociation< T1, T2 >::key_type Ra::Core::Utils::BijectiveAssociation< T1, T2 >::key ( const value_type &  value) const

Gets the key associated to a value.

Exceptions
std::out_of_rangeif value is not present in the association as a value.

Definition at line 222 of file BijectiveAssociation.hpp.

◆ keyIfExists()

template<typename T1 , typename T2 >
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.

◆ operator()()

template<typename T1 , typename T2 >
BijectiveAssociation< T1, T2 >::value_type Ra::Core::Utils::BijectiveAssociation< T1, T2 >::operator() ( const key_type &  key) const

Gets the value associated to the key.

Exceptions
std::out_of_rangeif key is not present in the association as a key.

Definition at line 216 of file BijectiveAssociation.hpp.

◆ remove() [1/2]

template<typename T1 , typename T2 >
bool Ra::Core::Utils::BijectiveAssociation< T1, T2 >::remove ( key_type  key,
value_type  value 
)

Convenient alias for remove({key, value}).

See also
Ra::Core::Utils::BijectiveAssociation::remove(std::pair<key_type, value_type>)

Definition at line 196 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ remove() [2/2]

template<typename T1 , typename T2 >
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.

Returns
true if the pair was in the association, and removed. False otherwise.

Definition at line 210 of file BijectiveAssociation.hpp.

◆ replace() [1/2]

template<typename T1 , typename T2 >
void Ra::Core::Utils::BijectiveAssociation< T1, T2 >::replace ( key_type  key,
value_type  value 
)

Convenient alias of replace({key, value}).

See also
Ra::Core::Utils::BijectiveAssociation::replace(std::pair<key_type, value_type>)

Definition at line 170 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ replace() [2/2]

template<typename T1 , typename T2 >
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

remove({p.first, old_value});
remove({old_key, p.second});
insert(p);
bool remove(std::pair< key_type, value_type > p)
Remove a pair from the association.
bool insert(std::pair< key_type, value_type > p)
Insert a pair into the association.

Definition at line 191 of file BijectiveAssociation.hpp.

◆ value()

template<typename T1 , typename T2 >
BijectiveAssociation< T1, T2 >::value_type Ra::Core::Utils::BijectiveAssociation< T1, T2 >::value ( const key_type &  key) const

Gets the value associated to key.

Exceptions
std::out_of_rangeif key is not present in the association as a key.

Definition at line 236 of file BijectiveAssociation.hpp.

◆ valueIfExists()

template<typename T1 , typename T2 >
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.


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