aGrUM  0.13.2
gum::BijectionImplementation< T1, T2, Alloc, Gen > Class Template Reference

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

#include <agrum/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 83 of file bijection.h.

Member Typedef Documentation

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 105 of file bijection.h.

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 107 of file bijection.h.

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 99 of file bijection.h.

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 101 of file bijection.h.

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 103 of file bijection.h.

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 98 of file bijection.h.

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 639 of file bijection.h.

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 640 of file bijection.h.

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 100 of file bijection.h.

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 102 of file bijection.h.

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 97 of file bijection.h.

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 91 of file bijection.h.

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 89 of file bijection.h.

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 90 of file bijection.h.

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 88 of file bijection.h.

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 87 of file bijection.h.

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 96 of file bijection.h.

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 94 of file bijection.h.

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 95 of file bijection.h.

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 93 of file bijection.h.

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 92 of file bijection.h.

Constructor & Destructor Documentation

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 81 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::end4Statics(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::endSafe4Statics().

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

+ Here is the call graph for this function:

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 99 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::end4Statics(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::endSafe4Statics(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert().

100  :
101  __firstToSecond(Size(list.size()) / 2, true, false),
102  __secondToFirst(Size(list.size()) / 2, true, false) {
103  GUM_CONSTRUCTOR(BijectionImplementation);
104 
105  for (const auto& elt : list) {
106  insert(elt.first, elt.second);
107  }
108 
109  // make sure the end() iterator is constructed properly
110  end4Statics();
111  endSafe4Statics();
112  }
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:649
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
static const iterator_safe & endSafe4Statics()
Returns the safe end iterator for other classes&#39; statics.
Definition: bijection_tpl.h:39
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
static const iterator & end4Statics()
Returns the unsafe end iterator for other classes&#39; statics.
Definition: bijection_tpl.h:47
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

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 116 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond.

117  :
118  __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
119  __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
120  GUM_CONS_CPY(BijectionImplementation);
121  __copy(toCopy.__firstToSecond);
122  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649
void __copy(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

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.
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 137 of file bijection_tpl.h.

138  :
139  __firstToSecond(std::move(from.__firstToSecond)),
140  __secondToFirst(std::move(from.__secondToFirst)) {
141  GUM_CONS_MOV(BijectionImplementation);
142  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661
template<typename T1 , typename T2 , typename Alloc >
INLINE gum::BijectionImplementation< T1, T2, Alloc >::~BijectionImplementation ( )

Destructor.

Definition at line 147 of file bijection_tpl.h.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation().

147  {
148  GUM_DESTRUCTOR(BijectionImplementation);
149  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649

+ Here is the caller graph for this function:

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 127 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond.

128  :
129  __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
130  __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
131  GUM_CONS_CPY(BijectionImplementation);
132  __copy(toCopy.__firstToSecond);
133  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649
void __copy(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

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 573 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond.

574  :
575  __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
576  __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
577  GUM_CONS_CPY(BijectionImplementation);
578  __copy(toCopy.__firstToSecond);
579  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649
void __copy(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

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 584 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond.

585  :
586  __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
587  __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
588  GUM_CONS_CPY(BijectionImplementation);
589  __copy(toCopy.__firstToSecond);
590  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649
void __copy(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

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 594 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::__BijectionIterEnd, gum::BijectionIteratorStaticEnd::__BijectionIterEndSafe, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::BijectionImplementation< T1, T2, Alloc, Gen >::begin(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::beginSafe(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::cbegin(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::cbeginSafe(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::cend(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::cendSafe(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::clear(), gum::HashTable< Key, Val, Alloc >::clear(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::end(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::endSafe(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::~BijectionImplementation().

595  :
596  __firstToSecond(std::move(toCopy.__firstToSecond)),
597  __secondToFirst(std::move(toCopy.__secondToFirst)) {
598  GUM_CONS_MOV(BijectionImplementation);
599  }
friend class BijectionImplementation
a friend to speed-up accesses
Definition: bijection.h:649
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

Member Function Documentation

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 55 of file bijection_tpl.h.

References gum::HashTable< Key, Val, Alloc >::cbegin(), and gum::HashTable< Key, Val, Alloc >::cend().

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

+ Here is the call graph for this function:

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 552 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::HashTable< Key, Val, Alloc >::cbegin(), gum::HashTable< Key, Val, Alloc >::cend(), gum::HashTable< Key, Val, Alloc >::erase(), and gum::HashTable< Key, Val, Alloc >::insert().

553  {
554  // parse f2s and perform copies
555  for (auto iter = f2s.cbegin(); iter != f2s.cend(); ++iter) {
556  __firstToSecond.insert(iter.key(), iter.val());
557 
558  try {
559  __secondToFirst.insert(iter.val(), iter.key());
560  } catch (...) {
561  __firstToSecond.erase(iter.key());
562  throw;
563  }
564  }
565 
566  // note that __iter_end is actually a constant, whatever we add/remove
567  // to/from __firstToSecond. As a consequence, it need not be updated
568  // after __copy
569  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

+ Here is the call graph for this function:

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.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

+ Here is the caller graph for this function:

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 307 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::HashTable< Key, Val, Alloc >::erase(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::existsFirst(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::existsSecond(), GUM_ERROR, and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::emplace(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::firstWithDefault(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::secondWithDefault().

308  {
309  // check the uniqueness property
311  GUM_ERROR(DuplicateElement,
312  "the bijection contains an element with the same key");
313  }
314 
315  // insert copies of first and second
316  typename HashTable12::value_type* val1 =
317  &(__firstToSecond.insert(first, nullptr));
318  typename HashTable21::value_type* val2;
319 
320  try {
321  val2 = &(__secondToFirst.insert(second, nullptr));
322  } catch (...) {
324  throw;
325  }
326 
327  val1->second = &(const_cast< T2& >(val2->first));
328  val2->second = &(const_cast< T1& >(val1->first));
329 
330  return val1;
331  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
bool existsSecond(const T2 &second) const
Returns true if second is the second element in a pair in the gum::Bijection.
std::pair< const T1, T2 * > value_type
Definition: hashTable.h:682
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 337 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::HashTable< Key, Val, Alloc >::erase(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::existsFirst(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::existsSecond(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::second().

338  {
339  // check the uniqueness property
341  GUM_ERROR(DuplicateElement,
342  "the bijection contains an element with the same key");
343  }
344 
345  // insert copies of first and second
346  typename HashTable12::value_type* val1 =
347  &(__firstToSecond.insert(std::move(first), nullptr));
348  typename HashTable21::value_type* val2;
349 
350  try {
351  val2 = &(__secondToFirst.insert(std::move(second), nullptr));
352  } catch (...) {
353  __firstToSecond.erase(val1->first);
354  throw;
355  }
356 
357  val1->second = &(const_cast< T2& >(val2->first));
358  val2->second = &(const_cast< T1& >(val1->first));
359 
360  return val1;
361  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
void erase(const Key &key)
Removes a given element from the hash table.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
bool existsSecond(const T2 &second) const
Returns true if second is the second element in a pair in the gum::Bijection.
std::pair< const T1, T2 * > value_type
Definition: hashTable.h:682
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
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:66

+ Here is the call graph for this function:

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 214 of file bijection_tpl.h.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

214  {
215  return BijectionIterator< T1, T2 >{*this};
216  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

+ Here is the caller graph for this function:

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 245 of file bijection_tpl.h.

Referenced by gum::ExactTerminalNodePolicy< GUM_SCALAR >::beginValues(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation().

245  {
246  return BijectionIteratorSafe< T1, T2 >{*this};
247  }
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:645

+ Here is the caller graph for this function:

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 446 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, and gum::HashTable< Key, Val, Alloc >::capacity().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

447  {
448  return __firstToSecond.capacity();
449  }
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
Size capacity() const noexcept
Returns the number of slots in the &#39;nodes&#39; vector of the hashtable.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 221 of file bijection_tpl.h.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation().

221  {
222  return BijectionIterator< T1, T2 >{*this};
223  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646

+ Here is the caller graph for this function:

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 253 of file bijection_tpl.h.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation().

253  {
254  return BijectionIteratorSafe< T1, T2 >{*this};
255  }
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:645

+ Here is the caller graph for this function:

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 237 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::__BijectionIterEnd.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation().

237  {
238  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
240  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646
static const BijectionIterator< int, int > * __BijectionIterEnd
The unsafe iterator used by everyone.
Definition: bijection.h:1335

+ Here is the caller graph for this function:

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 270 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::__BijectionIterEndSafe.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation().

270  {
271  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
273  }
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:645
static const BijectionIteratorSafe< int, int > * __BijectionIterEndSafe
The safe iterator used by everyone.
Definition: bijection.h:1332

+ Here is the caller graph for this function:

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 153 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::HashTable< Key, Val, Alloc >::clear(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), gum::ExactTerminalNodePolicy< GUM_SCALAR >::clearAllTerminalNodes(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

153  {
156  // note that __iter_end is actually a constant, whatever we add/remove
157  // to/from __firstToSecond. As a consequence, it need not be updated
158  // after the clear's
159  }
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
void clear()
Removes all the elements in the hash table.
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 403 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert().

403  {
404  std::pair< T1, T2 > new_elt(std::forward< Args >(args)...);
405  __insert(std::move(new_elt.first), std::move(new_elt.second));
406  }
HashTable12::value_type * __insert(const T1 &first, const T2 &second)
Inserts a new association into the gum::Bijection.

+ Here is the call graph for this function:

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

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

+ Here is the caller graph for this function:

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 410 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::empty().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

411  {
412  GUM_ASSERT(__firstToSecond.empty() == __secondToFirst.empty());
413  return __firstToSecond.empty();
414  }
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661
bool empty() const noexcept
Indicates whether the hash table is empty.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 228 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::__BijectionIterEnd.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

228  {
229  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
231  }
friend class BijectionIterator< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:646
static const BijectionIterator< int, int > * __BijectionIterEnd
The unsafe iterator used by everyone.
Definition: bijection.h:1335

+ Here is the caller graph for this function:

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 47 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::end4Statics().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

47  {
48  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
50  }
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:646

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 261 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::__BijectionIterEndSafe.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), and gum::ExactTerminalNodePolicy< GUM_SCALAR >::hasValue().

261  {
262  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
264  }
friend class BijectionIteratorSafe< T1, T2 >
a friend to speed-up accesses
Definition: bijection.h:645
static const BijectionIteratorSafe< int, int > * __BijectionIterEndSafe
The safe iterator used by everyone.
Definition: bijection.h:1332

+ Here is the caller graph for this function:

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 39 of file bijection_tpl.h.

References gum::BijectionIteratorStaticEnd::endSafe4Statics().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

39  {
40  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
42  }
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:645

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 427 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::erase().

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::ExactTerminalNodePolicy< GUM_SCALAR >::eraseTerminalNode(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

427  {
428  try {
430  __firstToSecond.erase(first);
431  } catch (NotFound&) {}
432  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 437 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::erase().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

437  {
438  try {
440  __secondToFirst.erase(second);
441  } catch (NotFound&) {}
442  }
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.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 291 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, and gum::HashTable< Key, Val, Alloc >::exists().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::ExactTerminalNodePolicy< GUM_SCALAR >::existsTerminalNodeWithId(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

292  {
293  return __firstToSecond.exists(first);
294  }
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:658
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 298 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::exists().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), gum::ExactTerminalNodePolicy< GUM_SCALAR >::existsTerminalNodeWithValue(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

299  {
300  return __secondToFirst.exists(second);
301  }
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:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 278 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::BijectionImplementation< T1, T2, Alloc, Gen >::second().

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::firstWithDefault(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), gum::learning::genericBNLearner::Database::nameFromId(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::second(), gum::ExactTerminalNodePolicy< GUM_SCALAR >::terminalNodeId(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::toDatabaseTable(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString(), and gum::learning::BNDatabaseGenerator< GUM_SCALAR >::varOrderNames().

278  {
279  return *(__secondToFirst[second]);
280  }
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:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 366 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::first().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

367  {
368  try {
369  return first(second);
370  } catch (NotFound&) { return __insert(val, second)->first; }
371  }
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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 387 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert().

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::ExactTerminalNodePolicy< GUM_SCALAR >::addTerminalNode(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::BNDatabaseGenerator(), gum::learning::genericBNLearner::Database::Database(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

388  {
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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 394 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::second().

395  {
396  __insert(std::move(first), std::move(second));
397  }
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.

+ Here is the call graph for this function:

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 165 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, and gum::BijectionImplementation< T1, T2, Alloc, Gen >::clear().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::clear(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.
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 183 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::clear(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

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

+ Here is the call graph for this function:

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 197 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::BijectionImplementation< T1, T2, Alloc, Gen >::clear().

197  {
198  // avoid self assignment
199  if (this != &from) {
200  clear();
201  __firstToSecond = std::move(from.__firstToSecond);
202  __secondToFirst = std::move(from.__secondToFirst);
203  }
204 
205  // note that __iter_end is actually a constant, whatever we add/remove
206  // to/from __firstToSecond. As a consequence, it need not be updated
207  // after __copy
208  return *this;
209  }
void clear()
Removes all the associations from the gum::Bijection.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

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 703 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::BijectionImplementation< T1, T2, Alloc, Gen >::begin(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::capacity(), gum::HashTable< Key, Val, Alloc >::capacity(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::clear(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::emplace(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::empty(), gum::HashTable< Key, Val, Alloc >::empty(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::end(), gum::HashTable< Key, Val, Alloc >::erase(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::eraseFirst(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::eraseSecond(), gum::HashTable< Key, Val, Alloc >::exists(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::existsFirst(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::existsSecond(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::firstWithDefault(), GUM_ERROR, gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::resize(), gum::HashTable< Key, Val, Alloc >::resize(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::resizePolicy(), gum::HashTable< Key, Val, Alloc >::resizePolicy(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::second(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::secondWithDefault(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::setResizePolicy(), gum::HashTable< Key, Val, Alloc >::setResizePolicy(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::size(), gum::HashTable< Key, Val, Alloc >::size(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

704  {
705  clear();
706  __copy(toCopy.__firstToSecond);
707 
708  // note that __iter_end is actually a constant, whatever we add/remove
709  // to/from __firstToSecond. As a consequence, it need not be updated
710  // after __copy
711  return *this;
712  }
void __copy(const HashTable< T1, T2 *, OtherAlloc > &source)
A function that performs a complete copy of another gum::Bijection.
void clear()
Removes all the associations from the gum::Bijection.
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 454 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::resize().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

454  {
455  __firstToSecond.resize(new_size);
456  __secondToFirst.resize(new_size);
457  }
void resize(Size new_size)
Changes the number of slots in the &#39;nodes&#39; vector of the hash table.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 469 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, and gum::HashTable< Key, Val, Alloc >::resizePolicy().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

470  {
471  return __firstToSecond.resizePolicy();
472  }
bool resizePolicy() const noexcept
Returns the current resizing policy.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 285 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, and gum::BijectionImplementation< T1, T2, Alloc, Gen >::first().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::__varOrderFromCSV(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), gum::learning::genericBNLearner::Database::idFromName(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), gum::MultiDimBijArray< GUM_SCALAR >::MultiDimBijArray(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::secondWithDefault(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setVarOrder(), and gum::ExactTerminalNodePolicy< GUM_SCALAR >::terminalNodeValue().

285  {
286  return *(__firstToSecond[first]);
287  }
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 377 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__insert(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::second().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

378  {
379  try {
380  return second(first);
381  } catch (NotFound&) { return *(__insert(first, val)->second); }
382  }
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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 461 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::setResizePolicy().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

462  {
463  __firstToSecond.setResizePolicy(new_policy);
464  __secondToFirst.setResizePolicy(new_policy);
465  }
void setResizePolicy(const bool new_policy) noexcept
Enables the user to change dynamically the resizing policy.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 418 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, and gum::HashTable< Key, Val, Alloc >::size().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

419  {
420  GUM_ASSERT(__firstToSecond.size() == __secondToFirst.size());
421  return __firstToSecond.size();
422  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:658
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:661

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 476 of file bijection_tpl.h.

References gum::BijectionImplementation< T1, T2, Alloc, Gen >::__firstToSecond, gum::BijectionImplementation< T1, T2, Alloc, Gen >::__secondToFirst, gum::BijectionImplementation< T1, T2, Alloc, Gen >::begin(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::BijectionImplementation, gum::BijectionImplementation< T1, T2, Alloc, Gen >::end(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::end4Statics(), gum::BijectionIteratorStaticEnd::end4Statics(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::endSafe4Statics(), gum::BijectionIteratorStaticEnd::endSafe4Statics(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), and gum::BijectionImplementation< T1, T2, Alloc, Gen >::size().

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::operator=().

476  {
477  std::stringstream stream;
478  stream << "{ ";
479  bool first = true;
480 
481  for (iterator iter = begin(); iter != end(); ++iter) {
482  if (!first)
483  stream << ", ";
484  else
485  first = false;
486 
487  stream << '(' << iter.first() << " <-> " << iter.second() << ')';
488  }
489 
490  stream << " }";
491  return stream.str();
492  }
BijectionIterator< T1, T2 > iterator
types for STL compliance
Definition: bijection.h:100
const iterator & end() const noexcept
Returns the unsafe iterator at the end of the gum::Bijection.
iterator begin() const
Returns the unsafe iterator at the beginning of the gum::Bijection.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

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 649 of file bijection.h.

Referenced by gum::BijectionImplementation< T1, T2, Alloc, Gen >::toString().

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 647 of file bijection.h.

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

a friend to speed-up accesses

Definition at line 646 of file bijection.h.

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

a friend to speed-up accesses

Definition at line 645 of file bijection.h.

Member Data Documentation


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