40 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
41 const BijectionIteratorSafe< T1, T2 >&
48 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
56 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
57 template <
typename OtherAlloc >
61 for (
auto iter = f2s.
cbegin(); iter != f2s.
cend(); ++iter) {
63 &(__firstToSecond.insert(iter.key(),
nullptr));
67 val2 = &(__secondToFirst.insert(*(iter.val()),
nullptr));
69 __firstToSecond.erase(iter.key());
73 val1->second = &(
const_cast< T2&
>(val2->first));
74 val2->second = &(
const_cast< T1&
>(val1->first));
83 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
85 Size size,
bool resize_policy) :
91 __firstToSecond(size, resize_policy, false),
92 __secondToFirst(size, resize_policy, false) {
101 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
103 std::initializer_list< std::pair< T1, T2 > > list) :
104 __firstToSecond(
Size(list.size()) / 2, true, false),
105 __secondToFirst(
Size(list.size()) / 2, true, false) {
108 for (
const auto& elt : list) {
109 insert(elt.first, elt.second);
118 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
121 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
122 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
128 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
129 template <
typename OtherAlloc >
132 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
133 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
139 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
142 __firstToSecond(std::move(from.__firstToSecond)),
143 __secondToFirst(std::move(from.__secondToFirst)) {
148 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
155 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
157 __firstToSecond.
clear();
158 __secondToFirst.clear();
165 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
170 if (
this != &toCopy) {
182 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
183 template <
typename OtherAlloc >
197 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
204 __firstToSecond = std::move(from.__firstToSecond);
205 __secondToFirst = std::move(from.__secondToFirst);
215 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
222 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
229 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
233 BijectionIteratorStaticEnd::__BijectionIterEnd));
237 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
242 BijectionIteratorStaticEnd::__BijectionIterEnd));
246 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
253 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
261 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
266 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
270 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
275 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
279 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
282 return *(__secondToFirst[second]);
286 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
289 return *(__firstToSecond[first]);
293 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
295 const T1& first)
const {
296 return __firstToSecond.exists(first);
300 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
302 const T2& second)
const {
303 return __secondToFirst.exists(second);
307 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
313 if (existsFirst(first) || existsSecond(second)) {
315 "the bijection contains an element with the same couple (" 316 << first <<
"," << second <<
")");
321 &(__firstToSecond.insert(first,
nullptr));
325 val2 = &(__secondToFirst.insert(second,
nullptr));
327 __firstToSecond.erase(first);
331 val1->second = &(
const_cast< T2&
>(val2->first));
332 val2->second = &(
const_cast< T1&
>(val1->first));
338 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
344 if (existsFirst(first) || existsSecond(second)) {
346 "the bijection contains an element with the same couple (" 347 << first <<
"," << second <<
")");
352 &(__firstToSecond.insert(std::move(first),
nullptr));
356 val2 = &(__secondToFirst.insert(std::move(second),
nullptr));
358 __firstToSecond.erase(val1->first);
362 val1->second = &(
const_cast< T2&
>(val2->first));
363 val2->second = &(
const_cast< T1&
>(val1->first));
370 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
372 const T2& second,
const T1& val)
const {
374 return first(second);
375 }
catch (
NotFound&) {
return __insert(val, second)->first; }
380 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
383 const T1& first,
const T2& val)
const {
385 return second(first);
386 }
catch (
NotFound&) {
return *(__insert(first, val)->second); }
390 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
394 __insert(first, second);
398 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
401 __insert(std::move(first), std::move(second));
405 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
406 template <
typename... Args >
409 std::pair< T1, T2 > new_elt(std::forward< Args >(args)...);
410 __insert(std::move(new_elt.first), std::move(new_elt.second));
414 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
417 GUM_ASSERT(__firstToSecond.empty() == __secondToFirst.empty());
418 return __firstToSecond.
empty();
422 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
425 GUM_ASSERT(__firstToSecond.size() == __secondToFirst.size());
426 return __firstToSecond.
size();
430 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
434 __secondToFirst.erase(*__firstToSecond[first]);
435 __firstToSecond.erase(first);
440 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
444 __firstToSecond.erase(*__secondToFirst[second]);
445 __secondToFirst.erase(second);
450 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
457 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
460 __firstToSecond.
resize(new_size);
461 __secondToFirst.resize(new_size);
465 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
467 const bool new_policy) noexcept {
469 __secondToFirst.setResizePolicy(new_policy);
473 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
480 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
482 std::stringstream stream;
486 for (
iterator iter = begin(); iter != end(); ++iter) {
492 stream <<
'(' << iter.first() <<
" <-> " << iter.second() <<
')';
504 template <
typename T1,
typename T2,
typename Alloc >
508 BijectionIteratorStaticEnd::endSafe4Statics()));
512 template <
typename T1,
typename T2,
typename Alloc >
516 BijectionIteratorStaticEnd::end4Statics()));
520 template <
typename T1,
typename T2,
typename Alloc >
522 Size size,
bool resize_policy) :
528 __firstToSecond(size, resize_policy,
false),
529 __secondToFirst(size, resize_policy,
false) {
538 template <
typename T1,
typename T2,
typename Alloc >
539 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
540 std::initializer_list< std::pair< T1, T2 > > list) :
541 __firstToSecond(
Size(list.size()) / 2,
true,
false),
542 __secondToFirst(
Size(list.size()) / 2,
true,
false) {
545 for (
const auto& elt : list) {
546 insert(elt.first, elt.second);
555 template <
typename T1,
typename T2,
typename Alloc >
556 template <
typename OtherAlloc >
560 for (
auto iter = f2s.
cbegin(); iter != f2s.
cend(); ++iter) {
561 __firstToSecond.
insert(iter.key(), iter.val());
564 __secondToFirst.insert(iter.val(), iter.key());
566 __firstToSecond.erase(iter.key());
577 template <
typename T1,
typename T2,
typename Alloc >
578 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
580 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
581 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
587 template <
typename T1,
typename T2,
typename Alloc >
588 template <
typename OtherAlloc >
589 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
591 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
592 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
598 template <
typename T1,
typename T2,
typename Alloc >
599 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
601 __firstToSecond(std::move(toCopy.__firstToSecond)),
602 __secondToFirst(std::move(toCopy.__secondToFirst)) {
607 template <
typename T1,
typename T2,
typename Alloc >
614 template <
typename T1,
typename T2,
typename Alloc >
621 template <
typename T1,
typename T2,
typename Alloc >
628 template <
typename T1,
typename T2,
typename Alloc >
632 BijectionIteratorStaticEnd::__BijectionIterEnd));
636 template <
typename T1,
typename T2,
typename Alloc >
641 BijectionIteratorStaticEnd::__BijectionIterEnd));
645 template <
typename T1,
typename T2,
typename Alloc >
652 template <
typename T1,
typename T2,
typename Alloc >
660 template <
typename T1,
typename T2,
typename Alloc >
665 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
669 template <
typename T1,
typename T2,
typename Alloc >
674 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
678 template <
typename T1,
typename T2,
typename Alloc >
680 __firstToSecond.
clear();
681 __secondToFirst.clear();
688 template <
typename T1,
typename T2,
typename Alloc >
693 if (
this != &toCopy) {
705 template <
typename T1,
typename T2,
typename Alloc >
706 template <
typename OtherAlloc >
720 template <
typename T1,
typename T2,
typename Alloc >
725 if (
this != &toCopy) {
738 template <
typename T1,
typename T2,
typename Alloc >
741 return __secondToFirst[second];
745 template <
typename T1,
typename T2,
typename Alloc >
748 return __firstToSecond[first];
752 template <
typename T1,
typename T2,
typename Alloc >
755 return __firstToSecond.exists(first);
759 template <
typename T1,
typename T2,
typename Alloc >
762 return __secondToFirst.exists(second);
766 template <
typename T1,
typename T2,
typename Alloc >
770 if (existsFirst(first) || existsSecond(second)) {
772 "the bijection contains an element with the same couple (" 773 << first <<
"," << second <<
")");
777 __firstToSecond.insert(first, second);
780 __secondToFirst.insert(second, first);
782 __firstToSecond.erase(first);
788 template <
typename T1,
typename T2,
typename Alloc >
791 __insert(first, second);
795 template <
typename T1,
typename T2,
typename Alloc >
796 template <
typename... Args >
799 std::pair< T1, T2 > new_elt(std::forward< Args >(args)...);
800 __insert(new_elt.first, new_elt.second);
805 template <
typename T1,
typename T2,
typename Alloc >
808 T2 second, T1 val)
const {
810 return first(second);
812 __insert(val, second);
819 template <
typename T1,
typename T2,
typename Alloc >
822 T1 first, T2 val)
const {
824 return second(first);
826 __insert(first, val);
832 template <
typename T1,
typename T2,
typename Alloc >
835 GUM_ASSERT(__firstToSecond.empty() == __secondToFirst.empty());
836 return __firstToSecond.
empty();
840 template <
typename T1,
typename T2,
typename Alloc >
843 GUM_ASSERT(__firstToSecond.size() == __secondToFirst.size());
844 return __firstToSecond.
size();
848 template <
typename T1,
typename T2,
typename Alloc >
852 __secondToFirst.erase(__firstToSecond[first]);
853 __firstToSecond.erase(first);
858 template <
typename T1,
typename T2,
typename Alloc >
862 __firstToSecond.erase(__secondToFirst[second]);
863 __secondToFirst.erase(second);
868 template <
typename T1,
typename T2,
typename Alloc >
875 template <
typename T1,
typename T2,
typename Alloc >
878 __firstToSecond.
resize(new_size);
879 __secondToFirst.resize(new_size);
883 template <
typename T1,
typename T2,
typename Alloc >
885 const bool new_policy) noexcept {
887 __secondToFirst.setResizePolicy(new_policy);
891 template <
typename T1,
typename T2,
typename Alloc >
898 template <
typename T1,
typename T2,
typename Alloc >
900 std::stringstream stream;
904 for (
iterator iter = begin(); iter != end(); ++iter) {
910 stream <<
'(' << iter.first() <<
" <-> " << iter.second() <<
')';
922 template <
typename T1,
typename T2 >
928 template <
typename T1,
typename T2 >
929 template <
typename Alloc,
bool Gen >
937 template <
typename T1,
typename T2 >
938 template <
typename Alloc >
941 __iter{bijection.__firstToSecond.
cbeginSafe()} {
946 template <
typename T1,
typename T2 >
954 template <
typename T1,
typename T2 >
957 __iter{std::move(from.__iter)} {
962 template <
typename T1,
typename T2 >
968 template <
typename T1,
typename T2 >
976 template <
typename T1,
typename T2 >
979 __iter = std::move(toCopy.__iter);
984 template <
typename T1,
typename T2 >
992 template <
typename T1,
typename T2 >
1000 template <
typename T1,
typename T2 >
1007 template <
typename T1,
typename T2 >
1010 return __iter != toCompare.__iter;
1014 template <
typename T1,
typename T2 >
1017 return __iter == toCompare.__iter;
1021 template <
typename T1,
typename T2 >
1023 return __iter.key();
1027 template <
typename T1,
typename T2 >
1029 return Getter::op_second(__iter.val());
1040 template <
typename T1,
typename T2 >
1046 template <
typename T1,
typename T2 >
1047 template <
typename Alloc,
bool Gen >
1055 template <
typename T1,
typename T2 >
1056 template <
typename Alloc >
1059 __iter{bijection.__firstToSecond.
cbegin()} {
1064 template <
typename T1,
typename T2 >
1072 template <
typename T1,
typename T2 >
1075 __iter{std::move(from.__iter)} {
1080 template <
typename T1,
typename T2 >
1086 template <
typename T1,
typename T2 >
1094 template <
typename T1,
typename T2 >
1097 __iter = std::move(toCopy.__iter);
1102 template <
typename T1,
typename T2 >
1110 template <
typename T1,
typename T2 >
1118 template <
typename T1,
typename T2 >
1125 template <
typename T1,
typename T2 >
1128 return __iter != toCompare.__iter;
1132 template <
typename T1,
typename T2 >
1135 return __iter == toCompare.__iter;
1139 template <
typename T1,
typename T2 >
1141 return __iter.key();
1145 template <
typename T1,
typename T2 >
1147 return Getter::op_second(__iter.val());
1155 template <
typename T1,
typename T2,
typename Alloc >
1160 std::is_scalar< T1 >::value
1161 &&
std::is_scalar< T2 >::value >(size,
1167 template <
typename T1,
typename T2,
typename Alloc >
1169 std::initializer_list< std::pair< T1, T2 > > list) :
1173 std::is_scalar< T1 >::value
1174 &&
std::is_scalar< T2 >::value >(list) {
1179 template <
typename T1,
typename T2,
typename Alloc >
1185 std::is_scalar< T1 >::value
1186 &&
std::is_scalar< T2 >::value >(toCopy) {
1191 template <
typename T1,
typename T2,
typename Alloc >
1192 template <
typename OtherAlloc >
1198 std::is_scalar< T1 >::value
1199 &&
std::is_scalar< T2 >::value >(toCopy) {
1204 template <
typename T1,
typename T2,
typename Alloc >
1210 std::is_scalar< T1 >::value
1211 && std::is_scalar< T2 >::value >(
1217 template <
typename T1,
typename T2,
typename Alloc >
1223 template <
typename T1,
typename T2,
typename Alloc >
1226 Implementation::operator=(toCopy);
1231 template <
typename T1,
typename T2,
typename Alloc >
1232 template <
typename OtherAlloc >
1235 Implementation::operator=(toCopy);
1240 template <
typename T1,
typename T2,
typename Alloc >
1243 Implementation::operator=(std::move(bij));
1248 template <
typename T1,
typename T2,
typename Alloc >
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
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.
static const BijectionIterator< int, int > * end4Statics()
Creates (if needed) and returns the iterator __BijectionIterEnd.
Safe iterators for bijectionIterator.
HashIter __iter
The hashTable iterator that actually does all the job.
const_iterator cbegin() const
Returns the constant unsafe iterator at the beginning of the gum::Bjection.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
static const iterator_safe & endSafe4Statics()
Returns the safe end iterator for other classes' statics.
void resize(Size new_size)
Manually resize the gum::Bijection.
The class for generic Hash Tables.
static const BijectionIteratorSafe< int, int > * endSafe4Statics()
Creates (if needed) and returns the iterator __BijectionIterEndSafe.
Size capacity() const noexcept
Returns the number of hashtables slots used.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
bool empty() const noexcept
Returns true if the gum::Bijection doesn't contain any association.
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
HashTable12 __firstToSecond
The gum::HashTable associating T2 objects to T1 objects.
LpExpr operator+(LpExpr &&lhs, const T2 &rhs)
Overload of operator + between anything ( a scalar, a variable or an expression ) and anything except...
Unsafe iterators for bijection.
bool operator==(const TiXmlString &a, const TiXmlString &b)
Set of pairs of elements with fast search for both elements.
Size size() const noexcept
Returns the number of associations stored within the gum::Bijection.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
std::pair< const Idx, const std::string ** > value_type
bool operator!=(const TiXmlString &a, const TiXmlString &b)
HashIter __iter
The hashTable iterator that actually does all the job.
std::string toString() const
Returns a friendly representatin of the gum::Bijection.
bool resizePolicy() const noexcept
Returns true if the resize policy is automatic.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
static const iterator & end4Statics()
Returns the unsafe end iterator for other classes' statics.
HashTable21 __secondToFirst
The gum::HashTable associating T1 objects to T2 objects.
const_iterator_safe cbeginSafe() const
Returns the constant safe iterator at the begining of the gum::Bijection.
void setResizePolicy(const bool new_policy) noexcept
Change the gum::Bijection resizing policy.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
A non scalar implementation of a Bijection.
#define GUM_ERROR(type, msg)