aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::BijectionImplementation< T1, T2, Alloc, Gen > Class Template Reference

A non scalar implementation of a Bijection. More...

#include <agrum/tools/core/bijection.h>

+ Collaboration diagram for gum::BijectionImplementation< T1, T2, Alloc, Gen >:

Public Member Functions

template<typename OtherAlloc >
INLINE void copy__ (const HashTable< T1, T2 *, OtherAlloc > &f2s)
 
template<typename OtherAlloc >
INLINE BijectionImplementation (const BijectionImplementation< T1, T2, OtherAlloc, Gen > &toCopy)
 
template<typename OtherAlloc >
INLINE BijectionImplementation< T1, T2, Alloc, Gen > & operator= (const BijectionImplementation< T1, T2, OtherAlloc, Gen > &toCopy)
 
template<typename... Args>
INLINE void emplace (Args &&... args)
 
template<typename OtherAlloc >
INLINE void copy__ (const HashTable< T1, T2, OtherAlloc > &f2s)
 
template<typename T1, typename T2, typename Alloc>
INLINE BijectionImplementation (const BijectionImplementation< T1, T2, Alloc, true > &toCopy)
 
template<typename OtherAlloc >
INLINE BijectionImplementation (const BijectionImplementation< T1, T2, OtherAlloc, true > &toCopy)
 
template<typename T1, typename T2, typename Alloc>
INLINE BijectionImplementation (BijectionImplementation< T1, T2, Alloc, true > &&toCopy) noexcept
 
template<typename OtherAlloc >
INLINE BijectionImplementation< T1, T2, Alloc, true > & operator= (const BijectionImplementation< T1, T2, OtherAlloc, true > &toCopy)
 
Constructors/destructors
 ~BijectionImplementation ()
 Destructor. More...
 
Accessors / Modifiers
const T1 & first (const T2 &second) const
 Returns the first value of a pair given its second value. More...
 
const T1 & firstWithDefault (const T2 &second, const T1 &default_val) const
 Returns the first value of a pair given its second value or default_val if second is unfound. More...
 
const T2 & second (const T1 &first) const
 Returns the second value of a pair given its first value. More...
 
const T2 & secondWithDefault (const T1 &second, const T2 &default_val) const
 Returns the second value of a pair given its first value or default_val if first is unfound. More...
 
bool existsFirst (const T1 &first) const
 Returns true if first is the first element in a pair in the gum::Bijection. More...
 
bool existsSecond (const T2 &second) const
 Returns true if second is the second element in a pair in the gum::Bijection. More...
 
void insert (const T1 &first, const T2 &second)
 Inserts a new association in the gum::Bijection. More...
 
void insert (T1 &&first, T2 &&second)
 Inserts a new association in the gum::Bijection. More...
 
template<typename... Args>
void emplace (Args &&... args)
 Emplace a new element in the gum::Bijection. More...
 
void clear ()
 Removes all the associations from the gum::Bijection. More...
 
bool empty () const noexcept
 Returns true if the gum::Bijection doesn't contain any association. More...
 
Size size () const noexcept
 Returns the number of associations stored within the gum::Bijection. More...
 
void eraseFirst (const T1 &first)
 Erases an association containing the given first element. More...
 
void eraseSecond (const T2 &second)
 Erases an association containing the given second element. More...
 
std::string toString () const
 Returns a friendly representatin of the gum::Bijection. More...
 
Fine tuning
Size capacity () const noexcept
 Returns the number of hashtables slots used. More...
 
void resize (Size new_size)
 Manually resize the gum::Bijection. More...
 
void setResizePolicy (const bool new_policy) noexcept
 Change the gum::Bijection resizing policy. More...
 
bool resizePolicy () const noexcept
 Returns true if the resize policy is automatic. More...
 

Public Types

using type1_type = T1
 types for STL compliance More...
 
using type1_reference = T1 &
 types for STL compliance More...
 
using type1_const_reference = const T1 &
 types for STL compliance More...
 
using type1_pointer = T1 *
 types for STL compliance More...
 
using type1_const_pointer = const T1 *
 types for STL compliance More...
 
using type2_type = T2
 types for STL compliance More...
 
using type2_reference = T2 &
 types for STL compliance More...
 
using type2_const_reference = const T2 &
 types for STL compliance More...
 
using type2_pointer = T2 *
 types for STL compliance More...
 
using type2_const_pointer = const T2 *
 types for STL compliance More...
 
using size_type = std::size_t
 types for STL compliance More...
 
using difference_type = std::ptrdiff_t
 types for STL compliance More...
 
using allocator_type = Alloc
 types for STL compliance More...
 
using iterator = BijectionIterator< T1, T2 >
 types for STL compliance More...
 
using const_iterator = BijectionIterator< T1, T2 >
 types for STL compliance More...
 
using iterator_safe = BijectionIteratorSafe< T1, T2 >
 types for STL compliance More...
 
using const_iterator_safe = BijectionIteratorSafe< T1, T2 >
 types for STL compliance More...
 
using allocator12_type = typename Alloc::template rebind< std::pair< T1, T2 *> >::other
 types for STL compliance More...
 
using allocator21_type = typename Alloc::template rebind< std::pair< T2, T1 *> >::other
 types for STL compliance More...
 

Friends

class BijectionIteratorSafe< T1, T2 >
 a friend to speed-up accesses More...
 
class BijectionIterator< T1, T2 >
 a friend to speed-up accesses More...
 
class Bijection< T1, T2, Alloc >
 a friend to speed-up accesses More...
 
template<typename TT1 , typename TT2 , typename A , bool >
class BijectionImplementation
 a friend to speed-up accesses More...
 

Iterators

iterator begin () const
 Returns the unsafe iterator at the beginning of the gum::Bijection. More...
 
const_iterator cbegin () const
 Returns the constant unsafe iterator at the beginning of the gum::Bjection. More...
 
const iteratorend () const noexcept
 Returns the unsafe iterator at the end of the gum::Bijection. More...
 
const const_iteratorcend () const noexcept
 Returns the constant iterator at the end of the gum::Bijection. More...
 
iterator_safe beginSafe () const
 Returns the safe iterator at the beginning of the gum::Bijection. More...
 
const_iterator_safe cbeginSafe () const
 Returns the constant safe iterator at the begining of the gum::Bijection. More...
 
const iterator_safeendSafe () const noexcept
 Returns the safe iterator at the end of the gum::Bijection. More...
 
