aGrUM  0.16.0
gum::Bijection< T1, T2, Alloc > Class Template Reference

Set of pairs of elements with fast search for both elements. More...

#include <agrum/core/bijection.h>

+ Inheritance diagram for gum::Bijection< T1, T2, Alloc >:
+ Collaboration diagram for gum::Bijection< T1, T2, Alloc >:

Public Member Functions

template<typename OtherAlloc >
INLINE Bijection (const Bijection< T1, T2, OtherAlloc > &toCopy)
 
template<typename OtherAlloc >
INLINE Bijection< T1, T2, Alloc > & operator= (const Bijection< T1, T2, OtherAlloc > &toCopy)
 
INLINE void emplace (Args &&... args)
 
INLINE void __copy (const HashTable< T1, T2 *, OtherAlloc > &f2s)
 
INLINE void __copy (const HashTable< T1, T2, OtherAlloc > &f2s)
 
Constructors/destructors
 Bijection (Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
 Default constructor: creates a gum::Bijection without any association. More...
 
 Bijection (std::initializer_list< std::pair< T1, T2 > > list)
 Initializer list constructor. More...
 
 Bijection (const Bijection< T1, T2, Alloc > &toCopy)
 Copy constructor. More...
 
template<typename OtherAlloc >
 Bijection (const Bijection< T1, T2, OtherAlloc > &toCopy)
 Generalized copy constructor. More...
 
 Bijection (Bijection< T1, T2, Alloc > &&from) noexcept
 Move constructor. More...
 
 ~Bijection ()
 Class destructor. More...
 
Operators
Bijection< T1, T2, Alloc > & operator= (const Bijection< T1, T2, Alloc > &toCopy)
 Copy operator. More...
 
template<typename OtherAlloc >
Bijection< T1, T2, Alloc > & operator= (const Bijection< T1, T2, OtherAlloc > &toCopy)
 Generalized copy operator. More...
 
Bijection< T1, T2, Alloc > & operator= (Bijection< T1, T2, Alloc > &&bij)
 Move operator. 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...
 
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 Implementation = BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >
 The Implementation of this gum::Bijection. More...
 
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 allocator1_type = typename Alloc::template rebind< T1 *>::other
 types for STL compliance More...
 
using allocator2_type = typename Alloc::template rebind< T2 *>::other
 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...
 

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 = std::allocator< T2 >>
class gum::Bijection< T1, T2, Alloc >

Set of pairs of elements with fast search for both elements.

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.

Definition at line 1805 of file bijection.h.

Member Typedef Documentation

◆ allocator12_type

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

types for STL compliance

Definition at line 107 of file bijection.h.

◆ allocator1_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::allocator1_type = typename Alloc::template rebind< T1* >::other

types for STL compliance

Definition at line 1832 of file bijection.h.

◆ allocator21_type

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

types for STL compliance

Definition at line 109 of file bijection.h.

◆ allocator2_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::allocator2_type = typename Alloc::template rebind< T2* >::other

types for STL compliance

Definition at line 1833 of file bijection.h.

◆ allocator_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::allocator_type = Alloc

types for STL compliance

Definition at line 1826 of file bijection.h.

◆ const_iterator

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::const_iterator = BijectionIterator< T1, T2 >

types for STL compliance

Definition at line 1828 of file bijection.h.

◆ const_iterator_safe

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::const_iterator_safe = BijectionIteratorSafe< T1, T2 >

types for STL compliance

Definition at line 1830 of file bijection.h.

◆ difference_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::difference_type = std::ptrdiff_t

types for STL compliance

Definition at line 1825 of file bijection.h.

◆ Implementation

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::Implementation = BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value && std::is_scalar< T2 >::value >

The Implementation of this gum::Bijection.

Definition at line 1842 of file bijection.h.

◆ iterator

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::iterator = BijectionIterator< T1, T2 >

types for STL compliance

Definition at line 1827 of file bijection.h.

◆ iterator_safe

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::iterator_safe = BijectionIteratorSafe< T1, T2 >

types for STL compliance

Definition at line 1829 of file bijection.h.

◆ size_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::size_type = std::size_t

types for STL compliance

Definition at line 1824 of file bijection.h.

◆ type1_const_pointer

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type1_const_pointer = const T1*

types for STL compliance

Definition at line 1818 of file bijection.h.

◆ type1_const_reference

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type1_const_reference = const T1&

types for STL compliance

Definition at line 1816 of file bijection.h.

◆ type1_pointer

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type1_pointer = T1*

types for STL compliance

Definition at line 1817 of file bijection.h.

◆ type1_reference

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type1_reference = T1&

types for STL compliance

Definition at line 1815 of file bijection.h.

◆ type1_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type1_type = T1

types for STL compliance

Definition at line 1814 of file bijection.h.

◆ type2_const_pointer

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type2_const_pointer = const T2*

types for STL compliance

Definition at line 1823 of file bijection.h.

◆ type2_const_reference

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type2_const_reference = const T2&

types for STL compliance

Definition at line 1821 of file bijection.h.

◆ type2_pointer

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type2_pointer = T2*

types for STL compliance

Definition at line 1822 of file bijection.h.

◆ type2_reference

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type2_reference = T2&

types for STL compliance

Definition at line 1820 of file bijection.h.

◆ type2_type

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
using gum::Bijection< T1, T2, Alloc >::type2_type = T2

types for STL compliance

Definition at line 1819 of file bijection.h.

Constructor & Destructor Documentation

◆ Bijection() [1/6]

template<typename T1 , typename T2 , typename Alloc >
INLINE gum::Bijection< T1, T2, Alloc >::Bijection ( Size  size = HashTableConst::default_size,
bool  resize_policy = HashTableConst::default_resize_policy 
)

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

Parameters
sizeThe gum::Bijection starting size.
resize_policyIf tru, the gum::Bijection will be automatically resized.

Definition at line 1156 of file bijection_tpl.h.

1156  :
1158  T2,
1159  Alloc,
1160  std::is_scalar< T1 >::value
1161  && std::is_scalar< T2 >::value >(size,
1162  resize_policy) {
1163  GUM_CONSTRUCTOR(Bijection);
1164  }
Size size() const noexcept
Returns the number of associations stored within the gum::Bijection.
Bijection(Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
Default constructor: creates a gum::Bijection without any association.

◆ Bijection() [2/6]

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

Initializer list constructor.

Parameters
listThe initialisation list.

Definition at line 1168 of file bijection_tpl.h.

1169  :
1171  T2,
1172  Alloc,
1173  std::is_scalar< T1 >::value
1174  && std::is_scalar< T2 >::value >(list) {
1175  GUM_CONSTRUCTOR(Bijection);
1176  }
Bijection(Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
Default constructor: creates a gum::Bijection without any association.

◆ Bijection() [3/6]

template<typename T1, typename T2, typename Alloc>
INLINE gum::Bijection< T1, T2, Alloc >::Bijection ( const Bijection< T1, T2, Alloc > &  toCopy)

Copy constructor.

Parameters
toCopyThe gum::Bijection to copy.

Definition at line 1180 of file bijection_tpl.h.

1181  :
1183  T2,
1184  Alloc,
1185  std::is_scalar< T1 >::value
1186  && std::is_scalar< T2 >::value >(toCopy) {
1187  GUM_CONS_CPY(Bijection);
1188  }
Bijection(Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
Default constructor: creates a gum::Bijection without any association.

◆ Bijection() [4/6]

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
template<typename OtherAlloc >
gum::Bijection< T1, T2, Alloc >::Bijection ( const Bijection< T1, T2, OtherAlloc > &  toCopy)

Generalized copy constructor.

Parameters
toCopyThe gum::Bijection to copy.
Template Parameters
Thegum::Bijection to copy allocator's type.

◆ Bijection() [5/6]

template<typename T1, typename T2, typename Alloc>
INLINE gum::Bijection< T1, T2, Alloc >::Bijection ( Bijection< T1, T2, Alloc > &&  from)
noexcept

Move constructor.

Parameters
fromThe gum::Bijection to move from.

Definition at line 1205 of file bijection_tpl.h.

1206  :
1208  T2,
1209  Alloc,
1210  std::is_scalar< T1 >::value
1211  && std::is_scalar< T2 >::value >(
1212  std::move(from)) {
1213  GUM_CONS_MOV(Bijection);
1214  }
Bijection(Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
Default constructor: creates a gum::Bijection without any association.

◆ ~Bijection()

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

Class destructor.

Definition at line 1218 of file bijection_tpl.h.

1218  {
1219  GUM_DESTRUCTOR(Bijection);
1220  }
Bijection(Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
Default constructor: creates a gum::Bijection without any association.

◆ Bijection() [6/6]

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
template<typename OtherAlloc >
INLINE gum::Bijection< T1, T2, Alloc >::Bijection ( const Bijection< T1, T2, OtherAlloc > &  toCopy)

Definition at line 1193 of file bijection_tpl.h.

1194  :
1196  T2,
1197  Alloc,
1198  std::is_scalar< T1 >::value
1199  && std::is_scalar< T2 >::value >(toCopy) {
1200  GUM_CONS_CPY(Bijection);
1201  }
Bijection(Size size=HashTableConst::default_size, bool resize_policy=HashTableConst::default_resize_policy)
Default constructor: creates a gum::Bijection without any association.

Member Function Documentation

◆ __copy() [1/2]

INLINE void gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy ( const HashTable< T1, T2 *, OtherAlloc > &  f2s)
inherited

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.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663
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/2]

INLINE void gum::BijectionImplementation< T1, T2, Alloc, Gen >::__copy ( const HashTable< T1, T2, OtherAlloc > &  f2s)
inherited

Definition at line 557 of file bijection_tpl.h.

558  {
559  // parse f2s and perform copies
560  for (auto iter = f2s.cbegin(); iter != f2s.cend(); ++iter) {
561  __firstToSecond.insert(iter.key(), iter.val());
562 
563  try {
564  __secondToFirst.insert(iter.val(), iter.key());
565  } catch (...) {
566  __firstToSecond.erase(iter.key());
567  throw;
568  }
569  }
570 
571  // note that __iter_end is actually a constant, whatever we add/remove
572  // to/from __firstToSecond. As a consequence, it need not be updated
573  // after __copy
574  }
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:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ begin()

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

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

◆ beginSafe()

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

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

248  {
249  return BijectionIteratorSafe< T1, T2 >{*this};
250  }

◆ capacity()

INLINE Size gum::BijectionImplementation< T1, T2, Alloc >::capacity ( ) const
noexceptinherited

Returns the number of hashtables slots used.

Returns
Returns the number of hashtables slots used.

Definition at line 451 of file bijection_tpl.h.

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

◆ cbegin()

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

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

Referenced by gum::BijectionIterator< int, int >::BijectionIterator().

◆ cbeginSafe()

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

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

Referenced by gum::BijectionIteratorSafe< NodeId, GUM_SCALAR >::BijectionIteratorSafe().

256  {
257  return BijectionIteratorSafe< T1, T2 >{*this};
258  }

◆ cend()

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

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

240  {
241  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
242  BijectionIteratorStaticEnd::__BijectionIterEnd));
243  }

◆ cendSafe()

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

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

273  {
274  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
275  BijectionIteratorStaticEnd::__BijectionIterEndSafe));
276  }

◆ clear()

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

Removes all the associations from the gum::Bijection.

Definition at line 156 of file bijection_tpl.h.

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

◆ emplace() [1/2]

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

Definition at line 408 of file bijection_tpl.h.

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

◆ emplace() [2/2]

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

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()

INLINE bool gum::BijectionImplementation< T1, T2, Alloc >::empty ( ) const
noexceptinherited

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

416  {
417  GUM_ASSERT(__firstToSecond.empty() == __secondToFirst.empty());
418  return __firstToSecond.empty();
419  }
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ end()

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

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

231  {
232  return *(reinterpret_cast< const BijectionIterator< T1, T2 >* >(
233  BijectionIteratorStaticEnd::__BijectionIterEnd));
234  }

◆ end4Statics()

const BijectionIterator< T1, T2 > & gum::BijectionImplementation< T1, T2, Alloc >::end4Statics ( )
staticinherited

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 >* >(
52  BijectionIteratorStaticEnd::end4Statics()));
53  }

