62 template <
typename Val >
69 template <
typename Val >
76 template <
typename Val >
77 template <
typename... Args >
79 _val_(
std::forward< Args >(args)...) {
85 template <
typename Val >
92 template <
typename Val >
104 template <
typename Val >
111 template <
typename Val >
117 template <
typename Val >
123 template <
typename Val >
129 template <
typename Val >
135 template <
typename Val >
141 template <
typename Val >
153 template <
typename Val >
160 template <
typename Val >
168 template <
typename Val >
176 template <
typename Val >
185 template <
typename Val >
203 --ind_elt, _bucket_ = _bucket_->_prev_) {}
208 template <
typename Val >
215 template <
typename Val >
221 _bucket_ = src._bucket_;
226 template <
typename Val >
231 _bucket_ = src._bucket_;
236 template <
typename Val >
242 template <
typename Val >
248 template <
typename Val >
255 template <
typename Val >
261 template <
typename Val >
271 template <
typename Val >
283 template <
typename Val >
293 template <
typename Val >
305 template <
typename Val >
312 template <
typename Val >
319 template <
typename Val >
326 template <
typename Val >
333 template <
typename Val >
340 template <
typename Val >
347 template <
typename Val >
364 template <
typename Val >
370 template <
typename Val >
377 template <
typename Val >
384 template <
typename Val >
392 template <
typename Val >
399 template <
typename Val >
408 template <
typename Val >
416 template <
typename Val >
422 template <
typename Val >
428 template <
typename Val >
434 template <
typename Val >
441 template <
typename Val >
449 template <
typename Val >
456 template <
typename Val >
464 template <
typename Val >
471 template <
typename Val >
478 template <
typename Val >
484 template <
typename Val >
490 template <
typename Val >
496 template <
typename Val >
508 template <
typename Val >
515 template <
typename Val >
526 template <
typename Val >
540 template <
typename Val >
554 if (ind_elt < (
_list_->_nb_elements_ >> 1)) {
568 template <
typename Val >
577 std::vector< ListConstIteratorSafe< Val >* >& vect =
_list_->_safe_iterators_;
579 for (
auto ptr = vect.rbegin(); ptr != vect.rend(); --ptr) {
593 template <
typename Val >
596 std::vector< ListConstIteratorSafe< Val >* >& vect =
_list_->_safe_iterators_;
598 for (
auto i = vect.size() - 1; i >= 0; --i) {
599 if (vect[i] ==
this) {
600 vect.erase(vect.begin() + i);
607 template <
typename Val >
626 src.
_list_->_safe_iterators_.push_back(
this);
630 _null_pointing_ =
false;
646 template <
typename Val >
656 if ((_list_ !=
nullptr) && (src.
_list_ != _list_)) {
657 _removeFromSafeList_();
662 if ((src.
_list_ !=
nullptr)) {
663 std::vector< ListConstIteratorSafe< Val >* >& vect = src.
_list_->_safe_iterators_;
664 Idx index_src =
Size(vect.size()) - 1;
666 for (;; --index_src) {
667 if (vect[index_src] == &src) {
break; }
670 if (_list_ ==
nullptr) {
671 vect[index_src] =
this;
673 vect.erase(vect.begin() + index_src);
692 template <
typename Val >
702 template <
typename Val >
708 template <
typename Val >
720 template <
typename Val >
727 template <
typename Val >
735 template <
typename Val >
764 if (_bucket_ !=
nullptr) { _bucket_ = _bucket_->_next_; }
771 template <
typename Val >
808 template <
typename Val >
845 template <
typename Val >
848 if (!i)
return *
this;
855 template <
typename Val >
891 template <
typename Val >
894 if (!i)
return *
this;
901 template <
typename Val >
908 template <
typename Val >
915 template <
typename Val >
924 template <
typename Val >
933 template <
typename Val >
940 template <
typename Val >
947 template <
typename Val >
954 for (; iter1 != iter3; ++iter3, ++res) {}
966 template <
typename Val >
972 template <
typename Val >
980 template <
typename Val >
988 template <
typename Val >
995 template <
typename Val >
1002 template <
typename Val >
1012 template <
typename Val >
1022 template <
typename Val >
1028 template <
typename Val >
1034 template <
typename Val >
1040 template <
typename Val >
1047 template <
typename Val >
1055 template <
typename Val >
1062 template <
typename Val >
1070 template <
typename Val >
1077 template <
typename Val >
1084 template <
typename Val >
1090 template <
typename Val >
1096 template <
typename Val >
1102 template <
typename Val >
1114 template <
typename Val >
1128 new_elt->
_prev_ = old_ptr;
1130 if (old_ptr) old_ptr->
_next_ = new_elt;
1153 template <
typename Val >
1163 next_ptr = ptr->_next_;
1168 _deb_list_ =
nullptr;
1169 _end_list_ =
nullptr;
1173 template <
typename Val >
1176 GUM_CONSTRUCTOR(
List);
1183 template <
typename Val >
1196 template <
typename Val >
1211 template <
typename Val >
1214 GUM_CONSTRUCTOR(
List);
1217 for (
const auto& val: list) {
1226 template <
typename Val >
1229 GUM_DESTRUCTOR(
List);
1237 template <
typename Val >
1255 template <
typename Val >
1281 template <
typename Val >
1287 template <
typename Val >
1293 template <
typename Val >
1299 template <
typename Val >
1305 template <
typename Val >
1311 template <
typename Val >
1317 template <
typename Val >
1323 template <
typename Val >
1329 template <
typename Val >
1335 template <
typename Val >
1341 template <
typename Val >
1347 template <
typename Val >
1353 template <
typename Val >
1359 template <
typename Val >
1365 template <
typename Val >
1371 template <
typename Val >
1378 template <
typename Val >
1385 template <
typename Val >
1392 template <
typename Val >
1399 template <
typename Val >
1406 template <
typename Val >
1412 template <
typename Val >
1418 template <
typename Val >
1419 template <
typename... Args >
1422 std::forward< Args >(args)...);
1426 template <
typename Val >
1439 return new_elt->
_val_;
1443 template <
typename Val >
1457 return new_elt->
_val_;
1461 template <
typename Val >
1467 template <
typename Val >
1473 template <
typename Val >
1474 template <
typename... Args >
1476 return pushFront(std::forward< Args >(args)...);
1480 template <
typename Val >
1481 template <
typename... Args >
1487 template <
typename Val >
1493 template <
typename Val >
1499 template <
typename Val >
1500 template <
typename... Args >
1502 return pushBack(std::forward< Args >(args)...);
1506 template <
typename Val >
1507 template <
typename... Args >
1514 template <
typename Val >
1520 template <
typename Val >
1526 template <
typename Val >
1540 template <
typename Val >
1543 new_elt->
_next_ = current_elt;
1545 current_elt->
_prev_ = new_elt;
1548 else new_elt->
_prev_->_next_ = new_elt;
1554 return new_elt->
_val_;
1558 template <
typename Val >
1561 new_elt->
_prev_ = current_elt;
1563 current_elt->
_next_ = new_elt;
1566 else new_elt->
_next_->_prev_ = new_elt;
1572 return new_elt->
_val_;
1576 template <
typename Val >
1585 template <
typename Val >
1595 template <
typename Val >
1612 if (ptr ==
nullptr) {
1628 template <
typename Val >
1635 if (ptr ==
nullptr) {
1651 template <
typename Val >
1654 if (iter.
_list_ !=
this) {
1663 template <
typename Val >
1666 if (iter.
_list_ !=
this) {
1675 template <
typename Val >
1682 template <
typename Val >
1688 template <
typename Val >
1689 template <
typename... Args >
1695 template <
typename Val >
1696 template <
typename... Args >
1702 template <
typename Val >
1710 template <
typename Val >
1718 template <
typename Val >
1724 template <
typename Val >
1727 if (ptr->_val_ == val)
return true;
1733 template <
typename Val >
1736 if (bucket !=
nullptr) {
1739 if (ptr_iter->_bucket_ == bucket) {
1740 ptr_iter->_next_current_bucket_ = bucket->
_prev_;
1741 ptr_iter->_prev_current_bucket_ = bucket->
_next_;
1742 ptr_iter->_bucket_ =
nullptr;
1743 ptr_iter->_null_pointing_ =
true;
1745 if (ptr_iter->_null_pointing_) {
1746 if (ptr_iter->_next_current_bucket_ == bucket)
1747 ptr_iter->_next_current_bucket_ = bucket->
_prev_;
1749 if (ptr_iter->_prev_current_bucket_ == bucket)
1750 ptr_iter->_prev_current_bucket_ = bucket->
_next_;
1771 template <
typename Val >
1780 template <
typename Val >
1786 template <
typename Val >
1792 template <
typename Val >
1795 if (ptr->_val_ == val)
return ptr;
1801 template <
typename Val >
1807 template <
typename Val >
1810 iter = next_bucket) {
1811 next_bucket = iter->_next_;
1813 if (val == iter->_val_)
_erase_(iter);
1818 template <
typename Val >
1824 template <
typename Val >
1830 template <
typename Val >
1836 template <
typename Val >
1839 std::stringstream stream;
1843 if (deja) stream <<
" --> ";
1845 stream << ptr->_val_;
1850 return stream.str();
1854 template <
typename Val >
1855 template <
typename Mount >
1869 template <
typename Val >
1870 template <
typename Mount >
1884 template <
typename Val >
1885 template <
typename Mount >
1899 template <
typename Val >
1900 template <
typename Mount >
1914 template <
typename Val >
1921 template <
typename Val >
1927 template <
typename Val >
1934 iter1 = iter1->_next_, iter2 = iter2->_next_)
1935 if (*iter1 != *iter2)
return false;
1941 template <
typename Val >
1947 template <
typename Val >
1956 template <
typename Val >
1965 template <
typename Val >
1974 template <
typename Val >
Exception : fatal (unknown ?) error.
Exception: at least one argument passed to a function is not what was expected.
Bucket for a chained list.
Val _val_
Val is the value contained in the box.
INLINE ListBucket(typename ListBucket< gum::Instantiation * >::Emplace, Args &&... args)
const ListBucket< Val > * next() const noexcept
Returns the bucket toward the next element.
ListBucket< Val > * _next_
Chaining toward the adjacent elements.
const ListBucket< Val > * previous() const noexcept
Returns the bucket toward the preceding element.
bool operator==(const ListBucket< Val > &src) const
Equality check.
ListBucket< Val > & operator=(const ListBucket< Val > &src)
Copy operator.
ListBucket()=delete
Removes empty constructor.
~ListBucket()
Class destructor.
Val & operator*() noexcept
Dereferencing operator.
Emplace
C dummy type for the emplace constructor.
ListBucket< Val > * _prev_
Chaining toward the adjacent elements.
bool operator!=(const ListBucket< Val > &src) const
Inequality check.
Safe const iterators for Lists.
bool operator==(const ListConstIteratorSafe< Val > &src) const
Checks whether two iterators point toward the same elements.
ListConstIteratorSafe< Val > operator+(difference_type i) noexcept
Returns a new iterator pointing to i further elements in the gum::List.
void _removeFromSafeList_() const
Remove the iterator for its list' safe iterators list.
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
bool isEnd() const
Returns a bool indicating whether the iterator points to the end of the list.
std::ptrdiff_t difference_type
Types for STL compliance.
const Val * operator->() const
Dereferences the value pointed to by the iterator.
ListConstIteratorSafe< Val > & _opPlus_(Size i) noexcept
Makes the iterator point to the next element in the List.
ListConstIteratorSafe< Val > & operator-=(difference_type i) noexcept
Makes the iterator point to i elements befor in the List.
ListConstIteratorSafe< Val > & operator--() noexcept
Makes the iterator point to the preceding element in the List.
ListConstIteratorSafe< Val > operator-(difference_type i) noexcept
Returns a new iterator pointing to i preceding elements in the gum::List.
ListConstIteratorSafe< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
~ListConstIteratorSafe()
Class Desctructor.
ListBucket< Val > * _getBucket_() const noexcept
Returns the bucket the iterator is pointing to.
friend class List< Val >
class List must be a friend because it uses the getBucket method to speed up some processes.
ListConstIteratorSafe< Val > & operator=(const ListConstIteratorSafe< Val > &src)
Copy operator.
ListBucket< Val > * _next_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a ++.
ListBucket< Val > * _prev_current_bucket_
The bucket we should start from when we are pointing on a deleted bucket and we decide to do a –.
bool operator!=(const ListConstIteratorSafe< Val > &src) const
Checks whether two iterators point toward different elements.
ListConstIteratorSafe() noexcept
Default constructor.
const Val & operator*() const
Gives access to the content of the iterator.
void setToEnd()
Positions the iterator to the end of the list.
const List< Val > * _list_
The list the iterator is pointing to.
ListConstIteratorSafe< Val > & _opMinus_(Size i) noexcept
Makes the iterator point to i elements before in the List.
void clear()
Makes the iterator point toward nothing.
bool _null_pointing_
Indicates whether the bucket the iterator points to has been deleted.
ListConstIteratorSafe< Val > & operator+=(difference_type i) noexcept
Makes the iterator point to i elements further in the List.
Unsafe but fast const iterators for Lists.
ListBucket< Val > * _bucket_
The bucket in the chained list pointed to by the iterator.
std::ptrdiff_t difference_type
Types for STL compliance.
ListConstIterator< Val > & operator+=(difference_type i) noexcept
Makes the iterator point to i elements further in the List.
bool isEnd() const noexcept
Returns a bool indicating whether the iterator points to the end of the list.
ListConstIterator< Val > & operator=(const ListConstIterator< Val > &src) noexcept
Copy operator.
ListBucket< Val > * _getBucket_() const noexcept
Returns the bucket the iterator is pointing to.
ListConstIterator< Val > & operator--() noexcept
Makes the iterator point to the preceding element in the List.
ListConstIterator< Val > & operator-=(difference_type i) noexcept
Makes the iterator point to i elements befor in the List.
bool operator==(const ListConstIterator< Val > &src) const noexcept
Checks whether two iterators point toward the same elements.
const Val * operator->() const
Dereferences the value pointed to by the iterator.
void clear() noexcept
Makes the iterator point toward nothing.
ListConstIterator< Val > operator-(difference_type i) noexcept
Returns a new iterator pointing to i preceding elements in the gum::List.
friend class List< Val >
Class List must be a friend because it uses the getBucket method to speed up some processes.
~ListConstIterator() noexcept
Class Desctructor.
ListConstIterator() noexcept
Default constructor.
ListConstIterator< Val > operator+(difference_type i) noexcept
Returns a new iterator pointing to i further elements in the gum::List.
bool operator!=(const ListConstIterator< Val > &src) const noexcept
Checks whether two iterators point toward different elements.
void setToEnd() noexcept
Positions the iterator to the end of the list.
const Val & operator*() const
Gives access to the content of the iterator.
ListConstIterator< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
Safe iterators for Lists.
std::ptrdiff_t difference_type
Types for STL compliance.
ListIteratorSafe< Val > & operator--() noexcept
Makes the iterator point to the preceding element in the List.
ListIteratorSafe() noexcept
Default constructor.
ListIteratorSafe< Val > operator+(difference_type i) noexcept
Returns a new iterator pointing to i further elements in the gum::List.
~ListIteratorSafe()
Class Desctructor.
ListIteratorSafe< Val > & operator=(const ListIteratorSafe< Val > &src)
Copy operator.
Val * operator->()
Dereferences the value pointed to by the iterator.
bool operator!=(const ListIteratorSafe< Val > &src) const
Checks whether two iterators point toward different elements.
bool operator==(const ListIteratorSafe< Val > &src) const
Checks whether two iterators point toward the same elements.
ListIteratorSafe< Val > & operator-=(difference_type i) noexcept
Makes the iterator point to i elements befor in the List.
Val & operator*()
Gives access to the content of the iterator.
ListIteratorSafe< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
ListIteratorSafe< Val > operator-(difference_type i) noexcept
Returns a new iterator pointing to i preceding elements in the gum::List.
ListIteratorSafe< Val > & operator+=(difference_type i) noexcept
Makes the iterator point to i elements further in the List.
Unsafe but fast iterators for Lists.
ListIterator< Val > & operator-=(difference_type i) noexcept
Makes the iterator point to i elements befor in the List.
ListIterator< Val > & operator--() noexcept
Makes the iterator point to the preceding element in the List.
bool operator!=(const ListIterator< Val > &src) const noexcept
Checks whether two iterators point toward different elements.
std::ptrdiff_t difference_type
Types for STL compliance.
ListIterator< Val > & operator=(const ListIterator< Val > &src) noexcept
Copy operator.
ListIterator< Val > operator-(difference_type i) noexcept
Returns a new iterator pointing to i preceding elements in the gum::List.
const Val * operator->() const
Dereferences the value pointed to by the iterator.
ListIterator< Val > operator+(difference_type i) noexcept
Returns a new iterator pointing to i further elements in the gum::List.
~ListIterator() noexcept
Class destructor.
ListIterator() noexcept
Default constructor.
ListIterator< Val > & operator+=(difference_type i) noexcept
Makes the iterator point to i elements further in the List.
ListIterator< Val > & operator++() noexcept
Makes the iterator point to the next element in the List.
bool operator==(const ListIterator< Val > &src) const noexcept
Checks whether two iterators point toward the same elements.
const Val & operator*() const
Gives access to the content of the iterator.
Generic doubly linked lists.
Val & emplaceFront(Args &&... args)
Emplace elements at the beginning of the chained list.
std::vector< const_iterator_safe * > _safe_iterators_
The list of "safe" iterators attached to the list.
void eraseByVal(const Val &val)
erases the first element encountered with a given value.
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
const_iterator cbegin() const
Returns an unsafe const iterator pointing to the beginning of the List.
const_iterator crbegin() const
Returns an unsafe const iterator pointing to the last element of the List.
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
const iterator_safe & endSafe() noexcept
Returns a safe iterator pointing to the end of the List.
Val & front() const
Returns a reference to first element of a list, if any.
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Val & operator+=(const Val &val)
Inserts a new element at the end of the list (alias of pushBack).
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
bool operator!=(const List< Val > &src) const
Checks whether two lists are different (different elements or orders).
INLINE ListBucket< gum::Instantiation * > * _createEmplaceBucket_(Args &&... args) const
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
location
Locations around iterators where insertions of new elements can take / place.
Val & push_front(Args &&... args)
An alias for pushFront used for STL compliance.
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
List()
A basic constructor that creates an empty list.
void popBack()
Removes the last element of a List, if any.
Size size() const noexcept
Returns the number of elements in the list.
void clear()
Deletes all the elements of a chained list.
friend class ListIteratorSafe< Val >
friend class ListConstIteratorSafe< Val >
std::string toString() const
Converts a list into a string.
List< Val > & operator=(const List< Val > &src)
Copy operator.
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
void eraseAllVal(const Val &val)
erases all the elements encountered with a given value
friend class ListIterator< Val >
iterator_safe rbeginSafe()
Returns a safe iterator pointing to the last element of the List.
List< Mount > map(Mount(*f)(Val)) const
Creates a list of mountains from a list of val.
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
iterator rbegin()
Returns an unsafe iterator pointing to the last element of the List.
const iterator & rend() noexcept
Returns an unsafe iterator pointing just before the beginning of the List.
Val & push_back(Args &&... args)
An alias for pushBack used for STL compliance.
const const_iterator & cend() const noexcept
Returns an unsafe const iterator pointing to the end of the List.
const iterator_safe & rendSafe() noexcept
Returns a safe iterator pointing just before the beginning of the List.
void popFront()
Removes the first element of a List, if any.
Val & emplaceBack(Args &&... args)
Emplace elements at the end of the chained list.
const const_iterator & crend() const noexcept
Returns an unsafe const iterator pointing just before the beginning of the List.
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Val & operator[](const Size i)
Returns the ith element in the current chained list.
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
iterator_safe beginSafe()
Returns a safe iterator pointing to the beginning of the List.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Size _nb_elements_
The number of elements in the list.
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
void _copy_elements_(const List< Val > &src)
A function used to perform copies of elements of Lists.
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Val & emplace(const const_iterator &iter, Args &&... args)
Emplace a new element before a given iterator.
Val & back() const
Returns a reference to last element of a list, if any.
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Val & _insert_(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
void swap(List &other_list)
Swap the current list with another one.
ListConstIterator< Val > const_iterator
Types for STL compliance.
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
bool operator==(const List< Val > &src) const
Checks whether two lists are identical (same elements in the same order).
Exception : the element we looked for cannot be found.
Exception : generic error on iterator.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Generic class for manipulating lists.
#define GUM_DEFAULT_ITERATOR_NUMBER
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
ListConstIterator< Val >::difference_type operator-(const ListConstIterator< Val > &iter1, const ListConstIterator< Val > &iter2)
For STL compliance, a distance operator.
bool operator==(const HashTableIteratorSafe< Key, Val > &from) const noexcept
Checks whether two iterators are pointing toward equal elements.