1#ifndef BIMAP_PROJECT_COMMA_H
2#define BIMAP_PROJECT_COMMA_H
27template<
typename A,
typename B>
44 void insert(
const A &a,
const B &b) {
45 auto aitr =
_mapA.insert({b,
nullptr}).first;
46 const B *bp = &(aitr->first);
48 _mapB.insert({a, bp}).first;
49 const A *ap = &(bitr->first);
50 _mapA.insert_or_assign(b, ap);
55 for (
const auto &[key, value] :
_mapB) {
56 std::cout <<
'[' << key <<
"] = " << *value <<
"; ";
66 auto node =
_mapB.extract(a_old);
69 _mapB.insert(std::move(node));
79 auto node =
_mapA.extract(b_old);
82 _mapA.insert(std::move(node));
93 auto it =
_mapB.find(a);
94 return (*(it->second));
104 auto it =
_mapA.find(b);
105 return (*(it->second));
115 auto itB =
_mapB.find(a);
116 auto be = *(itB->second);
117 auto itA =
_mapA.find(be);
An easy and straight forward implementation of a Bimap.
Definition: Bimap.h:28
void update_nodeA(const B &b_old, const B &b_new)
Update of the key of the map A and hence the value of the node B.
Definition: Bimap.h:78
B get_B(const A &a)
Getter of the B value starting from a A value.
Definition: Bimap.h:90
~Bimap()=default
Destructor.
Bimap()=default
Constructor.
void insert(const A &a, const B &b)
Insertion function in the Bimap.
Definition: Bimap.h:44
bool empty()
Check if the Bimap is empty.
Definition: Bimap.h:125
void erase_B(const A &a)
Eraser of the value starting from a A value.
Definition: Bimap.h:112
std::map< A, const B * > _mapB
Right map.
Definition: Bimap.h:136
A get_A(const B &b)
Getter of the A value starting from a B value.
Definition: Bimap.h:101
void update_nodeB(const A &a_old, const A &a_new)
Update of the key of the map B and hence the value of the node A.
Definition: Bimap.h:65
std::map< B, const A * > _mapA
Left map
Definition: Bimap.h:134
void print()
Function to print the map.
Definition: Bimap.h:54
size_t lung()
Returns the size of the container.
Definition: Bimap.h:130
Definition: Agglomerator.h:37