37 template <
typename Key,
typename Alloc,
bool Gen >
43 template <
typename Key,
typename Alloc,
bool Gen >
49 template <
typename Key,
typename Alloc >
55 template <
typename Key,
typename Alloc >
65 template <
typename Key >
66 template <
typename Alloc,
bool Gen >
69 __seq{
reinterpret_cast< 71 std::allocator< Key >,
72 std::is_scalar< Key >::value
>* >(&seq)} {
75 if (pos > __seq->size())
76 __iterator = __seq->size();
82 template <
typename Key >
83 template <
typename Alloc >
86 __seq{
reinterpret_cast< 88 std::allocator< Key >,
89 std::is_scalar< Key >::value
>* >(&seq)} {
92 if (pos > __seq->size())
93 __iterator = __seq->size();
99 template <
typename Key >
102 __iterator{source.__iterator},
103 __seq{source.__seq} {
108 template <
typename Key >
111 __iterator{source.__iterator},
112 __seq{source.__seq} {
117 template <
typename Key >
123 template <
typename Key >
126 __iterator = source.__iterator;
127 __seq = source.__seq;
132 template <
typename Key >
135 __iterator = source.__iterator;
136 __seq = source.__seq;
141 template <
typename Key >
144 if (__iterator < __seq->size())
147 __iterator = __seq->size();
153 template <
typename Key >
156 if (__iterator != std::numeric_limits< Idx >::max()) --__iterator;
162 template <
typename Key >
165 if (__iterator == std::numeric_limits< Idx >::max())
return *
this;
167 if (__iterator > __seq->size()) __iterator = __seq->size();
173 template <
typename Key >
176 if (__iterator == std::numeric_limits< Idx >::max())
return *
this;
178 if (__iterator > __seq->size()) __iterator = std::numeric_limits< Idx >::max();
184 template <
typename Key >
191 template <
typename Key >
198 template <
typename Key >
204 if ((__iterator != source.__iterator) || (__seq != source.__seq))
return false;
210 template <
typename Key >
217 template <
typename Key >
219 if (__iterator >= __seq->size()) {
227 template <
typename Key >
229 if (pos > __seq->size())
230 __iterator = __seq->size();
236 template <
typename Key >
238 __iterator = std::numeric_limits< Idx >::max();
242 template <
typename Key >
244 __iterator = __seq->size();
248 template <
typename Key >
250 return Getter::op_star(__seq->__v[pos()]);
254 template <
typename Key >
256 return Getter::op_arrow(__seq->__v[pos()]);
264 template <
typename Key,
typename Alloc,
bool Gen >
266 __end_safe.__setAtEnd();
270 template <
typename Key,
typename Alloc,
bool Gen >
278 template <
typename Key,
typename Alloc,
bool Gen >
279 template <
typename OtherAlloc >
284 for (
Size i = 0; i < aSeq.
size(); ++i) {
285 Key& new_key =
const_cast< Key&
>(__h.insert(*(aSeq.
__v[i]), i).first);
286 __v.push_back(&new_key);
293 template <
typename Key,
typename Alloc,
bool Gen >
297 __end_safe{*
this}, __rend_safe{*
this} {
300 __rend_safe.__setAtRend();
305 template <
typename Key,
typename Alloc,
bool Gen >
307 std::initializer_list< Key > list) :
311 __rend_safe.__setAtRend();
312 for (
const auto& elt : list) {
318 template <
typename Key,
typename Alloc,
bool Gen >
325 __rend_safe.__setAtRend();
330 template <
typename Key,
typename Alloc,
bool Gen >
331 template <
typename OtherAlloc >
338 __rend_safe.__setAtRend();
343 template <
typename Key,
typename Alloc,
bool Gen >
346 __h(
std::move(aSeq.__h)),
347 __v(
std::move(aSeq.__v)), __end_safe{*
this}, __rend_safe{*
this} {
350 __rend_safe.__setAtRend();
355 template <
typename Key,
typename Alloc,
bool Gen >
362 template <
typename Key,
typename Alloc,
bool Gen >
375 template <
typename Key,
typename Alloc,
bool Gen >
376 template <
typename OtherAlloc >
385 template <
typename Key,
typename Alloc,
bool Gen >
391 __h = std::move(aSeq.__h);
392 __v = std::move(aSeq.__v);
400 template <
typename Key,
typename Alloc,
bool Gen >
407 template <
typename Key,
typename Alloc,
bool Gen >
410 Key& new_key =
const_cast< Key&
>(__h.insert(k, __h.size()).first);
411 __v.push_back(&new_key);
416 template <
typename Key,
typename Alloc,
bool Gen >
419 Key& new_key =
const_cast< Key&
>(__h.insert(std::move(k), __h.size()).first);
420 __v.push_back(&new_key);
425 template <
typename Key,
typename Alloc,
bool Gen >
426 template <
typename... Args >
428 Key key(std::forward< Args >(args)...);
430 const_cast< Key&
>(__h.insert(std::move(key), __h.size()).first);
431 __v.push_back(&new_key);
436 template <
typename Key,
typename Alloc,
bool Gen >
444 template <
typename Key,
typename Alloc,
bool Gen >
447 insert(std::move(k));
452 template <
typename Key,
typename Alloc,
bool Gen >
462 __v.
erase(__v.begin() + pos);
463 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
472 template <
typename Key,
typename Alloc,
bool Gen >
475 if (iter.
pos() >= size())
return;
480 __v.erase(__v.begin() + pos);
482 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
491 template <
typename Key,
typename Alloc,
bool Gen >
499 template <
typename Key,
typename Alloc,
bool Gen >
501 if (i >= __h.size()) {
503 "index " << i <<
" for a sequence of size" << __h.size());
510 template <
typename Key,
typename Alloc,
bool Gen >
517 template <
typename Key,
typename Alloc,
bool Gen >
523 template <
typename Key,
typename Alloc,
bool Gen >
529 Key& new_key =
const_cast< Key&
>(__h.insert(newKey, i).first);
530 __h.erase(*(__v[i]));
535 template <
typename Key,
typename Alloc,
bool Gen >
540 Key& new_key =
const_cast< Key&
>(__h.insert(std::move(newKey), i).first);
541 __h.erase(*(__v[i]));
546 template <
typename Key,
typename Alloc,
bool Gen >
550 Key& ki =
const_cast< Key&
>(atPos(i));
551 Key& kj =
const_cast< Key&
>(atPos(j));
561 template <
typename Key,
typename Alloc,
bool Gen >
567 template <
typename Key,
typename Alloc,
bool Gen >
569 return atPos(size() - 1);
573 template <
typename Key,
typename Alloc,
bool Gen >
575 std::stringstream stream;
579 stream << 0 <<
":" << *__v[0];
581 for (
Idx i = 1; i < __h.size(); ++i) {
582 stream <<
" - " << i <<
":" << *__v[i];
588 std::string res = stream.str();
593 template <
typename Key,
typename Alloc,
bool Gen >
594 template <
typename OtherAlloc >
597 if (size() != k.
size())
600 for (
Idx i = 0; i < size(); ++i)
601 if (*__v[i] != *(k.
__v[i]))
return false;
608 template <
typename Key,
typename Alloc,
bool Gen >
609 template <
typename OtherAlloc >
616 template <
typename Key,
typename Alloc,
bool Gen >
625 template <
typename Key,
typename Alloc,
bool Gen >
632 template <
typename Key,
typename Alloc,
bool Gen >
639 template <
typename Key,
typename Alloc,
bool Gen >
648 template <
typename Key,
typename Alloc,
bool Gen >
655 template <
typename Key,
typename Alloc,
bool Gen >
656 INLINE SequenceIterator< Key >
658 return SequenceIterator< Key >{*
this};
662 template <
typename Key,
typename Alloc,
bool Gen >
663 INLINE
const SequenceIterator< Key >&
669 template <
typename Key,
typename Alloc,
bool Gen >
670 INLINE SequenceIterator< Key >
672 SequenceIterator< Key > it{*
this};
673 it.__setPos(size() - 1);
678 template <
typename Key,
typename Alloc,
bool Gen >
679 INLINE
const SequenceIterator< Key >&
685 template <
typename Key,
typename Alloc,
bool Gen >
687 if (new_size < __h.size())
return;
690 __v.reserve(new_size);
698 template <
typename Key,
typename Alloc >
700 __end_safe.__setAtEnd();
704 template <
typename Key,
typename Alloc >
712 template <
typename Key,
typename Alloc >
713 template <
typename OtherAlloc >
718 for (
Size i = 0; i < aSeq.
size(); ++i) {
719 __h.insert(aSeq.
__v[i], i);
720 __v.push_back(aSeq.
__v[i]);
727 template <
typename Key,
typename Alloc >
731 __end_safe{*
this}, __rend_safe{*
this} {
734 __rend_safe.__setAtRend();
735 __end_safe.__setAtEnd();
739 template <
typename Key,
typename Alloc >
740 INLINE SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
741 std::initializer_list< Key > list) :
745 __rend_safe.__setAtRend();
746 for (
const auto& elt : list) {
752 template <
typename Key,
typename Alloc >
753 SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
756 __v(aSeq.__v), __end_safe{*
this}, __rend_safe{*
this} {
759 __rend_safe.__setAtRend();
760 __end_safe.__setAtEnd();
764 template <
typename Key,
typename Alloc >
765 template <
typename OtherAlloc >
766 SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
768 __h(aSeq.size() / 2),
769 __end_safe{*
this}, __rend_safe{*
this} {
772 __rend_safe.__setAtRend();
777 template <
typename Key,
typename Alloc >
778 INLINE SequenceImplementation< Key, Alloc, true >::SequenceImplementation(
780 __h(
std::move(aSeq.__h)),
781 __v(
std::move(aSeq.__v)), __end_safe{*
this}, __rend_safe{*
this} {
784 __rend_safe.__setAtRend();
785 __end_safe.__setAtEnd();
789 template <
typename Key,
typename Alloc >
795 template <
typename Key,
typename Alloc >
800 if (&aSeq !=
this) { __copy(aSeq); }
806 template <
typename Key,
typename Alloc >
807 template <
typename OtherAlloc >
816 template <
typename Key,
typename Alloc >
822 __h = std::move(aSeq.
__h);
823 __v = std::move(aSeq.
__v);
831 template <
typename Key,
typename Alloc >
837 template <
typename Key,
typename Alloc >
840 __h.
insert(k, __h.size());
846 template <
typename Key,
typename Alloc >
847 template <
typename... Args >
849 Key new_key(std::forward< Args >(args)...);
850 __h.insert(new_key, __h.size());
851 __v.push_back(new_key);
856 template <
typename Key,
typename Alloc >
864 template <
typename Key,
typename Alloc >
874 __v.
erase(__v.begin() + pos);
875 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
884 template <
typename Key,
typename Alloc >
887 if (iter.
pos() >= size())
return;
892 __v.erase(__v.begin() + pos);
894 for (
Idx i = pos, nb_elts = __h.size() - 1; i < nb_elts; ++i) {
903 template <
typename Key,
typename Alloc >
911 template <
typename Key,
typename Alloc >
914 if (i >= __h.size()) {
922 template <
typename Key,
typename Alloc >
929 template <
typename Key,
typename Alloc >
935 template <
typename Key,
typename Alloc >
940 __h.insert(newKey, i);
946 template <
typename Key,
typename Alloc >
961 template <
typename Key,
typename Alloc >
967 template <
typename Key,
typename Alloc >
969 return atPos(size() - 1);
973 template <
typename Key,
typename Alloc >
975 std::stringstream stream;
979 stream << 0 <<
":" << __v[0];
981 for (
Idx i = 1; i < __h.size(); ++i) {
982 stream <<
" - " << i <<
":" << __v[i];
988 std::string res = stream.str();
993 template <
typename Key,
typename Alloc >
994 template <
typename OtherAlloc >
997 if (size() != k.
size())
1000 for (
Idx i = 0; i < size(); ++i)
1001 if (__v[i] != k.
__v[i])
return false;
1008 template <
typename Key,
typename Alloc >
1009 template <
typename OtherAlloc >
1016 template <
typename Key,
typename Alloc >
1017 INLINE std::ostream&
1025 template <
typename Key,
typename Alloc >
1032 template <
typename Key,
typename Alloc >
1039 template <
typename Key,
typename Alloc >
1048 template <
typename Key,
typename Alloc >
1055 template <
typename Key,
typename Alloc >
1056 INLINE SequenceIterator< Key >
1058 return SequenceIterator< Key >{*
this};
1062 template <
typename Key,
typename Alloc >
1063 INLINE
const SequenceIterator< Key >&
1069 template <
typename Key,
typename Alloc >
1070 INLINE SequenceIterator< Key >
1072 SequenceIterator< Key > it{*
this};
1073 it.__setPos(size() - 1);
1078 template <
typename Key,
typename Alloc >
1079 INLINE
const SequenceIterator< Key >&
1085 template <
typename Key,
typename Alloc >
1087 if (new_size < __h.size())
return;
1090 __v.reserve(new_size);
1098 template <
typename Key,
typename Alloc >
1107 template <
typename Key,
typename Alloc >
1115 template <
typename Key,
typename Alloc >
1123 template <
typename Key,
typename Alloc >
1124 template <
typename OtherAlloc >
1133 template <
typename Key,
typename Alloc >
1142 template <
typename Key,
typename Alloc >
1149 template <
typename Key,
typename Alloc >
1152 Implementation::operator=(aSeq);
1157 template <
typename Key,
typename Alloc >
1158 template <
typename OtherAlloc >
1161 Implementation::operator=(aSeq);
1166 template <
typename Key,
typename Alloc >
1169 Implementation::operator=(std::move(aSeq));
1174 template <
typename Key,
typename Alloc >
1175 template <
typename OtherAlloc >
1180 for (
iterator iter = this->begin(); iter != this->end(); ++iter) {
1181 if (!seq.
exists(*iter)) res << *iter;
1188 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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).
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.