◆ endSafe()

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

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

264  {
265  return *(reinterpret_cast< const BijectionIteratorSafe< T1, T2 >* >(
266  BijectionIteratorStaticEnd::__BijectionIterEndSafe));
267  }

◆ endSafe4Statics()

const BijectionIteratorSafe< T1, T2 > & gum::BijectionImplementation< T1, T2, Alloc >::endSafe4Statics ( )
staticinherited

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 >* >(
44  BijectionIteratorStaticEnd::endSafe4Statics()));
45  }

◆ eraseFirst()

INLINE void gum::BijectionImplementation< T1, T2, Alloc >::eraseFirst ( const T1 &  first)
inherited

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

Referenced by gum::prm::gspan::Pattern::__not_rec(), and gum::prm::gspan::Pattern::__rec().

432  {
433  try {
435  __firstToSecond.erase(first);
436  } catch (NotFound&) {}
437  }
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.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663

◆ eraseSecond()

INLINE void gum::BijectionImplementation< T1, T2, Alloc >::eraseSecond ( const T2 &  second)
inherited

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

442  {
443  try {
445  __secondToFirst.erase(second);
446  } catch (NotFound&) {}
447  }
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:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663

◆ existsFirst()

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

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

Referenced by gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::prm::StructuredInference< GUM_SCALAR >::__translatePotSet(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::copy(), gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::copy(), and gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::copyAndReassign().

295  {
296  return __firstToSecond.exists(first);
297  }
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:660

◆ existsSecond()

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

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

302  {
303  return __secondToFirst.exists(second);
304  }
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:663

◆ first()

INLINE const T1 & gum::BijectionImplementation< T1, T2, Alloc >::first ( const T2 &  second) const
inherited

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

Referenced by gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::prm::StructuredInference< GUM_SCALAR >::__translatePotSet(), and gum::MultiDimICIModel< GUM_SCALAR >::MultiDimICIModel().

281  {
282  return *(__secondToFirst[second]);
283  }
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:663

◆ firstWithDefault()

INLINE const T1 & gum::BijectionImplementation< T1, T2, Alloc >::firstWithDefault ( const T2 &  second,
const T1 &  default_val 
) const
inherited

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

372  {
373  try {
374  return first(second);
375  } catch (NotFound&) { return __insert(val, second)->first; }
376  }
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]

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

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

