34 template <
typename Key,
typename Alloc,
bool Gen >
40 template <
typename Key,
typename Alloc,
bool Gen >
46 template <
typename Key,
typename Alloc >
52 template <
typename Key,
typename Alloc >
62 template <
typename Key >
63 template <
typename Alloc,
bool Gen >
66 __seq{
reinterpret_cast< 68 std::allocator< Key >,
69 std::is_scalar< Key >::value
>* >(&seq)} {
72 if (pos > __seq->size())
73 __iterator = __seq->size();
79 template <
typename Key >
80 template <
typename Alloc >
83 __seq{
reinterpret_cast< 85 std::allocator< Key >,
86 std::is_scalar< Key >::value
>* >(&seq)} {
89 if (pos > __seq->size())
90 __iterator = __seq->size();
96 template <
typename Key >
99 __iterator{source.__iterator},
100 __seq{source.__seq} {
105 template <
typename Key >
108 __iterator{source.__iterator},
109 __seq{source.__seq} {
114 template <
typename Key >
120 template <
typename Key >
123 __iterator = source.__iterator;
124 __seq = source.__seq;
129 template <
typename Key >
132 __iterator = source.__iterator;
133 __seq = source.__seq;
138 template <
typename Key >
141 if (__iterator < __seq->size())
144 __iterator = __seq->size();
150 template <
typename Key >
153 if (__iterator != std::numeric_limits< Idx >::max()) --__iterator;
159 template <
typename Key >
162 if (__iterator == std::numeric_limits< Idx >::max())
return *
this;
164 if (__iterator > __seq->size()) __iterator = __seq->size();
170 template <
typename Key >
173 if (__iterator == std::numeric_limits< Idx >::max())
return *
this;
175 if (__iterator > __seq->size()) __iterator = std::numeric_limits< Idx >::max();
181 template <
typename Key >
188 template <
typename Key >
195 template <
typename Key >
201 if ((__iterator != source.__iterator) || (__seq != source.__seq))
return false;
207 template <
typename Key >
214 template <
typename Key >
216 if (__iterator >= __seq->size()) {
224 template <
typename Key >
226 if (pos > __seq->size())
227 __iterator = __seq->size();
233 template <
typename Key >
235 __iterator = std::numeric_limits< Idx >::max();
239 template <
typename Key >
241 __iterator = __seq->size();
245 template <
typename Key >
247 return Getter::op_star(__seq->__v[pos()]);
251 template <
typename Key >
253 return Getter::op_arrow(__seq->__v[pos()]);
261 template <
typename Key,
typename Alloc,
bool Gen >
263 __end_safe.__setAtEnd();
267 template <
typename Key,
typename Alloc,
bool Gen >
275 template <
typename Key,
typename Alloc,
bool Gen >
276 template <
typename OtherAlloc >
281 for (
Size i = 0; i < aSeq.
size(); ++i) {
282 Key& new_key =
const_cast< Key&
>(__h.insert(*(aSeq.
__v[i]), i).first);
283 __v.push_back(&new_key);
290 template <
typename Key,
typename Alloc,
bool Gen >
294 __end_safe{*
this}, __rend_safe{*
this} {
297 __rend_safe.__setAtRend();
302 template <
typename Key,
typename Alloc,
bool Gen >
304 std::initializer_list< Key > list) :
308 __rend_safe.__setAtRend();
309 for (
const auto& elt : list) {
315 template <
typename Key,
typename Alloc,
bool Gen >
322 __rend_safe.__setAtRend();
327 template <
typename Key,
typename Alloc,
bool Gen >
328 template <
typename OtherAlloc >
335 __rend_safe.__setAtRend();
340 template <
typename Key,
typename Alloc,
bool Gen >
343 __h(
std::move(aSeq.__h)),
344 __v(
std::move(aSeq.__v)), __end_safe{*
this}, __rend_safe{*
this} {
347 __rend_safe.__setAtRend();
352 template <
typename Key,
typename Alloc,
bool Gen >
359 template <
typename Key,
typename Alloc,
bool Gen >
372 template <
typename Key,
typename Alloc,
bool Gen >
373 template <
typename OtherAlloc >
382 template <
typename Key,
typename Alloc,
bool Gen >
388 __h = std::move(aSeq.__h);
389 __v = std::move(aSeq.__v);
397 template <
typename Key,
typename Alloc,
bool Gen >
404 template <
typename Key,
typename Alloc,
bool Gen >
407 Key& new_key =
const_cast< Key&
>(__h.insert(k, __h.size()).first);
408 __v.push_back(&new_key);
413 template <
typename Key,
typename Alloc,
bool Gen >
416 Key& new_key =
const_cast< Key&
>(__h.insert(std::move(k), __h.size()).first);
417 __v.push_back(&new_key);
422 template <
typename Key,
typename Alloc,
bool Gen >
423 template <
typename... Args >
425 Key key(std::forward< Args >(args)...);
427 const_cast< Key&
>(__h.insert(std::move(key), __h.size()).first);
428 __v.push_back(&new_key);
433 template <
typename Key,
typename Alloc,
bool Gen >
441 template <
typename Key,
typename Alloc,
bool Gen >
444 insert(std::move(k));
449 template <
typename Key,
typename Alloc,
bool Gen >
459 __v.
erase(__v.begin() + pos);
460 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
469 template <
typename Key,
typename Alloc,
bool Gen >
472 if (iter.
pos() >= size())
return;
477 __v.erase(__v.begin() + pos);
479 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
488 template <
typename Key,
typename Alloc,
bool Gen >
496 template <
typename Key,
typename Alloc,
bool Gen >
498 if (i >= __h.size()) {
500 "index " << i <<
" for a sequence of size" << __h.size());
507 template <
typename Key,
typename Alloc,
bool Gen >
514 template <
typename Key,
typename Alloc,
bool Gen >
520 template <
typename Key,
typename Alloc,
bool Gen >
526 Key& new_key =
const_cast< Key&
>(__h.insert(newKey, i).first);
527 __h.erase(*(__v[i]));
532 template <
typename Key,
typename Alloc,
bool Gen >
537 Key& new_key =
const_cast< Key&
>(__h.insert(std::move(newKey), i).first);
538 __h.erase(*(__v[i]));
543 template <
typename Key,
typename Alloc,
bool Gen >
547 Key& ki =
const_cast< Key&
>(atPos(i));
548 Key& kj =
const_cast< Key&
>(atPos(j));
558 template <
typename Key,
typename Alloc,
bool Gen >
564 template <
typename Key,
typename Alloc,
bool Gen >
566 return atPos(size() - 1);
570 template <
typename Key,
typename Alloc,
bool Gen >
572 std::stringstream stream;
576 stream << 0 <<
":" << *__v[0];
578 for (
Idx i = 1; i < __h.size(); ++i) {
579 stream <<
" - " << i <<
":" << *__v[i];
585 std::string res = stream.str();
590 template <
typename Key,
typename Alloc,
bool Gen >
591 template <
typename OtherAlloc >
594 if (size() != k.
size())
597 for (
Idx i = 0; i < size(); ++i)
598 if (*__v[i] != *(k.
__v[i]))
return false;
605 template <
typename Key,
typename Alloc,
bool Gen >
606 template <
typename OtherAlloc >
613 template <
typename Key,
typename Alloc,
bool Gen >
622 template <
typename Key,
typename Alloc,
bool Gen >
629 template <
typename Key,
typename Alloc,
bool Gen >
636 template <
typename Key,
typename Alloc,
bool Gen >
645 template <
typename Key,
typename Alloc,
bool Gen >
652 template <
typename Key,
typename Alloc,
bool Gen >
653 INLINE SequenceIterator< Key >
655 return SequenceIterator< Key >{*
this};
659 template <
typename Key,
typename Alloc,
bool Gen >
660 INLINE
const SequenceIterator< Key >&
666 template <
typename Key,
typename Alloc,
bool Gen >
667 INLINE SequenceIterator< Key >
669 SequenceIterator< Key > it{*
this};
670 it.__setPos(size() - 1);
675 template <
typename Key,
typename Alloc,
bool Gen >
676 INLINE
const SequenceIterator< Key >&
682 template <
typename Key,
typename Alloc,
bool Gen >
684 if (new_size < __h.size())
return;
687 __v.reserve(new_size);
695 template <
typename Key,
typename Alloc >
697 __end_safe.__setAtEnd();
701 template <
typename Key,
typename Alloc >
709 template <
typename Key,
typename Alloc >
710 template <
typename OtherAlloc >
715 for (
Size i = 0; i < aSeq.
size(); ++i) {
716 __h.insert(aSeq.
__v[i], i);
717 __v.push_back(aSeq.
__v[i]);
724 template <
typename Key,
typename Alloc >
728 __end_safe{*
this}, __rend_safe{*
this} {
731 __rend_safe.__setAtRend();
732 __end_safe.__setAtEnd();
736 template <
typename Key,
typename Alloc >
737 INLINE SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
738 std::initializer_list< Key > list) :
742 __rend_safe.__setAtRend();
743 for (
const auto& elt : list) {
749 template <
typename Key,
typename Alloc >
750 SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
753 __v(aSeq.__v), __end_safe{*
this}, __rend_safe{*
this} {
756 __rend_safe.__setAtRend();
757 __end_safe.__setAtEnd();
761 template <
typename Key,
typename Alloc >
762 template <
typename OtherAlloc >
763 SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
765 __h(aSeq.size() / 2),
766 __end_safe{*
this}, __rend_safe{*
this} {
769 __rend_safe.__setAtRend();
774 template <
typename Key,
typename Alloc >
775 INLINE SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
777 __h(
std::move(aSeq.__h)),
778 __v(
std::move(aSeq.__v)), __end_safe{*
this}, __rend_safe{*
this} {
781 __rend_safe.__setAtRend();
782 __end_safe.__setAtEnd();
786 template <
typename Key,
typename Alloc >
792 template <
typename Key,
typename Alloc >
797 if (&aSeq !=
this) { __copy(aSeq); }
803 template <
typename Key,
typename Alloc >
804 template <
typename OtherAlloc >
813 template <
typename Key,
typename Alloc >
819 __h = std::move(aSeq.
__h);
820 __v = std::move(aSeq.
__v);
828 template <
typename Key,
typename Alloc >
834 template <
typename Key,
typename Alloc >
837 __h.
insert(k, __h.size());
843 template <
typename Key,
typename Alloc >
844 template <
typename... Args >
846 Key new_key(std::forward< Args >(args)...);
847 __h.insert(new_key, __h.size());
848 __v.push_back(new_key);
853 template <
typename Key,
typename Alloc >
861 template <
typename Key,
typename Alloc >
871 __v.
erase(__v.begin() + pos);
872 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
881 template <
typename Key,
typename Alloc >
884 if (iter.
pos() >= size())
return;
889 __v.erase(__v.begin() + pos);
891 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
900 template <
typename Key,
typename Alloc >
908 template <
typename Key,
typename Alloc >
911 if (i >= __h.size()) {
919 template <
typename Key,
typename Alloc >
926 template <
typename Key,
typename Alloc >
932 template <
typename Key,
typename Alloc >
937 __h.insert(newKey, i);
943 template <
typename Key,
typename Alloc >
958 template <
typename Key,
typename Alloc >
964 template <
typename Key,
typename Alloc >
966 return atPos(size() - 1);
970 template <
typename Key,
typename Alloc >
972 std::stringstream stream;
976 stream << 0 <<
":" << __v[0];
978 for (
Idx i = 1; i < __h.size(); ++i) {
979 stream <<
" - " << i <<
":" << __v[i];
985 std::string res = stream.str();
990 template <
typename Key,
typename Alloc >
991 template <
typename OtherAlloc >
994 if (size() != k.
size())
997 for (
Idx i = 0; i < size(); ++i)
998 if (__v[i] != k.
__v[i])
return false;
1005 template <
typename Key,
typename Alloc >
1006 template <
typename OtherAlloc >
1013 template <
typename Key,
typename Alloc >
1014 INLINE std::ostream&
1022 template <
typename Key,
typename Alloc >
1029 template <
typename Key,
typename Alloc >
1036 template <
typename Key,
typename Alloc >
1045 template <
typename Key,
typename Alloc >
1052 template <
typename Key,
typename Alloc >
1053 INLINE SequenceIterator< Key >
1055 return SequenceIterator< Key >{*
this};
1059 template <
typename Key,
typename Alloc >
1060 INLINE
const SequenceIterator< Key >&
1066 template <
typename Key,
typename Alloc >
1067 INLINE SequenceIterator< Key >
1069 SequenceIterator< Key > it{*
this};
1070 it.__setPos(size() - 1);
1075 template <
typename Key,
typename Alloc >
1076 INLINE
const SequenceIterator< Key >&
1082 template <
typename Key,
typename Alloc >
1084 if (new_size < __h.size())
return;
1087 __v.reserve(new_size);
1095 template <
typename Key,
typename Alloc >
1104 template <
typename Key,
typename Alloc >
1112 template <
typename Key,
typename Alloc >
1120 template <
typename Key,
typename Alloc >
1121 template <
typename OtherAlloc >
1130 template <
typename Key,
typename Alloc >
1139 template <
typename Key,
typename Alloc >
1146 template <
typename Key,
typename Alloc >
1149 Implementation::operator=(aSeq);
1154 template <
typename Key,
typename Alloc >
1155 template <
typename OtherAlloc >
1158 Implementation::operator=(aSeq);
1163 template <
typename Key,
typename Alloc >
1166 Implementation::operator=(std::move(aSeq));
1171 template <
typename Key,
typename Alloc >
1172 template <
typename OtherAlloc >
1177 for (
iterator iter = this->begin(); iter != this->end(); ++iter) {
1178 if (!seq.
exists(*iter)) res << *iter;
1185 template <
typename Key,
typename Alloc >
Safe iterators for Sequence.
SequenceIteratorSafe< Key > operator-(Size nb) noexcept
Returns a new iterator.
bool operator!=(const SequenceIteratorSafe< Key > &source) const noexcept
Checks whether two iterators are pointing to different elements.
SequenceIteratorSafe< Key > & operator=(const SequenceIteratorSafe< Key > &source) noexcept
Copy operator.
SequenceIterator< NodeId > iterator
void clear()
Clear the sequence.
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
friend class SequenceImplementation
Friends to speed up access.
void resize(Size new_size)
Modifies the size of the internal structures of the sequence.
Size size() const noexcept
Returns the size of the sequence.
Idx pos() const
Returns the position of the iterator in the sequence.
The generic class for storing (ordered) sequences of objects.
~SequenceIteratorSafe() noexcept
Class destructor.
SequenceIteratorSafe< Key > & operator++() noexcept
Point the iterator to the next value in the sequence.
SequenceIteratorSafe< Key > & operator--() noexcept
Point the iterator to the preceding value in the sequence.
bool empty() const noexcept
Return true if empty.
const Key * operator->() const
Returns the value pointed to by the iterator (works only for non-scalars).
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
std::string toString() const
Displays the content of the sequence.
HashTable< Key, Idx, Alloc > __h
Keep track of the position of the element in v (for fast retrieval).
gum is the global namespace for all aGrUM entities
void __setAtEnd() noexcept
The iterator points to the end (which is pos size()-1).
The internal class for storing (ordered) sequences of objects.
std::istream & operator>>(std::istream &in, TiXmlNode &base)
void __update_end() noexcept
A method to update the end iterator after changes in the sequence.
Representation of a setA Set is a structure that contains arbitrary elements.
bool operator==(const SequenceIteratorSafe< Key > &source) const noexcept
Checks whether two iterators are pointing to the same elements.
bool exists(const Key &k) const
Check the existence of k in the sequence.
bool operator==(const TiXmlString &a, const TiXmlString &b)
SequenceIteratorSafe< Key > & operator-=(Size nb) noexcept
Makes the iterator point to i elements further in the sequence.
void erase(const Key &k)
Remove an element from the sequence.
void __setAtRend() noexcept
The iterator points to rend.
const Key & operator*() const
Returns the value pointed to by the iterator.
bool operator!=(const TiXmlString &a, const TiXmlString &b)
void __copy(const SequenceImplementation< Key, OtherAlloc, Gen > &aSeq)
Clears the current sequence and fill it with copies the element of aSeq.
Size Idx
Type for indexes.
INLINE std::ostream & operator<<(std::ostream &stream, const Sequence< Key, Alloc > &seq)
A << operator for displaying the content of the Sequence.
std::vector< Key *, typename Alloc::template rebind< Key *>::other > __v
The set of the elements stored into the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
SequenceIteratorSafe(const SequenceImplementation< Key, Alloc, Gen > &seq, Idx pos=0) noexcept
Constructor, always give a valid iterator (even if pos too large).
SequenceIteratorSafe< Key > operator+(Size nb) noexcept
Returns a new iterator.
SequenceIteratorSafe< Key > & operator+=(Size nb) noexcept
Makes the iterator point to i elements further in the sequence.
void __setPos(Idx pos) noexcept
The iterator points to the posth element (0 = beginning of the sequence).
#define GUM_ERROR(type, msg)
void insert(const Key &k)
Insert an element at the end of the sequence.