const const_iterator_safecendSafe () const noexcept
 Returns the constant safe iterator at the end of the gum::Bijection. More...
 
static const iterator_safeendSafe4Statics ()
 Returns the safe end iterator for other classes' statics. More...
 
static const iteratorend4Statics ()
 Returns the unsafe end iterator for other classes' statics. More...
 

Detailed Description

template<typename T1, typename T2, typename Alloc, bool Gen>
class gum::BijectionImplementation< T1, T2, Alloc, Gen >

A non scalar implementation of a Bijection.

This class is designed for modeling a gum::Bijection between two sets, the idea is following :

  • We want to create a gum::Bjection relation between type T1 and type T2,
  • For x in T1, there exists only one y in T2 associated to x,
  • For y in T2, there exists only one x in T1 associated to y,
  • The user inserts all the (x, y) associations and can search efficiently the values thus associated.
Template Parameters
T1The first type of elements in the gum::Bjection.
T2The second type of elements in the gum::Bjection.
AllocThe allocator used for allocating memory.
GenIf true, this will be replaced by a implementation omptimized for non-scalar types.

Definition at line 84 of file bijection.h.

Member Typedef Documentation

◆ allocator12_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::allocator12_type = typename Alloc::template rebind< std::pair< T1, T2* > >::other

types for STL compliance

Definition at line 106 of file bijection.h.

◆ allocator21_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::allocator21_type = typename Alloc::template rebind< std::pair< T2, T1* > >::other

types for STL compliance

Definition at line 108 of file bijection.h.

◆ allocator_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::allocator_type = Alloc

types for STL compliance

Definition at line 100 of file bijection.h.

◆ const_iterator

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::const_iterator = BijectionIterator< T1, T2 >

types for STL compliance

Definition at line 102 of file bijection.h.

◆ const_iterator_safe

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::const_iterator_safe = BijectionIteratorSafe< T1, T2 >

types for STL compliance

Definition at line 104 of file bijection.h.

◆ difference_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::difference_type = std::ptrdiff_t

types for STL compliance

Definition at line 99 of file bijection.h.

◆ HashTable12

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::HashTable12 = HashTable< T1, T2*, allocator12_type >
private

Alias for more readable code.

Definition at line 640 of file bijection.h.

◆ HashTable21

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::HashTable21 = HashTable< T2, T1*, allocator21_type >
private

Alias for more readable code.

Definition at line 641 of file bijection.h.

◆ iterator

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::iterator = BijectionIterator< T1, T2 >

types for STL compliance

Definition at line 101 of file bijection.h.

◆ iterator_safe

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::iterator_safe = BijectionIteratorSafe< T1, T2 >

types for STL compliance

Definition at line 103 of file bijection.h.

◆ size_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::size_type = std::size_t

types for STL compliance

Definition at line 98 of file bijection.h.

◆ type1_const_pointer

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type1_const_pointer = const T1*

types for STL compliance

Definition at line 92 of file bijection.h.

◆ type1_const_reference

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type1_const_reference = const T1&

types for STL compliance

Definition at line 90 of file bijection.h.

◆ type1_pointer

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type1_pointer = T1*

types for STL compliance

Definition at line 91 of file bijection.h.

◆ type1_reference

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type1_reference = T1&

types for STL compliance

Definition at line 89 of file bijection.h.

◆ type1_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type1_type = T1

types for STL compliance

Definition at line 88 of file bijection.h.

◆ type2_const_pointer

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type2_const_pointer = const T2*

types for STL compliance

Definition at line 97 of file bijection.h.

◆ type2_const_reference

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type2_const_reference = const T2&

types for STL compliance

Definition at line 95 of file bijection.h.

◆ type2_pointer

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type2_pointer = T2*

types for STL compliance

Definition at line 96 of file bijection.h.

◆ type2_reference

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type2_reference = T2&

types for STL compliance

Definition at line 94 of file bijection.h.

◆ type2_type

template<typename T1, typename T2, typename Alloc, bool Gen>
using gum::BijectionImplementation< T1, T2, Alloc, Gen >::type2_type = T2

types for STL compliance

Definition at line 93 of file bijection.h.

Constructor & Destructor Documentation

◆ BijectionImplementation() [1/9]

template<typename T1 , typename T2 , typename Alloc >
INLINE gum::BijectionImplementation< T1, T2, Alloc >::BijectionImplementation ( Size  size,
bool  resize_policy 
)
private

Default constructor: creates a gum::Bijection without any association.

Parameters
sizeThe Bijection starting size.
resize_policyIf true, the gum::Bijection will resize itself automatically.

Definition at line 84 of file bijection_tpl.h.

