Radium Engine  1.5.20
Loading...
Searching...
No Matches
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.
 
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.
 

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 Typedef Documentation

◆ key_to_value_map

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

◆ key_type

template<typename T1 , typename T2 >
using Ra::Core::Utils::BijectiveAssociation< T1, T2 >::key_type = T1

Definition at line 23 of file BijectiveAssociation.hpp.

◆ value_to_key_map

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

◆ value_type

template<typename T1 , typename T2 >
using Ra::Core::Utils::BijectiveAssociation< T1, T2 >::value_type = T2

Definition at line 24 of file BijectiveAssociation.hpp.

Constructor & Destructor Documentation

◆ BijectiveAssociation()

template<typename T1 , typename T2 >
Ra::Core::Utils::BijectiveAssociation< T1, T2 >::BijectiveAssociation ( std::initializer_list< std::pair< key_type, value_type > > pairs)
explicit

Constructor from { <T1, T2> } pairs.

Definition at line 146 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ begin()

template<typename T1 , typename T2 >
std::map< T1, T2 >::const_iterator Ra::Core::Utils::BijectiveAssociation< T1, T2 >::begin ( ) const
noexcept

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

Definition at line 259 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ cbegin()

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

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

Definition at line 249 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ cend()

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

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

Definition at line 254 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ end()

template<typename T1 , typename T2 >
std::map< T1, T2 >::const_iterator Ra::Core::Utils::BijectiveAssociation< T1, T2 >::end ( ) const
noexcept

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

Definition at line 264 of file BijectiveAssociation.hpp.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ size()

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

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

◆ 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.

+ Here is the call graph for this function:

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