37 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
38 const BijectionIteratorSafe< T1, T2 >&
45 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
53 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
54 template <
typename OtherAlloc >
58 for (
auto iter = f2s.
cbegin(); iter != f2s.
cend(); ++iter) {
60 &(__firstToSecond.insert(iter.key(),
nullptr));
64 val2 = &(__secondToFirst.insert(*(iter.val()),
nullptr));
66 __firstToSecond.erase(iter.key());
70 val1->second = &(
const_cast< T2&
>(val2->first));
71 val2->second = &(
const_cast< T1&
>(val1->first));
80 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
82 Size size,
bool resize_policy) :
88 __firstToSecond(size, resize_policy, false),
89 __secondToFirst(size, resize_policy, false) {
98 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
100 std::initializer_list< std::pair< T1, T2 > > list) :
101 __firstToSecond(
Size(list.size()) / 2, true, false),
102 __secondToFirst(
Size(list.size()) / 2, true, false) {
105 for (
const auto& elt : list) {
106 insert(elt.first, elt.second);
115 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
118 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
119 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
125 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
126 template <
typename OtherAlloc >
129 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
130 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
136 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
139 __firstToSecond(std::move(from.__firstToSecond)),
140 __secondToFirst(std::move(from.__secondToFirst)) {
145 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
152 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
154 __firstToSecond.
clear();
155 __secondToFirst.clear();
162 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
167 if (
this != &toCopy) {
179 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
180 template <
typename OtherAlloc >
194 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
201 __firstToSecond = std::move(from.__firstToSecond);
202 __secondToFirst = std::move(from.__secondToFirst);
212 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
219 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
226 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
230 BijectionIteratorStaticEnd::__BijectionIterEnd));
234 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
239 BijectionIteratorStaticEnd::__BijectionIterEnd));
243 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
250 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
258 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
263 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
267 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
272 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
276 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
279 return *(__secondToFirst[second]);
283 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
286 return *(__firstToSecond[first]);
290 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
292 const T1& first)
const {
293 return __firstToSecond.exists(first);
297 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
299 const T2& second)
const {
300 return __secondToFirst.exists(second);
304 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
310 if (existsFirst(first) || existsSecond(second)) {
312 "the bijection contains an element with the same couple (" 313 << first <<
"," << second <<
")");
318 &(__firstToSecond.insert(first,
nullptr));
322 val2 = &(__secondToFirst.insert(second,
nullptr));
324 __firstToSecond.erase(first);
328 val1->second = &(
const_cast< T2&
>(val2->first));
329 val2->second = &(
const_cast< T1&
>(val1->first));
335 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
341 if (existsFirst(first) || existsSecond(second)) {
343 "the bijection contains an element with the same couple (" 344 << first <<
"," << second <<
")");
349 &(__firstToSecond.insert(std::move(first),
nullptr));
353 val2 = &(__secondToFirst.insert(std::move(second),
nullptr));
355 __firstToSecond.erase(val1->first);
359 val1->second = &(
const_cast< T2&
>(val2->first));
360 val2->second = &(
const_cast< T1&
>(val1->first));
367 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
369 const T2& second,
const T1& val)
const {
371 return first(second);
372 }
catch (
NotFound&) {
return __insert(val, second)->first; }
377 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
380 const T1& first,
const T2& val)
const {
382 return second(first);
383 }
catch (
NotFound&) {
return *(__insert(first, val)->second); }
387 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
391 __insert(first, second);
395 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
398 __insert(std::move(first), std::move(second));
402 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
403 template <
typename... Args >
406 std::pair< T1, T2 > new_elt(std::forward< Args >(args)...);
407 __insert(std::move(new_elt.first), std::move(new_elt.second));
411 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
414 GUM_ASSERT(__firstToSecond.empty() == __secondToFirst.empty());
415 return __firstToSecond.
empty();
419 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
422 GUM_ASSERT(__firstToSecond.size() == __secondToFirst.size());
423 return __firstToSecond.
size();
427 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
431 __secondToFirst.erase(*__firstToSecond[first]);
432 __firstToSecond.erase(first);
437 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
441 __firstToSecond.erase(*__secondToFirst[second]);
442 __secondToFirst.erase(second);
447 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
454 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
457 __firstToSecond.
resize(new_size);
458 __secondToFirst.resize(new_size);
462 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
464 const bool new_policy) noexcept {
466 __secondToFirst.setResizePolicy(new_policy);
470 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
477 template <
typename T1,
typename T2,
typename Alloc,
bool Gen >
479 std::stringstream stream;
483 for (
iterator iter = begin(); iter != end(); ++iter) {
489 stream <<
'(' << iter.first() <<
" <-> " << iter.second() <<
')';
501 template <
typename T1,
typename T2,
typename Alloc >
505 BijectionIteratorStaticEnd::endSafe4Statics()));
509 template <
typename T1,
typename T2,
typename Alloc >
513 BijectionIteratorStaticEnd::end4Statics()));
517 template <
typename T1,
typename T2,
typename Alloc >
519 Size size,
bool resize_policy) :
525 __firstToSecond(size, resize_policy,
false),
526 __secondToFirst(size, resize_policy,
false) {
535 template <
typename T1,
typename T2,
typename Alloc >
536 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
537 std::initializer_list< std::pair< T1, T2 > > list) :
538 __firstToSecond(
Size(list.size()) / 2,
true,
false),
539 __secondToFirst(
Size(list.size()) / 2,
true,
false) {
542 for (
const auto& elt : list) {
543 insert(elt.first, elt.second);
552 template <
typename T1,
typename T2,
typename Alloc >
553 template <
typename OtherAlloc >
557 for (
auto iter = f2s.
cbegin(); iter != f2s.
cend(); ++iter) {
558 __firstToSecond.
insert(iter.key(), iter.val());
561 __secondToFirst.insert(iter.val(), iter.key());
563 __firstToSecond.erase(iter.key());
574 template <
typename T1,
typename T2,
typename Alloc >
575 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
577 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
578 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
584 template <
typename T1,
typename T2,
typename Alloc >
585 template <
typename OtherAlloc >
586 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
588 __firstToSecond(toCopy.__firstToSecond.capacity(), true, false),
589 __secondToFirst(toCopy.__secondToFirst.capacity(), true, false) {
595 template <
typename T1,
typename T2,
typename Alloc >
596 INLINE BijectionImplementation< T1, T2, Alloc, true >::BijectionImplementation(
598 __firstToSecond(std::move(toCopy.__firstToSecond)),
599 __secondToFirst(std::move(toCopy.__secondToFirst)) {
604 template <
typename T1,
typename T2,
typename Alloc >
611 template <
typename T1,
typename T2,
typename Alloc >
618 template <
typename T1,
typename T2,
typename Alloc >
625 template <
typename T1,
typename T2,
typename Alloc >
629 BijectionIteratorStaticEnd::__BijectionIterEnd));
633 template <
typename T1,
typename T2,
typename Alloc >
638 BijectionIteratorStaticEnd::__BijectionIterEnd));
642 template <
typename T1,
typename T2,
typename Alloc >
649 template <
typename T1,
typename T2,
typename Alloc >
657 template <
typename T1,
typename T2,
typename Alloc >
662 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
666 template <
typename T1,
typename T2,
typename Alloc >
671 BijectionIteratorStaticEnd::__BijectionIterEndSafe));
675 template <
typename T1,
typename T2,
typename Alloc >
677 __firstToSecond.
clear();
678 __secondToFirst.clear();
685 template <
typename T1,
typename T2,
typename Alloc >
690 if (
this != &toCopy) {
702 template <
typename T1,
typename T2,
typename Alloc >
703 template <
typename OtherAlloc >
717 template <
typename T1,
typename T2,
typename Alloc >
722 if (
this != &toCopy) {
735 template <
typename T1,
typename T2,
typename Alloc >
738 return __secondToFirst[second];
742 template <
typename T1,
typename T2,
typename Alloc >
745 return __firstToSecond[first];
749 template <
typename T1,
typename T2,
typename Alloc >
752 return __firstToSecond.exists(first);
756 template <
typename T1,
typename T2,
typename Alloc >
759 return __secondToFirst.exists(second);
763 template <
typename T1,
typename T2,
typename Alloc >
767 if (existsFirst(first) || existsSecond(second)) {
769 "the bijection contains an element with the same couple (" 770 << first <<
"," << second <<
")");
774 __firstToSecond.insert(first, second);
777 __secondToFirst.insert(second, first);
779 __firstToSecond.erase(first);
785 template <
typename T1,
typename T2,
typename Alloc >
788 __insert(first, second);
792 template <
typename T1,
typename T2,
typename Alloc >
793 template <
typename... Args >
796 std::pair< T1, T2 > new_elt(std::forward< Args >(args)...);
797 __insert(new_elt.first, new_elt.second);
802 template <
typename T1,
typename T2,
typename Alloc >
805 T2 second, T1 val)
const {
807 return first(second);
809 __insert(val, second);
816 template <
typename T1,
typename T2,
typename Alloc >
819 T1 first, T2 val)
const {
821 return second(first);
823 __insert(first, val);
829 template <
typename T1,
typename T2,
typename Alloc >
832 GUM_ASSERT(__firstToSecond.empty() == __secondToFirst.empty());
833 return __firstToSecond.
empty();
837 template <
typename T1,
typename T2,
typename Alloc >
840 GUM_ASSERT(__firstToSecond.size() == __secondToFirst.size());
841 return __firstToSecond.
size();
845 template <
typename T1,
typename T2,
typename Alloc >
849 __secondToFirst.erase(__firstToSecond[first]);
850 __firstToSecond.erase(first);
855 template <
typename T1,
typename T2,
typename Alloc >
859 __firstToSecond.erase(__secondToFirst[second]);
860 __secondToFirst.erase(second);
865 template <
typename T1,
typename T2,
typename Alloc >
872 template <
typename T1,
typename T2,
typename Alloc >
875 __firstToSecond.
resize(new_size);
876 __secondToFirst.resize(new_size);
880 template <
typename T1,
typename T2,
typename Alloc >
882 const bool new_policy) noexcept {
884 __secondToFirst.setResizePolicy(new_policy);
888 template <
typename T1,
typename T2,
typename Alloc >
895 template <
typename T1,
typename T2,
typename Alloc >
897 std::stringstream stream;
901 for (
iterator iter = begin(); iter != end(); ++iter) {
907 stream <<
'(' << iter.first() <<
" <-> " << iter.second() <<
')';
919 template <
typename T1,
typename T2 >
925 template <
typename T1,
typename T2 >
926 template <
typename Alloc,
bool Gen >
934 template <
typename T1,
typename T2 >
935 template <
typename Alloc >
938 __iter{bijection.__firstToSecond.
cbeginSafe()} {
943 template <
typename T1,
typename T2 >
951 template <
typename T1,
typename T2 >
954 __iter{std::move(from.__iter)} {
959 template <
typename T1,
typename T2 >
965 template <
typename T1,
typename T2 >
973 template <
typename T1,
typename T2 >
976 __iter = std::move(toCopy.__iter);
981 template <
typename T1,
typename T2 >
989 template <
typename T1,
typename T2 >
997 template <
typename T1,
typename T2 >
1004 template <
typename T1,
typename T2 >
1007 return __iter != toCompare.__iter;
1011 template <
typename T1,
typename T2 >
1014 return __iter == toCompare.__iter;
1018 template <
typename T1,
typename T2 >
1020 return __iter.key();
1024 template <
typename T1,
typename T2 >
1026 return Getter::op_second(__iter.val());
1037 template <
typename T1,
typename T2 >
1043 template <
typename T1,
typename T2 >
1044 template <
typename Alloc,
bool Gen >
1052 template <
typename T1,
typename T2 >
1053 template <
typename Alloc >
1056 __iter{bijection.__firstToSecond.
cbegin()} {
1061 template <
typename T1,
typename T2 >
1069 template <
typename T1,
typename T2 >
1072 __iter{std::move(from.__iter)} {
1077 template <
typename T1,
typename T2 >
1083 template <
typename T1,
typename T2 >
1091 template <
typename T1,
typename T2 >
1094 __iter = std::move(toCopy.__iter);
1099 template <
typename T1,
typename T2 >
1107 template <
typename T1,
typename T2 >
1115 template <
typename T1,
typename T2 >
1122 template <
typename T1,
typename T2 >
1125 return __iter != toCompare.__iter;
1129 template <
typename T1,
typename T2 >
1132 return __iter == toCompare.__iter;
1136 template <
typename T1,
typename T2 >
1138 return __iter.key();
1142 template <
typename T1,
typename T2 >
1144 return Getter::op_second(__iter.val());
1152 template <
typename T1,
typename T2,
typename Alloc >
1157 std::is_scalar< T1 >::value
1158 &&
std::is_scalar< T2 >::value >(size,
1164 template <
typename T1,
typename T2,
typename Alloc >
1166 std::initializer_list< std::pair< T1, T2 > > list) :
1170 std::is_scalar< T1 >::value
1171 &&
std::is_scalar< T2 >::value >(list) {
1176 template <
typename T1,
typename T2,
typename Alloc >
1182 std::is_scalar< T1 >::value
1183 &&
std::is_scalar< T2 >::value >(toCopy) {
1188 template <
typename T1,
typename T2,
typename Alloc >
1189 template <
typename OtherAlloc >
1195 std::is_scalar< T1 >::value
1196 &&
std::is_scalar< T2 >::value >(toCopy) {
1201 template <
typename T1,
typename T2,
typename Alloc >
1207 std::is_scalar< T1 >::value
1208 && std::is_scalar< T2 >::value >(
1214 template <
typename T1,
typename T2,
typename Alloc >
1220 template <
typename T1,
typename T2,
typename Alloc >
1223 Implementation::operator=(toCopy);
1228 template <
typename T1,
typename T2,
typename Alloc >
1229 template <
typename OtherAlloc >
1232 Implementation::operator=(toCopy);
1237 template <
typename T1,
typename T2,
typename Alloc >
1240 Implementation::operator=(std::move(bij));
1245 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.
gum is the global namespace for all aGrUM entities
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.
Set of pairs of elements with fast search for both elements.
A non scalar implementation of a Bijection.
#define GUM_ERROR(type, msg)