86  :
87  // warning: below, we create the internal hashTables with a key
88  // uniqueness
89  // policy set to false because we will do the uniqueness tests ourselves
90  // (this
91  // will speed-up the process)
92  firstToSecond__(size, resize_policy, false),
93  secondToFirst__(size, resize_policy, false) {
94  GUM_CONSTRUCTOR(BijectionImplementation);
95 
96  // make sure the end() iterator is constructed properly
97  end4Statics();
99  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
static const iterator_safe & endSafe4Statics()
Returns the safe end iterator for other classes&#39; statics.
Definition: bijection_tpl.h:42
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
Size size() const noexcept
Returns the number of associations stored within the gum::Bijection.
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
static const iterator & end4Statics()
Returns the unsafe end iterator for other classes&#39; statics.
Definition: bijection_tpl.h:50

◆ BijectionImplementation() [2/9]

template<typename T1, typename T2, typename Alloc >
INLINE gum::BijectionImplementation< T1, T2, Alloc >::BijectionImplementation ( std::initializer_list< std::pair< T1, T2 > >  list)
private

Initializer list constructor.

Parameters
listThe initialize list.

Definition at line 103 of file bijection_tpl.h.

104  :
105  firstToSecond__(Size(list.size()) / 2, true, false),
106  secondToFirst__(Size(list.size()) / 2, true, false) {
107  GUM_CONSTRUCTOR(BijectionImplementation);
108 
109  for (const auto& elt: list) {
110  insert(elt.first, elt.second);
111  }
112 
113  // make sure the end() iterator is constructed properly
114  end4Statics();
115  endSafe4Statics();
116  }
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
static const iterator_safe & endSafe4Statics()
Returns the safe end iterator for other classes&#39; statics.
Definition: bijection_tpl.h:42
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
static const iterator & end4Statics()
Returns the unsafe end iterator for other classes&#39; statics.
Definition: bijection_tpl.h:50

◆ BijectionImplementation() [3/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
INLINE gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( const BijectionImplementation< T1, T2, Alloc, Gen > &  toCopy)
private

Copy constructor.

Parameters
toCopyBijection to copy.

Definition at line 120 of file bijection_tpl.h.

121  :
122  firstToSecond__(toCopy.firstToSecond__.capacity(), true, false),
123  secondToFirst__(toCopy.secondToFirst__.capacity(), true, false) {
124  GUM_CONS_CPY(BijectionImplementation);
125  copy__(toCopy.firstToSecond__);
126  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ BijectionImplementation() [4/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( const BijectionImplementation< T1, T2, OtherAlloc, Gen > &  toCopy)
private

Generalized copy constructor.

Parameters
toCopyBijection to copy.

◆ BijectionImplementation() [5/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
INLINE gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( BijectionImplementation< T1, T2, Alloc, Gen > &&  from)
privatenoexcept

Move constructor.

Parameters
fromBijection to move.

Definition at line 141 of file bijection_tpl.h.

142  :
143  firstToSecond__(std::move(from.firstToSecond__)),
144  secondToFirst__(std::move(from.secondToFirst__)) {
145  GUM_CONS_MOV(BijectionImplementation);
146  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ ~BijectionImplementation()

template<typename T1 , typename T2 , typename Alloc >
INLINE gum::BijectionImplementation< T1, T2, Alloc >::~BijectionImplementation ( )

Destructor.

Definition at line 151 of file bijection_tpl.h.

151  {
152  GUM_DESTRUCTOR(BijectionImplementation);
153  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650

◆ BijectionImplementation() [6/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( const BijectionImplementation< T1, T2, OtherAlloc, Gen > &  toCopy)

Definition at line 131 of file bijection_tpl.h.

132  :
133  firstToSecond__(toCopy.firstToSecond__.capacity(), true, false),
134  secondToFirst__(toCopy.secondToFirst__.capacity(), true, false) {
135  GUM_CONS_CPY(BijectionImplementation);
136  copy__(toCopy.firstToSecond__);
137  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ BijectionImplementation() [7/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename T1, typename T2, typename Alloc>
INLINE gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( const BijectionImplementation< T1, T2, Alloc, true > &  toCopy)

Definition at line 582 of file bijection_tpl.h.

583  :
584  firstToSecond__(toCopy.firstToSecond__.capacity(), true, false),
585  secondToFirst__(toCopy.secondToFirst__.capacity(), true, false) {
586  GUM_CONS_CPY(BijectionImplementation);
587  copy__(toCopy.firstToSecond__);
588  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ BijectionImplementation() [8/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( const BijectionImplementation< T1, T2, OtherAlloc, true > &  toCopy)

Definition at line 593 of file bijection_tpl.h.

594  :
595  firstToSecond__(toCopy.firstToSecond__.capacity(), true, false),
596  secondToFirst__(toCopy.secondToFirst__.capacity(), true, false) {
597  GUM_CONS_CPY(BijectionImplementation);
598  copy__(toCopy.firstToSecond__);
599  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ BijectionImplementation() [9/9]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename T1, typename T2, typename Alloc>
INLINE gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation ( BijectionImplementation< T1, T2, Alloc, true > &&  toCopy)
noexcept

Definition at line 603 of file bijection_tpl.h.

604  :
605  firstToSecond__(std::move(toCopy.firstToSecond__)),
606  secondToFirst__(std::move(toCopy.secondToFirst__)) {
607  GUM_CONS_MOV(BijectionImplementation);
608  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:650
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

Member Function Documentation

◆ begin()

template<typename T1 , typename T2 , typename Alloc >
INLINE BijectionImplementation< T1, T2, Alloc, true >::iterator gum::BijectionImplementation< T1, T2, Alloc >::begin ( ) const

Returns the unsafe iterator at the beginning of the gum::Bijection.

Unsafe iterators are a little bit faster than safe ones. But this speed is at the expense of safety: if you point to an element that is deleted, then try to access it or trying to operate a ++ will most certainly result in a segfault. So, Unsafe iterators should only be used to parse gum::Bjection where no element is ever deleted. If unsure, prefer using safe iterators.

Note that the notion of a beginning/end of a gum::Bjection is rather fuzzy. What is important here is that for an instance bij of this class:

for(iterator iter = bij.begin(); iter != bij.end(); ++iter) {
// will parse all the associations.
}

Definition at line 218 of file bijection_tpl.h.

218  {
219  return BijectionIterator< T1, T2 >{*this};
220  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:647

◆ beginSafe()

template<typename T1 , typename T2 , typename Alloc >
INLINE BijectionImplementation< T1, T2, Alloc, true >::iterator_safe gum::BijectionImplementation< T1, T2, Alloc >::beginSafe ( ) const

Returns the safe iterator at the beginning of the gum::Bijection.

Safe iterators are slightly slower than unsafe iterators. However, they guarantee that no segmentation fault can ever occur when trying to access the element they point to or when applying a ++ operator. When no element of the gum::Bijection is to be deleted during the parsing of the gum::Bijection (as for instance when you parse the gum::Bijection to display its content), prefer using the unsafe iterators, which are a little bit faster and cannot, in this case, produce segfaults.

Note that the notion of a beginning/end of a gum::Bijection is rather fuzzy. What is important here is that for an instance bij of this class:

for (iterator iter = bij.beginSafe(); iter != bij.endSafe(); ++iter) {
// loops will parse all the associations
}

Definition at line 249 of file bijection_tpl.h.

249  {
250  return BijectionIteratorSafe< T1, T2 >{*this};
251  }
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

◆ capacity()

template<typename T1 , typename T2 , typename Alloc >
INLINE Size gum::BijectionImplementation< T1, T2, Alloc >::capacity ( ) const
noexcept

Returns the number of hashtables slots used.

Returns
Returns the number of hashtables slots used.

Definition at line 455 of file bijection_tpl.h.

455  {
456  return firstToSecond__.capacity();
457  }
Size capacity() const noexcept
Returns the number of slots in the &#39;nodes&#39; vector of the hashtable.
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ cbegin()

template<typename T1 , typename T2 , typename Alloc >
INLINE BijectionImplementation< T1, T2, Alloc, true >::const_iterator gum::BijectionImplementation< T1, T2, Alloc >::cbegin ( ) const

Returns the constant unsafe iterator at the beginning of the gum::Bjection.

Unsafe iterators are a little bit faster than safe ones. But this speed is at the expense of safety: if you point to an element that is deleted, then try to access it or trying to operate a ++ will most certainly result in a segfault. So, Unsafe iterators should only be used to parse gum::Bjection where no element is ever deleted. If unsure, prefer using safe iterators.

Note that the notion of a beginning/end of a gum::Bjection is rather fuzzy. What is important here is that for an instance bij of this class:

for (iterator iter = bij.cbegin(); iter != bij.cend(); ++iter) {
// will parse all the association
}

Definition at line 225 of file bijection_tpl.h.

225  {
226  return BijectionIterator< T1, T2 >{*this};
227  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:647

◆ cbeginSafe()

template<typename T1 , typename T2 , typename Alloc >
INLINE BijectionImplementation< T1, T2, Alloc, true >::const_iterator_safe gum::BijectionImplementation< T1, T2, Alloc >::cbeginSafe ( ) const

Returns the constant safe iterator at the begining of the gum::Bijection.

Safe iterators are slightly slower than unsafe iterators. However, they guarantee that no segmentation fault can ever occur when trying to access the element they point to or when applying a ++ operator. When no element of the gum::Bijection is to be deleted during the parsing of the gum::Bijection (as for instance when you parse the bijection to display its content), prefer using the unsafe iterators, which are a little bit faster and cannot, in this case, produce segfaults.

Note that the notion of a beginning/end of a gum::Bijection is rather fuzzy. What is important here is that for an instance bij of this class:

for (iterator iter = bij.cbeginSafe(); iter != bij.cendSafe(); ++iter) {
// loops will parse all the associations
}

Definition at line 257 of file bijection_tpl.h.

257  {
258  return BijectionIteratorSafe< T1, T2 >{*this};
259  }
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

◆ cend()

template<typename T1 , typename T2 , typename Alloc >
INLINE const BijectionImplementation< T1, T2, Alloc, true >::const_iterator & gum::BijectionImplementation< T1, T2, Alloc >::cend ( ) const
noexcept

Returns the constant iterator at the end of the gum::Bijection.

Unsafe iterators are a little bit faster than safe ones. But this speed is at the expense of safety: if you point to an element that is deleted, then try to access it or trying to operate a ++ will most certainly result in a segfault. So, Unsafe iterators should only be used to parse gum::Bijection where no element is ever deleted. If unsure, prefer using safe iterators.

Note that the notion of a beginning/end of a gum::Bijection is rather fuzzy. What is important here is that for an instance bij of this class:

for (iterator iter = bij.cbegin(); iter != bij.cend(); ++iter) {
// loops will parse all the associations
}

Definition at line 241 of file bijection_tpl.h.

241  {
242  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
244  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:647
static const BijectionIterator< int, int > * BijectionIterEnd__
The unsafe iterator used by everyone.
Definition: bijection.h:1336

◆ cendSafe()

template<typename T1 , typename T2 , typename Alloc >
INLINE const BijectionImplementation< T1, T2, Alloc, true >::const_iterator_safe & gum::BijectionImplementation< T1, T2, Alloc >::cendSafe ( ) const
noexcept

Returns the constant safe iterator at the end of the gum::Bijection.

Safe iterators are slightly slower than unsafe iterators. However, they guarantee that no segmentation fault can ever occur when trying to access the element they point to or when applying a ++ operator. When no element of the gum::Bijection is to be deleted during the parsing of the gum::Bijection (as for instance when you parse the gum::Bijection to display its content), prefer using the unsafe iterators, which are a little bit faster and cannot, in this case, produce segfaults.

Note that the notion of a beginning/end of a gum::Bijection is rather fuzzy. What is important here is that for an instance bij of this class:

for (iterator iter = bij.cbeginSafe(); iter != bij.cendSafe(); ++iter) {
// loops will parse all the associations
}

Definition at line 274 of file bijection_tpl.h.

274  {
275  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
277  }
static const BijectionIteratorSafe< int, int > * BijectionIterEndSafe__
The safe iterator used by everyone.
Definition: bijection.h:1333
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

◆ clear()

template<typename T1 , typename T2 , typename Alloc >
INLINE void gum::BijectionImplementation< T1, T2, Alloc >::clear ( )

Removes all the associations from the gum::Bijection.

Definition at line 157 of file bijection_tpl.h.

157  {
160  // note that iter_end__ is actually a constant, whatever we add/remove
161  // to/from firstToSecond__. As a consequence, it need not be updated
162  // after the clear's
163  }
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
void clear()
Removes all the elements in the hash table.

◆ copy__() [1/3]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE void gum::BijectionImplementation< T1, T2, Alloc, Gen >::copy__ ( const HashTable< T1, T2 *, OtherAlloc > &  f2s)

Definition at line 58 of file bijection_tpl.h.

59  {
60  // parse f2s and perform copies
61  for (auto iter = f2s.cbegin(); iter != f2s.cend(); ++iter) {
62  typename HashTable12::value_type* val1
63  = &(firstToSecond__.insert(iter.key(), nullptr));
64  typename HashTable21::value_type* val2;
65 
66  try {
67  val2 = &(secondToFirst__.insert(*(iter.val()), nullptr));
68  } catch (...) {
69  firstToSecond__.erase(iter.key());
70  throw;
71  }
72 
73  val1->second = &(const_cast< T2& >(val2->first));
74  val2->second = &(const_cast< T1& >(val1->first));
75  }
76 
77  // note that iter_end__ is actually a constant, whatever we add/remove
78  // to/from firstToSecond__. As a consequence, it need not be updated
79  // after copy__
80  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
std::pair< const T1, T2 * > value_type
Definition: hashTable.h:685
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ copy__() [2/3]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE void gum::BijectionImplementation< T1, T2, Alloc, Gen >::copy__ ( const HashTable< T1, T2, OtherAlloc > &  f2s)

Definition at line 561 of file bijection_tpl.h.

562  {
563  // parse f2s and perform copies
564  for (auto iter = f2s.cbegin(); iter != f2s.cend(); ++iter) {
565  firstToSecond__.insert(iter.key(), iter.val());
566 
567  try {
568  secondToFirst__.insert(iter.val(), iter.key());
569  } catch (...) {
570  firstToSecond__.erase(iter.key());
571  throw;
572  }
573  }
574 
575  // note that iter_end__ is actually a constant, whatever we add/remove
576  // to/from firstToSecond__. As a consequence, it need not be updated
577  // after copy__
578  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ copy__() [3/3]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
void gum::BijectionImplementation< T1, T2, Alloc, Gen >::copy__ ( const HashTable< T1, T2 *, OtherAlloc > &  source)
private

A function that performs a complete copy of another gum::Bijection.

Warning
this function assumes that "this" is an empty gum::Bijection. If it is not the case, use function clear() before calling copy__.
Parameters
sourceThe source from copied into this gum::Bijection.
Template Parameters
OtherAllocThe allocator used by source.

◆ emplace() [1/2]

template<typename T1 , typename T2 , typename Alloc >
template<typename... Args>
INLINE void gum::BijectionImplementation< T1, T2, Alloc >::emplace ( Args &&...  args)

Definition at line 411 of file bijection_tpl.h.

411  {
412  std::pair< T1, T2 > new_elt(std::forward< Args >(args)...);
413  insert__(std::move(new_elt.first), std::move(new_elt.second));
414  }
HashTable12::value_type * insert__(const T1 &first, const T2 &second)
Inserts a new association into the gum::Bijection.

◆ emplace() [2/2]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename... Args>
void gum::BijectionImplementation< T1, T2, Alloc, Gen >::emplace ( Args &&...  args)

Emplace a new element in the gum::Bijection.

The emplace method allows to construct directly an element of type Key by passing to its constructor all the arguments it needs.

Parameters
argsthe arguments passed to the constructor
Exceptions
DuplicateElementexception is thrown if the association already exists

◆ empty()

template<typename T1 , typename T2 , typename Alloc >
INLINE bool gum::BijectionImplementation< T1, T2, Alloc >::empty ( ) const
noexcept

Returns true if the gum::Bijection doesn't contain any association.

Returns
Returns true if the gum::Bijection doesn't contain any association.

Definition at line 419 of file bijection_tpl.h.

419  {
420  GUM_ASSERT(firstToSecond__.empty() == secondToFirst__.empty());
421  return firstToSecond__.empty();
422  }
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ end()

template<typename T1 , typename T2 , typename Alloc >
INLINE const BijectionImplementation< T1, T2, Alloc, true >::iterator & gum::BijectionImplementation< T1, T2, Alloc >::end ( ) const
noexcept

Returns the unsafe iterator at the end of the gum::Bijection.

Unsafe iterators are a little bit faster than safe ones. But this speed is at the expense of safety: if you point to an element that is deleted, then try to access it or trying to operate a ++ will most certainly result in a segfault. So, Unsafe iterators should only be used to parse gum::Bijection where no element is ever deleted. If unsure, prefer using safe iterators.

Note that the notion of a beginning/end of a gum::Bijection is rather fuzzy. What is important here is that for an instance bij of this class:

for(iterator iter = bij.begin(); iter != bij.end(); ++iter) {
// loops will parse all the associations
}

Definition at line 232 of file bijection_tpl.h.

232  {
233  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
235  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:647
static const BijectionIterator< int, int > * BijectionIterEnd__
The unsafe iterator used by everyone.
Definition: bijection.h:1336

◆ end4Statics()

template<typename T1 , typename T2 , typename Alloc >
const BijectionIterator< T1, T2 > & gum::BijectionImplementation< T1, T2, Alloc >::end4Statics ( )
static

Returns the unsafe end iterator for other classes' statics.

To reduce the gum::Bijection memory consumption (which are heavily used in aGrUM) while allowing fast for loops, end iterators are created just once as a static member of a non-template gum::Bijection. While this scheme is efficient and it works quite effectively, it has a drawback: other classes with static members using the BijectionImplementation::end() iterator may fail to work due to the well known "static initialization order fiasco" (see Marshall Cline's C++ FAQ for more details about this C++ feature).

So what is the problem? Consider a class, say X, containing a gum::Bijection that stores all its elements in a convenient way. To reduce memory consumption, X::end iterator is a static member that is initialized with a gum::Bijection::end iterator. If the compiler decides to initialize X::end before initializing gum::Bijection::end, then X::end will be in an incoherent state.

Unfortunately, we cannot know for sure in which order static members will be initialized (the order is a compiler's decision). Hence, we shall enfore the fact that gum::Bijection::end is initialized before X::end. Using method gum::Bijection::end4Statics will ensure this fact: it uses the C++ "construct on first use" idiom (see the C++ FAQ) that ensures that the order fiasco is avoided. More precisely, end4Statics uses a global variable that is the very end iterator used by all gum::Bijection. Now, this induces a small overhead. So, we also provide a gum::Bijection::end() method that returns the gum::Bijection::end iterator without this small overhead, but assuming that function end4Statics has already been called once (which is always the case) when a gum::Bijection has been created.

So, to summarize: when initializing static members use end4Statics() and in all the other cases, use end().

Definition at line 50 of file bijection_tpl.h.

50  {
51  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
53  }
static const BijectionIterator< int, int > * end4Statics()
Creates (if needed) and returns the iterator BijectionIterEnd__.
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:647

◆ endSafe()

template<typename T1 , typename T2 , typename Alloc >
INLINE const BijectionImplementation< T1, T2, Alloc, true >::iterator_safe & gum::BijectionImplementation< T1, T2, Alloc >::endSafe ( ) const
noexcept

Returns the safe iterator at the end of the gum::Bijection.

Safe iterators are slightly slower than unsafe iterators. However, they guarantee that no segmentation fault can ever occur when trying to access the element they point to or when applying a ++ operator. When no element of the gum::Bijection is to be deleted during the parsing of the gum::Bijection (as for instance when you parse the gum::Bijection to display its content), prefer using the unsafe iterators, which are a little bit faster and cannot, in this case, produce segfaults.

Note that the notion of a beginning/end of a gum::Bijection is rather fuzzy. What is important here is that for an instance bij of this class:

for (iterator iter = bij.beginSafe(); iter != bij.endSafe(); ++iter) {
// loops will parse all the associations
}

Definition at line 265 of file bijection_tpl.h.

265  {
266  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
268  }
static const BijectionIteratorSafe< int, int > * BijectionIterEndSafe__
The safe iterator used by everyone.
Definition: bijection.h:1333
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

◆ endSafe4Statics()

template<typename T1 , typename T2 , typename Alloc >
const BijectionIteratorSafe< T1, T2 > & gum::BijectionImplementation< T1, T2, Alloc >::endSafe4Statics ( )
static

Returns the safe end iterator for other classes' statics.

To reduce the gum::Bijection memory consumption (which are heavily used in aGrUM) while allowing fast for loops, end iterators are created just once as a static member of a non-template gum::Bijection. While this scheme is efficient and it works quite effectively, it has a drawback: other classes with static members using the BijectionImplementation::end() iterator may fail to work due to the well known "static initialization order fiasco" (see Marshall Cline's C++ FAQ for more details about this C++ feature).

So what is the problem? Consider a class, say X, containing a gum::Bijection that stores all its elements in a convenient way. To reduce memory consumption, X::end iterator is a static member that is initialized with a gum::Bijection::end iterator. If the compiler decides to initialize X::end before initializing gum::Bijection::end, then X::end will be in an incoherent state.

Unfortunately, we cannot know for sure in which order static members will be initialized (the order is a compiler's decision). Hence, we shall enfore the fact that gum::Bijection::end is initialized before X::end. Using method gum::Bijection::end4Statics will ensure this fact: it uses the C++ "construct on first use" idiom (see the C++ FAQ) that ensures that the order fiasco is avoided. More precisely, end4Statics uses a global variable that is the very end iterator used by all gum::Bijection. Now, this induces a small overhead. So, we also provide a gum::Bijection::end() method that returns the gum::Bijection::end iterator without this small overhead, but assuming that function end4Statics has already been called once (which is always the case) when a gum::Bijection has been created.

So, to summarize: when initializing static members use endSafe4Statics() and in all the other cases, use endSafe().

Definition at line 42 of file bijection_tpl.h.

42  {
43  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
45  }
static const BijectionIteratorSafe< int, int > * endSafe4Statics()
Creates (if needed) and returns the iterator BijectionIterEndSafe__.
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

◆ eraseFirst()

template<typename T1, typename T2 , typename Alloc , bool Gen>
INLINE void gum::BijectionImplementation< T1, T2, Alloc >::eraseFirst ( const T1 &  first)

Erases an association containing the given first element.

If the element cannot be found, nothing is done. In particular, no exception is raised.

Parameters
firstThe first element of a pair in the gum::Bijection.

Definition at line 435 of file bijection_tpl.h.

435  {
436  try {
438  firstToSecond__.erase(first);
439  } catch (NotFound&) {}
440  }
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ eraseSecond()

template<typename T1 , typename T2, typename Alloc , bool Gen>
INLINE void gum::BijectionImplementation< T1, T2, Alloc >::eraseSecond ( const T2 &  second)

Erases an association containing the given second element.

If the element cannot be found, nothing is done. In particular, no exception is raised.

Parameters
secondThe second element of a pair in the gum::Bijection.

Definition at line 445 of file bijection_tpl.h.

445  {
446  try {
448  secondToFirst__.erase(second);
449  } catch (NotFound&) {}
450  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ existsFirst()

template<typename T1, typename T2 , typename Alloc , bool Gen>
INLINE bool gum::BijectionImplementation< T1, T2, Alloc >::existsFirst ( const T1 &  first) const

Returns true if first is the first element in a pair in the gum::Bijection.

Parameters
firstThe element tested for existence.
Returns
Returns true if first is in the first element in a pair in the gum::Bijection.

Definition at line 295 of file bijection_tpl.h.

296  {
297  return firstToSecond__.exists(first);
298  }
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ existsSecond()

template<typename T1 , typename T2, typename Alloc , bool Gen>
INLINE bool gum::BijectionImplementation< T1, T2, Alloc >::existsSecond ( const T2 &  second) const

Returns true if second is the second element in a pair in the gum::Bijection.

Parameters
secondThe element tested for existence.
Returns
Returns true if second is in the second element in a pair in the gum::Bijection.

Definition at line 302 of file bijection_tpl.h.

303  {
304  return secondToFirst__.exists(second);
305  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662

◆ first()

template<typename T1 , typename T2, typename Alloc , bool Gen>
INLINE const T1 & gum::BijectionImplementation< T1, T2, Alloc >::first ( const T2 &  second) const

Returns the first value of a pair given its second value.

Parameters
secondThe second value of a pair in the gum::Bijection.
Returns
Returns the first value of a pair given its second value.
Exceptions
NotFoundRaised if the element cannot be found.

Definition at line 282 of file bijection_tpl.h.

282  {
283  return *(secondToFirst__[second]);
284  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662

◆ firstWithDefault()

template<typename T1, typename T2, typename Alloc , bool Gen>
INLINE const T1 & gum::BijectionImplementation< T1, T2, Alloc >::firstWithDefault ( const T2 &  second,
const T1 &  default_val 
) const

Returns the first value of a pair given its second value or default_val if second is unfound.

Parameters
secondThe second value of a pair in the gum::Bijection.
default_valThe default value returned if second is not in the gum::Bijection.
Returns
Returns the first value of a pair given its second value or default_val if second is not in the bjection.

Definition at line 372 of file bijection_tpl.h.

374  {
375  try {
376  return first(second);
377  } catch (NotFound&) { return insert__(val, second)->first; }
378  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
HashTable12::value_type * insert__(const T1 &first, const T2 &second)
Inserts a new association into the gum::Bijection.

◆ insert() [1/2]

template<typename T1, typename T2, typename Alloc , bool Gen>
INLINE void gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert ( const T1 &  first,
const T2 &  second 
)

Inserts a new association in the gum::Bijection.

The values are added by copy.

Parameters
firstThe first element of the pair to insert.
secondThe second element of the pair to insert.
Exceptions
DuplicateElementRaised if the association already exists.

Definition at line 395 of file bijection_tpl.h.

396  {
398  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
HashTable12::value_type * insert__(const T1 &first, const T2 &second)
Inserts a new association into the gum::Bijection.

◆ insert() [2/2]

template<typename T1, typename T2, typename Alloc , bool Gen>
INLINE void gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert ( T1 &&  first,
T2 &&  second 
)

Inserts a new association in the gum::Bijection.

The values are moved in the gum::Bijection.

Parameters
firstThe first element of the pair to insert.
secondThe second element of the pair to insert.
Exceptions
DuplicateElementRaised if the association already exists.

Definition at line 402 of file bijection_tpl.h.

403  {
404  insert__(std::move(first), std::move(second));
405  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
HashTable12::value_type * insert__(const T1 &first, const T2 &second)
Inserts a new association into the gum::Bijection.

◆ insert__() [1/2]

template<typename T1, typename T2, typename Alloc , bool Gen>
INLINE BijectionImplementation< T1, T2, Alloc, Gen >::HashTable12::value_type * gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert__ ( const T1 &  first,
const T2 &  second 
)
private

Inserts a new association into the gum::Bijection.

Parameters
firstThe first object in the association.
secondThe second object in the association.
Returns
Returns a pointer toward the inserted association.

Definition at line 311 of file bijection_tpl.h.

312  {
313  // check the uniqueness property
315  GUM_ERROR(DuplicateElement,
316  "the bijection contains an element with the same couple ("
317  << first << "," << second << ")");
318  }
319 
320  // insert copies of first and second
321  typename HashTable12::value_type* val1
322  = &(firstToSecond__.insert(first, nullptr));
323  typename HashTable21::value_type* val2;
324 
325  try {
326  val2 = &(secondToFirst__.insert(second, nullptr));
327  } catch (...) {
329  throw;
330  }
331 
332  val1->second = &(const_cast< T2& >(val2->first));
333  val2->second = &(const_cast< T1& >(val1->first));
334 
335  return val1;
336  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
void erase(const Key &key)
Removes a given element from the hash table.
bool existsSecond(const T2 &second) const
Returns true if second is the second element in a pair in the gum::Bijection.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
std::pair< const T1, T2 * > value_type
Definition: hashTable.h:685
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ insert__() [2/2]

template<typename T1, typename T2, typename Alloc , bool Gen>
INLINE BijectionImplementation< T1, T2, Alloc, Gen >::HashTable12::value_type * gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert__ ( T1 &&  first,
T2 &&  second 
)
private

Inserts a new association into the gum::Bijection.

Parameters
firstThe first object in the association.
secondThe second object in the association.
Returns
Returns a pointer toward the inserted association.

Definition at line 342 of file bijection_tpl.h.

343  {
344  // check the uniqueness property
346  GUM_ERROR(DuplicateElement,
347  "the bijection contains an element with the same couple ("
348  << first << "," << second << ")");
349  }
350 
351  // insert copies of first and second
352  typename HashTable12::value_type* val1
353  = &(firstToSecond__.insert(std::move(first), nullptr));
354  typename HashTable21::value_type* val2;
355 
356  try {
357  val2 = &(secondToFirst__.insert(std::move(second), nullptr));
358  } catch (...) {
359  firstToSecond__.erase(val1->first);
360  throw;
361  }
362 
363  val1->second = &(const_cast< T2& >(val2->first));
364  val2->second = &(const_cast< T1& >(val1->first));
365 
366  return val1;
367  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
void erase(const Key &key)
Removes a given element from the hash table.
bool existsSecond(const T2 &second) const
Returns true if second is the second element in a pair in the gum::Bijection.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
std::pair< const T1, T2 * > value_type
Definition: hashTable.h:685
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ operator=() [1/5]

template<typename T1, typename T2, typename Alloc, bool Gen>
INLINE BijectionImplementation< T1, T2, Alloc, Gen > & gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator= ( const BijectionImplementation< T1, T2, Alloc, Gen > &  toCopy)
private

Copy operator.

Parameters
toCopyBijection to copy.
Returns
Returns the gum::Bijection in which the copy was made.

Definition at line 168 of file bijection_tpl.h.

169  {
170  // avoid self assignment
171  if (this != &toCopy) {
172  clear();
173  copy__(toCopy.firstToSecond__);
174  }
175 
176  // note that iter_end__ is actually a constant, whatever we add/remove
177  // to/from firstToSecond__. As a consequence, it need not be updated
178  // after copy__
179  return *this;
180  }
void clear()
Removes all the associations from the gum::Bijection.
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.

◆ operator=() [2/5]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
BijectionImplementation< T1, T2, Alloc, Gen >& gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator= ( const BijectionImplementation< T1, T2, OtherAlloc, Gen > &  toCopy)
private

Generalized copy operator.

Parameters
toCopyBijection to copy.
Returns
Returns the gum::Bijection in which the copy was made.

◆ operator=() [3/5]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE BijectionImplementation< T1, T2, Alloc, Gen >& gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator= ( const BijectionImplementation< T1, T2, OtherAlloc, Gen > &  toCopy)

Definition at line 186 of file bijection_tpl.h.

187  {
188  clear();
189  copy__(toCopy.firstToSecond__);
190 
191  // note that iter_end__ is actually a constant, whatever we add/remove
192  // to/from firstToSecond__. As a consequence, it need not be updated
193  // after copy__
194  return *this;
195  }
void clear()
Removes all the associations from the gum::Bijection.
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.

◆ operator=() [4/5]

template<typename T1, typename T2, typename Alloc, bool Gen>
INLINE BijectionImplementation< T1, T2, Alloc, Gen > & gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator= ( BijectionImplementation< T1, T2, Alloc, Gen > &&  toCopy)
private

Move operator.

Parameters
toCopyBijection to move
Returns
Returns the moved gum::Bijection in which the move was made.

Definition at line 200 of file bijection_tpl.h.

201  {
202  // avoid self assignment
203  if (this != &from) {
204  clear();
205  firstToSecond__ = std::move(from.firstToSecond__);
206  secondToFirst__ = std::move(from.secondToFirst__);
207  }
208 
209  // note that iter_end__ is actually a constant, whatever we add/remove
210  // to/from firstToSecond__. As a consequence, it need not be updated
211  // after copy__
212  return *this;
213  }
void clear()
Removes all the associations from the gum::Bijection.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ operator=() [5/5]

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename OtherAlloc >
INLINE BijectionImplementation< T1, T2, Alloc, true >& gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator= ( const BijectionImplementation< T1, T2, OtherAlloc, true > &  toCopy)

Definition at line 712 of file bijection_tpl.h.

713  {
714  clear();
715  copy__(toCopy.firstToSecond__);
716 
717  // note that iter_end__ is actually a constant, whatever we add/remove
718  // to/from firstToSecond__. As a consequence, it need not be updated
719  // after copy__
720  return *this;
721  }
void clear()
Removes all the associations from the gum::Bijection.
void copy__(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.

◆ resize()

template<typename T1 , typename T2 , typename Alloc >
INLINE void gum::BijectionImplementation< T1, T2, Alloc >::resize ( Size  new_size)

Manually resize the gum::Bijection.

See gum::HashTable::resize(gum::Size)

Parameters
new_sizeThe gum::Bijection new size.

Definition at line 462 of file bijection_tpl.h.

462  {
463  firstToSecond__.resize(new_size);
464  secondToFirst__.resize(new_size);
465  }
void resize(Size new_size)
Changes the number of slots in the &#39;nodes&#39; vector of the hash table.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ resizePolicy()

template<typename T1 , typename T2 , typename Alloc >
INLINE bool gum::BijectionImplementation< T1, T2, Alloc >::resizePolicy ( ) const
noexcept

Returns true if the resize policy is automatic.

See gum::HashTable::resizePolicy().

Returns
Returns true if the resize policy is automatic.

Definition at line 478 of file bijection_tpl.h.

478  {
479  return firstToSecond__.resizePolicy();
480  }
bool resizePolicy() const noexcept
Returns the current resizing policy.
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ second()

template<typename T1, typename T2 , typename Alloc , bool Gen>
INLINE const T2 & gum::BijectionImplementation< T1, T2, Alloc >::second ( const T1 &  first) const

Returns the second value of a pair given its first value.

Parameters
firstThe first value of a pair in the gum::Bijection.
Returns
Returns the second value of a pair given its first value.
Exceptions
NotFoundRaised if the element cannot be found.

Definition at line 289 of file bijection_tpl.h.

289  {
290  return *(firstToSecond__[first]);
291  }
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ secondWithDefault()

template<typename T1, typename T2, typename Alloc , bool Gen>
INLINE const T2 & gum::BijectionImplementation< T1, T2, Alloc >::secondWithDefault ( const T1 &  second,
const T2 &  default_val 
) const

Returns the second value of a pair given its first value or default_val if first is unfound.

Parameters
secondThe second value of a pair in the gum::Bijection.
default_valThe default value returned if first is not in the gum::Bijection.
Returns
Returns the second value of a pair given its first value or default_val if first is not in the bjection.

Definition at line 384 of file bijection_tpl.h.

386  {
387  try {
388  return second(first);
389  } catch (NotFound&) { return *(insert__(first, val)->second); }
390  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
HashTable12::value_type * insert__(const T1 &first, const T2 &second)
Inserts a new association into the gum::Bijection.

◆ setResizePolicy()

template<typename T1 , typename T2 , typename Alloc >
INLINE void gum::BijectionImplementation< T1, T2, Alloc >::setResizePolicy ( const bool  new_policy)
noexcept

Change the gum::Bijection resizing policy.

See gum::HashTable::setResizePolicy( const bool );

Parameters
new_policyIf true, the gum::Bijection will resize automatically.

Definition at line 469 of file bijection_tpl.h.

470  {
471  firstToSecond__.setResizePolicy(new_policy);
472  secondToFirst__.setResizePolicy(new_policy);
473  }
void setResizePolicy(const bool new_policy) noexcept
Enables the user to change dynamically the resizing policy.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ size()

template<typename T1 , typename T2 , typename Alloc >
INLINE Size gum::BijectionImplementation< T1, T2, Alloc >::size ( ) const
noexcept

Returns the number of associations stored within the gum::Bijection.

Returns
Returns the number of associations stored within the gum::Bijection.

Definition at line 427 of file bijection_tpl.h.

427  {
428  GUM_ASSERT(firstToSecond__.size() == secondToFirst__.size());
429  return firstToSecond__.size();
430  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable21 secondToFirst__
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:662
HashTable12 firstToSecond__
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:659

◆ toString()

template<typename T1 , typename T2 , typename Alloc >
std::string gum::BijectionImplementation< T1, T2, Alloc >::toString ( ) const

Returns a friendly representatin of the gum::Bijection.

Returns
Returns a friendly representatin of the gum::Bijection.

Definition at line 484 of file bijection_tpl.h.

484  {
485  std::stringstream stream;
486  stream << "{ ";
487  bool first = true;
488 
489  for (iterator iter = begin(); iter != end(); ++iter) {
490  if (!first)
491  stream << ", ";
492  else
493  first = false;
494 
495  stream << '(' << iter.first() << " <-> " << iter.second() << ')';
496  }
497 
498  stream << " }";
499  return stream.str();
500  }
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
iterator begin() const
Returns the unsafe iterator at the beginning of the gum::Bijection.
BijectionIterator< T1, T2 > iterator
types for STL compliance
Definition: bijection.h:101
const iterator & end() const noexcept
Returns the unsafe iterator at the end of the gum::Bijection.

Friends And Related Function Documentation

◆ BijectionImplementation

template<typename T1, typename T2, typename Alloc, bool Gen>
template<typename TT1 , typename TT2 , typename A , bool >
friend class BijectionImplementation
friend

a friend to speed-up accesses

Definition at line 650 of file bijection.h.

◆ Bijection< T1, T2, Alloc >

template<typename T1, typename T2, typename Alloc, bool Gen>
friend class Bijection< T1, T2, Alloc >
friend

a friend to speed-up accesses

Definition at line 648 of file bijection.h.

◆ BijectionIterator< T1, T2 >

template<typename T1, typename T2, typename Alloc, bool Gen>
friend class BijectionIterator< T1, T2 >
friend

a friend to speed-up accesses

Definition at line 647 of file bijection.h.

◆ BijectionIteratorSafe< T1, T2 >

template<typename T1, typename T2, typename Alloc, bool Gen>
friend class BijectionIteratorSafe< T1, T2 >
friend

a friend to speed-up accesses

Definition at line 646 of file bijection.h.

Member Data Documentation

◆ firstToSecond__

template<typename T1, typename T2, typename Alloc, bool Gen>
HashTable12 gum::BijectionImplementation< T1, T2, Alloc, Gen >::firstToSecond__
private

The gum::HashTable associating T2 objects to T1 objects.

Definition at line 659 of file bijection.h.

◆ secondToFirst__

template<typename T1, typename T2, typename Alloc, bool Gen>
HashTable21 gum::BijectionImplementation< T1, T2, Alloc, Gen >::secondToFirst__
private

The gum::HashTable associating T1 objects to T2 objects.

Definition at line 662 of file bijection.h.


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