Referenced by gum::prm::gspan::Pattern::__expandCodeIsMinimal(), gum::prm::PRMSystem< double >::__groundPotential(), gum::prm::PRMClass< double >::__inheritClass(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::prm::GSpan< GUM_SCALAR >::__sortNodesAndEdges(), gum::prm::StructuredInference< GUM_SCALAR >::__translatePotSet(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::copy(), gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::copy(), gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::copyAndReassign(), and gum::IBayesNet< double >::operator==().

393  {
395  }
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]

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

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

400  {
401  __insert(std::move(first), std::move(second));
402  }
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.

◆ operator=() [1/4]

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
template<typename OtherAlloc >
INLINE Bijection< T1, T2, Alloc >& gum::Bijection< T1, T2, Alloc >::operator= ( const Bijection< T1, T2, OtherAlloc > &  toCopy)

Definition at line 1234 of file bijection_tpl.h.

1234  {
1235  Implementation::operator=(toCopy);
1236  return *this;
1237  }
BijectionImplementation< T1, T2, Alloc, Gen > & operator=(const BijectionImplementation< T1, T2, Alloc, Gen > &toCopy)
Copy operator.

◆ operator=() [2/4]

template<typename T1, typename T2, typename Alloc>
INLINE Bijection< T1, T2, Alloc > & gum::Bijection< T1, T2, Alloc >::operator= ( const Bijection< T1, T2, Alloc > &  toCopy)

Copy operator.

Parameters
toCopyThe gum::Bijection to copy.
Returns
Returns this gum::Bijection.

Definition at line 1225 of file bijection_tpl.h.

1225  {
1226  Implementation::operator=(toCopy);
1227  return *this;
1228  }
BijectionImplementation< T1, T2, Alloc, Gen > & operator=(const BijectionImplementation< T1, T2, Alloc, Gen > &toCopy)
Copy operator.

◆ operator=() [3/4]

template<typename T1, typename T2, typename Alloc = std::allocator< T2 >>
template<typename OtherAlloc >
Bijection< T1, T2, Alloc >& gum::Bijection< T1, T2, Alloc >::operator= ( const Bijection< T1, T2, OtherAlloc > &  toCopy)

Generalized copy operator.

Parameters
toCopyThe gum::Bijection to copy.
Template Parameters
OtherAllocThe gum::Bijection to copy allocator's type.

◆ operator=() [4/4]

template<typename T1, typename T2, typename Alloc>
INLINE Bijection< T1, T2, Alloc > & gum::Bijection< T1, T2, Alloc >::operator= ( Bijection< T1, T2, Alloc > &&  bij)

Move operator.

Parameters
bijThe gum::Bijection to move from.

Definition at line 1242 of file bijection_tpl.h.

1242  {
1243  Implementation::operator=(std::move(bij));
1244  return *this;
1245  }
BijectionImplementation< T1, T2, Alloc, Gen > & operator=(const BijectionImplementation< T1, T2, Alloc, Gen > &toCopy)
Copy operator.

◆ resize()

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

Manually resize the gum::Bijection.

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

Parameters
new_sizeThe gum::Bijection new size.

Definition at line 459 of file bijection_tpl.h.

459  {
460  __firstToSecond.resize(new_size);
461  __secondToFirst.resize(new_size);
462  }
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:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663

◆ resizePolicy()

INLINE bool gum::BijectionImplementation< T1, T2, Alloc >::resizePolicy ( ) const
noexceptinherited

Returns true if the resize policy is automatic.

See gum::HashTable::resizePolicy().

Returns
Returns true if the resize policy is automatic.

Definition at line 474 of file bijection_tpl.h.

475  {
476  return __firstToSecond.resizePolicy();
477  }
bool resizePolicy() const noexcept
Returns the current resizing policy.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
Definition: bijection.h:660

◆ second()

INLINE const T2 & gum::BijectionImplementation< T1, T2, Alloc >::second ( const T1 &  first) const
inherited

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

Referenced by gum::prm::PRMSystem< double >::__groundPotential(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::copy(), gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::copyAndReassign(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copyCpf(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::copyCpf(), gum::prm::copyPotential(), and gum::IBayesNet< double >::operator==().

288  {
289  return *(__firstToSecond[first]);
290  }
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:660

◆ secondWithDefault()

INLINE const T2 & gum::BijectionImplementation< T1, T2, Alloc >::secondWithDefault ( const T1 &  second,
const T2 &  default_val 
) const
inherited

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

383  {
384  try {
385  return second(first);
386  } catch (NotFound&) { return *(__insert(first, val)->second); }
387  }
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()

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

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

467  {
468  __firstToSecond.setResizePolicy(new_policy);
469  __secondToFirst.setResizePolicy(new_policy);
470  }
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:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663

◆ size()

INLINE Size gum::BijectionImplementation< T1, T2, Alloc >::size ( ) const
noexceptinherited

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

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

Definition at line 423 of file bijection_tpl.h.

424  {
425  GUM_ASSERT(__firstToSecond.size() == __secondToFirst.size());
426  return __firstToSecond.size();
427  }
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:660
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
Definition: bijection.h:663

◆ toString()

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

Returns a friendly representatin of the gum::Bijection.

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

Definition at line 481 of file bijection_tpl.h.

Referenced by gum::operator<<().

481  {
482  std::stringstream stream;
483  stream << "{ ";
484  bool first = true;
485 
486  for (iterator iter = begin(); iter != end(); ++iter) {
487  if (!first)
488  stream << ", ";
489  else
490  first = false;
491 
492  stream << '(' << iter.first() << " <-> " << iter.second() << ')';
493  }
494 
495  stream << " }";
496  return stream.str();
497  }
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.
const iterator & end() const noexcept
Returns the unsafe iterator at the end of the gum::Bijection.

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