aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::List< Val > Class Template Reference

Generic doubly linked lists. More...

#include <agrum/base/core/list.h>

Public Types

enum class  location { BEFORE , AFTER }
 Locations around iterators where insertions of new elements can take / place. More...
using value_type = Val
 Types for STL compliance.
using reference = Val&
 Types for STL compliance.
using const_reference = const Val&
 Types for STL compliance.
using pointer = Val*
 Types for STL compliance.
using const_pointer = const Val*
 Types for STL compliance.
using size_type = Size
 Types for STL compliance.
using difference_type = std::ptrdiff_t
 Types for STL compliance.
using iterator = ListIterator< Val >
 Types for STL compliance.
using const_iterator = ListConstIterator< Val >
 Types for STL compliance.
using iterator_safe = ListIteratorSafe< Val >
 Types for STL compliance.
using const_iterator_safe = ListConstIteratorSafe< Val >
 Types for STL compliance.

Public Member Functions

Constructors / Destructors
 List ()
 A basic constructor that creates an empty list.
 List (const List< Val > &src)
 Copy constructor.
 List (List< Val > &&src) noexcept
 Move constructor.
 List (std::initializer_list< Val > list)
 Initializer_list constructor.
 ~List ()
 Class destructor.
Iterators
const const_iterator_safecendSafe () const noexcept
 Returns a safe const iterator pointing to the end of the List.
const iterator_safeendSafe () noexcept
 Returns a safe iterator pointing to the end of the List.
const const_iterator_safecrendSafe () const noexcept
 Return a safe const iterator pointing just before the beginning of the List.
const iterator_saferendSafe () noexcept
 Returns a safe iterator pointing just before the beginning of the List.
const_iterator_safe cbeginSafe () const
 Returns a safe const iterator pointing to the beginning of the List.
iterator_safe beginSafe ()
 Returns a safe iterator pointing to the beginning of the List.
const_iterator_safe crbeginSafe () const
 Returns a safe const iterator pointing to the last element of the List.
iterator_safe rbeginSafe ()
 Returns a safe iterator pointing to the last element of the List.
const const_iteratorcend () const noexcept
 Returns an unsafe const iterator pointing to the end of the List.
const iteratorend () noexcept
 Returns an unsafe iterator pointing to the end of the List.
const const_iteratorend () const noexcept
 Returns an unsafe const iterator pointing to the end of the List.
const const_iteratorcrend () const noexcept
 Returns an unsafe const iterator pointing just before the beginning of the List.
const iteratorrend () noexcept
 Returns an unsafe iterator pointing just before the beginning of the List.
const const_iteratorrend () const noexcept
 Returns an unsafe const iterator pointing just before the beginning of the List.
const_iterator cbegin () const
 Returns an unsafe const iterator pointing to the beginning of the List.
iterator begin ()
 Returns an unsafe iterator pointing to the beginning of the List.
const_iterator begin () 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.
iterator rbegin ()
 Returns an unsafe iterator pointing to the last element of the List.
const_iterator rbegin () const
 Returns an unsafe const iterator pointing to the last element of the List.
Accessors / Modifiers
Val & pushFront (const Val &val)
 Inserts a new element (a copy) at the beginning of the chained list.
Val & pushFront (Val &&val)
 Inserts a new element (a move) at the beginning of the chained list.
template<typename... Args>
Val & push_front (Args &&... args)
 An alias for pushFront used for STL compliance.
template<typename... Args>
Val & emplaceFront (Args &&... args)
 Emplace elements at the beginning of the chained list.
Val & pushBack (const Val &val)
 Inserts a new element (a copy) at the end of the chained list.
Val & pushBack (Val &&val)
 Inserts a new element (a move) at the end of the chained list.
template<typename... Args>
Val & push_back (Args &&... args)
 An alias for pushBack used for STL compliance.
template<typename... Args>
Val & emplaceBack (Args &&... args)
 Emplace elements at the end of the chained list.
Val & insert (const Val &val)
 Inserts a new element at the end of the chained list (alias of pushBack).
Val & insert (Val &&val)
 Inserts a new element at the end of the chained list (alias of pushBack).
Val & insert (Size pos, const Val &val)
 Inserts a new element at the ith pos of the chained list.
Val & insert (Size pos, Val &&val)
 Insert an rvalue at the ith pos of the chained list.
Val & insert (const const_iterator_safe &iter, const Val &val, location place=location::BEFORE)
 Inserts a new element before or after a given iterator.
Val & insert (const const_iterator_safe &iter, Val &&val, location place=location::BEFORE)
 Inserts an rvalue before or after a given iterator.
Val & insert (const const_iterator &iter, const Val &val, location place=location::BEFORE)
 Inserts a new element before or after a given iterator.
Val & insert (const const_iterator &iter, Val &&val, location place=location::BEFORE)
 Inserts an rvalue before or after a given iterator.
template<typename... Args>
Val & emplace (const const_iterator &iter, Args &&... args)
 Emplace a new element before a given iterator.
template<typename... Args>
Val & emplace (const const_iterator_safe &iter, Args &&... args)
 Emplace a new element before a given safe iterator.
Val & front () const
 Returns a reference to first element of a list, if any.
Val & back () const
 Returns a reference to last element of a list, if any.
Size size () const noexcept
 Returns the number of elements in the list.
bool exists (const Val &val) const
 Checks whether there exists a given element in the list.
void erase (Size i)
 Erases the ith element of the List (the first one is in position 0).
void erase (const iterator_safe &iter)
 Erases the element of the List pointed to by the safe iterator.
void erase (const const_iterator_safe &iter)
 Erases the element of the List pointed to by the safe const iterator.
void eraseByVal (const Val &val)
 erases the first element encountered with a given value.
void eraseAllVal (const Val &val)
 erases all the elements encountered with a given value
void popBack ()
 Removes the last element of a List, if any.
void popFront ()
 Removes the first element of a List, if any.
void clear ()
 Deletes all the elements of a chained list.
bool empty () const noexcept
 Returns a boolean indicating whether the chained list is empty.
void swap (List &other_list)
 Swap the current list with another one.
std::string toString () const
 Converts a list into a string.
template<typename Mount>
List< Mount > map (Mount(*f)(Val)) const
 Creates a list of mountains from a list of val.
template<typename Mount>
List< Mount > map (Mount(*f)(Val &)) const
 Creates a list of mountains from a list of val.
template<typename Mount>
List< Mount > map (Mount(*f)(const Val &)) const
 Creates a list of mountains from a list of val.
template<typename Mount>
List< Mount > map (const Mount &mount) const
 Creates a list of mountains with a given value from a list of val.
Operators
List< Val > & operator= (const List< Val > &src)
 Copy operator.
List< Val > & operator= (List< Val > &&src)
 Move operator.
Val & operator+= (const Val &val)
 Inserts a new element at the end of the list (alias of pushBack).
Val & operator+= (Val &&val)
 Inserts a new element at the end of the list (alias of pushBack).
bool operator== (const List< Val > &src) const
 Checks whether two lists are identical (same elements in the same order).
bool operator!= (const List< Val > &src) const
 Checks whether two lists are different (different elements or orders).
Val & operator[] (const Size i)
 Returns the ith element in the current chained list.
const Val & operator[] (const Size i) const
 Returns the const ith element in the current chained list.

Private Member Functions

void _copy_elements_ (const List< Val > &src)
 A function used to perform copies of elements of Lists.
ListBucket< Val > * _getIthBucket_ (Size i) const noexcept
 Returns the bucket corresponding to the ith position in the list.
ListBucket< Val > * _getBucket_ (const Val &val) const noexcept
 Returns the bucket corresponding to a given value.
void _erase_ (ListBucket< Val > *bucket)
 Removes an element from a chained list.
ListBucket< Val > * _createBucket_ (const Val &val) const
 Create a new bucket with a given value.
ListBucket< Val > * _createBucket_ (Val &&val) const
 Create a new bucket with a given value.
template<typename... Args>
ListBucket< Val > * _createEmplaceBucket_ (Args &&... args) const
 Create an emplace bucket.
Val & _pushFront_ (ListBucket< Val > *new_elt)
 Insert a bucket at the front of the list.
Val & _pushBack_ (ListBucket< Val > *new_elt)
 Insert a bucket at the end of the list.
Val & _insertBefore_ (ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
 Insert a new bucket before another one.
Val & _insertAfter_ (ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
 Insert a new bucket after another one.
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.
Val & _insert_ (const const_iterator &iter, ListBucket< Val > *new_elt, location place)
 Inserts a new bucket before or after the location pointed to by an iterator.

Private Attributes

ListBucket< Val > * _deb_list_ {nullptr}
 A pointer on the first element of the chained list.
ListBucket< Val > * _end_list_ {nullptr}
 A pointer on the last element of the chained list.
Size _nb_elements_ {Size(0)}
 The number of elements in the list.
std::vector< const_iterator_safe * > _safe_iterators_
 The list of "safe" iterators attached to the list.

Friends

class ListIterator< Val >
 ListIterator should be a friend to optimize access to elements.
class ListConstIterator< Val >
 ListIterator should be a friend to optimize access to elements.
class ListIteratorSafe< Val >
 ListIterator should be a friend to optimize access to elements.
class ListConstIteratorSafe< Val >
 ListIterator should be a friend to optimize access to elements.

Detailed Description

template<typename Val>
class gum::List< Val >

Generic doubly linked lists.

List enables fast and safe manipulation of chained lists. Unless the elements are rvalues, the insertions of new elements into the lists are ALWAYS performed by copy, i.e., each time we add a new element X to the List, a copy of X is actually created and this very copy is stored into the list. For rvalues, move operations are performed.

The List iterators are implemented so as to avoid segmentation faults when elements of the list are deleted while some safe iterators are pointing on them. Moreover they ensure that, when elements are removed from a List, iterators on that list will never access these elements (which is not the case for the iterators in the C++ standard library). Note that this guarantee is ensured at low cost as experimental results show that List and ListIterator are as efficient as their STL counterparts. However, this guarantee can hold only if List is aware of all of the iterators pointing to it: thus, when List erases one element, it can parse the list of its iterators and update those that point toward the now deleted element. When parsing elements without removing any element, you can use unsafe iterators instead of safe ones because they are slightly faster. But those will most certainly segfault if they perform some operations on deleted elements.

Usage example:
// creation of an empty list
List<int> list1;
List<int> list2 { 3, 4, 5 }; // initializer list
// adding elements to the list
list1.pushFront (23);
list1.pushBack (10);
list1 += 25;
list1.insert (12);
// getting the second element of the list
cerr << "10 = " << list1[1] << endl;
// getting the first and last elements
cerr << "first = " << list1.front() << " last = " << list1.back() << endl;
// get the number of elements in the list
cerr << "number of elements = " << list1.size () << endl;
// display the content of the list
cerr << list1 << endl;
// copy the list
List<int> list2 = list1, list3;
list3 = list1;
// delete the second element from the list
list1.erase (1);
// delete the first and last elements
list1.popFront ();
list1.popBack ();
// delete element whose value is 25
list1.eraseByVal (25);
// check whether the list is empty
if (list1.empty()) cerr << "empty list" << endl;
// remove all elements from the list
list1.clear ();
// parse all the elements of a list using unsafe iterators
for (List<int>::iterator iter = list2.begin();
iter != list2.end(); ++iter)
cerr << *iter << endl;
for (List<int>::iterator iter = list2.rbegin();
iter != list2.rend(); --iter)
cerr << *iter << endl;
for (List<int>::const_iterator iter = list2.cbegin();
iter != list2.cend(); ++iter)
cerr << *iter << endl;
for (List<int>::const_iterator iter = list2.crbegin();
iter != list2.crend(); --iter)
cerr << *iter << endl;
// parse all the elements of a list using safe iterators
for (List<int>::iterator_safe iter = list2.beginSafe();
iter != list2.endSafe(); ++iter)
cerr << *iter << endl;
iter != list2.rendSafe(); --iter)
cerr << *iter << endl;
iter != list2.cendSafe(); ++iter)
cerr << *iter << endl;
iter != list2.crendSafe(); --iter)
cerr << *iter << endl;
// use an iterator to point the element we wish to erase
List2.erase ( iter );
List<int>::iterator iter2 = list2.begin() + 4; // 5th element of the list
iter2 = iter + 4;
// map a list into another list (assuming function f is defined as
// float f (int x) { return (2.5 * x); } )
List<float> flist = list2.map (f);
Generic doubly linked lists.
Definition list.h:378
Size size() const noexcept
Returns the number of elements in the list.
Definition list_tpl.h:1710
const iterator & rend() noexcept
Returns an unsafe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1323
iterator rbegin()
Returns an unsafe iterator pointing to the last element of the List.
Definition list_tpl.h:1386
const_iterator cbegin() const
Returns an unsafe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1347
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Definition list.h:392
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
Definition list_tpl.h:1455
const const_iterator & cend() const noexcept
Returns an unsafe const iterator pointing to the end of the List.
Definition list_tpl.h:1287
Val & back() const
Returns a reference to last element of a list, if any.
Definition list_tpl.h:1702
void clear()
Deletes all the elements of a chained list.
Definition list_tpl.h:1147
Val & front() const
Returns a reference to first element of a list, if any.
Definition list_tpl.h:1694
const iterator_safe & rendSafe() noexcept
Returns a safe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1311
ListIterator< Val > iterator
Types for STL compliance.
Definition list.h:389
iterator_safe beginSafe()
Returns a safe iterator pointing to the beginning of the List.
Definition list_tpl.h:1341
List< Mount > map(Mount(*f)(Val)) const
Creates a list of mountains from a list of val.
Definition list_tpl.h:1847
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1481
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1335
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition list_tpl.h:1293
void popBack()
Removes the last element of a List, if any.
Definition list_tpl.h:1810
List()
A basic constructor that creates an empty list.
Definition list_tpl.h:1167
const const_iterator & crend() const noexcept
Returns an unsafe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1317
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
Definition list.h:391
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition list_tpl.h:1353
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Definition list_tpl.h:1508
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition list_tpl.h:1822
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Definition list_tpl.h:1365
void popFront()
Removes the first element of a List, if any.
Definition list_tpl.h:1816
const_iterator crbegin() const
Returns an unsafe const iterator pointing to the last element of the List.
Definition list_tpl.h:1379
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Definition list_tpl.h:1275
void eraseByVal(const Val &val)
erases the first element encountered with a given value.
Definition list_tpl.h:1793
iterator_safe rbeginSafe()
Returns a safe iterator pointing to the last element of the List.
Definition list_tpl.h:1372
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition list.h:390
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1305
const iterator_safe & endSafe() noexcept
Returns a safe iterator pointing to the end of the List.
Definition list_tpl.h:1281
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
Definition list_tpl.h:1763
Template Parameters
ValThe values type stored in the gum::List.

Definition at line 378 of file list.h.

Member Typedef Documentation

◆ const_iterator

template<typename Val>
using gum::List< Val >::const_iterator = ListConstIterator< Val >

Types for STL compliance.

Definition at line 390 of file list.h.

◆ const_iterator_safe

template<typename Val>
using gum::List< Val >::const_iterator_safe = ListConstIteratorSafe< Val >

Types for STL compliance.

Definition at line 392 of file list.h.

◆ const_pointer

template<typename Val>
using gum::List< Val >::const_pointer = const Val*

Types for STL compliance.

Definition at line 386 of file list.h.

◆ const_reference

template<typename Val>
using gum::List< Val >::const_reference = const Val&

Types for STL compliance.

Definition at line 384 of file list.h.

◆ difference_type

template<typename Val>
using gum::List< Val >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 388 of file list.h.

◆ iterator

template<typename Val>
using gum::List< Val >::iterator = ListIterator< Val >

Types for STL compliance.

Definition at line 389 of file list.h.

◆ iterator_safe

template<typename Val>
using gum::List< Val >::iterator_safe = ListIteratorSafe< Val >

Types for STL compliance.

Definition at line 391 of file list.h.

◆ pointer

template<typename Val>
using gum::List< Val >::pointer = Val*

Types for STL compliance.

Definition at line 385 of file list.h.

◆ reference

template<typename Val>
using gum::List< Val >::reference = Val&

Types for STL compliance.

Definition at line 383 of file list.h.

◆ size_type

template<typename Val>
using gum::List< Val >::size_type = Size

Types for STL compliance.

Definition at line 387 of file list.h.

◆ value_type

template<typename Val>
using gum::List< Val >::value_type = Val

Types for STL compliance.

Definition at line 382 of file list.h.

Member Enumeration Documentation

◆ location

template<typename Val>
enum class gum::List::location
strong

Locations around iterators where insertions of new elements can take / place.

Enumerator
BEFORE 
AFTER 

Definition at line 397 of file list.h.

397{ BEFORE, AFTER };

Constructor & Destructor Documentation

◆ List() [1/4]

template<typename Val>
gum::List< Val >::List ( )
explicit

A basic constructor that creates an empty list.

Definition at line 1167 of file list_tpl.h.

1167 {
1168 // for debugging purposes
1170
1171 // reserve space for only the default number of iterators
1173 }
std::vector< const_iterator_safe * > _safe_iterators_
The list of "safe" iterators attached to the list.
Definition list.h:1262

References List(), _safe_iterators_, and GUM_DEFAULT_ITERATOR_NUMBER.

Referenced by List(), List(), List(), List(), ~List(), _copy_elements_(), map(), map(), map(), map(), operator!=(), operator=(), operator=(), operator==(), and swap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ List() [2/4]

template<typename Val>
gum::List< Val >::List ( const List< Val > & src)

Copy constructor.

The new list and that which is copied do not share their elements: the new list contains new instances of the values stored in the list to be copied. Of course if these values are pointers, the new values point toward the same elements. This constructor runs in linear time.

Parameters
srcthe list the contents of which is copied into the current one.

Definition at line 1177 of file list_tpl.h.

1177 {
1178 // for debugging purposes
1180
1181 // copy the elements
1183
1184 // reserve space for only the default number of iterators
1186 }
void _copy_elements_(const List< Val > &src)
A function used to perform copies of elements of Lists.
Definition list_tpl.h:1108

References List(), and _copy_elements_().

Here is the call graph for this function:

◆ List() [3/4]

template<typename Val>
gum::List< Val >::List ( List< Val > && src)
noexcept

Move constructor.

Parameters
srcThe gum::List to move.

Definition at line 1190 of file list_tpl.h.

1190 :
1194 // for debugging purposes
1196
1197 src._deb_list_ = nullptr;
1198 src._end_list_ = nullptr;
1199 src._nb_elements_ = 0;
1200 src._safe_iterators_.clear();
1201 }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition list.h:1253
Size _nb_elements_
The number of elements in the list.
Definition list.h:1259
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition list.h:1256

References List(), and _deb_list_.

Here is the call graph for this function:

◆ List() [4/4]

template<typename Val>
gum::List< Val >::List ( std::initializer_list< Val > list)

Initializer_list constructor.

Parameters
listThe initializer list.

Definition at line 1205 of file list_tpl.h.

1205 {
1206 // for debugging purposes
1208
1209 // adding all the elements
1210 for (const auto& val: list) {
1211 pushBack(val);
1212 }
1213
1214 // reserve space for only the default number of iterators
1216 }

References List().

Here is the call graph for this function:

◆ ~List()

template<typename Val>
gum::List< Val >::~List ( )

Class destructor.

Definition at line 1220 of file list_tpl.h.

1220 {
1221 // for debugging (although this program is bug-free)
1223
1224 // we detach all the safe iterators attached to the current List and we
1225 // remove all the elements from the list
1226 clear();
1227 }

References List(), and clear().

Here is the call graph for this function:

Member Function Documentation

◆ _copy_elements_()

template<typename Val>
void gum::List< Val >::_copy_elements_ ( const List< Val > & src)
private

A function used to perform copies of elements of Lists.

Before performing the copy, we assume in this function that the current list (this) is empty (else there would be memory leak).

Parameters
srcThe gum::List to copy.

Definition at line 1108 of file list_tpl.h.

1108 {
1110 ListBucket< Val >* old_ptr = nullptr;
1111 ListBucket< Val >* new_elt = nullptr;
1112
1113 // copy src's list
1114 try {
1115 for (ptr = src._deb_list_; ptr != nullptr; ptr = ptr->_next_) {
1116 // create a copy bucket
1118
1119 // rechain properly the new list (the next field is already initialized
1120 // with nullptr)
1121 new_elt->_prev_ = old_ptr;
1122
1123 if (old_ptr) old_ptr->_next_ = new_elt;
1124 else _deb_list_ = new_elt;
1125
1126 old_ptr = new_elt;
1127 }
1128 } catch (...) {
1129 // problem: we could not allocate an element in the list => we delete
1130 // the elements created so far and we throw an exception
1131 for (; _deb_list_ != nullptr; _deb_list_ = const_cast< ListBucket< Val >* >(ptr)) {
1132 ptr = _deb_list_->_next_;
1133 delete _deb_list_;
1134 }
1135
1136 _deb_list_ = nullptr;
1137 throw;
1138 }
1139
1140 // update properly the end of the chained list and the number of elements
1143 }

References List().

Referenced by List().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _createBucket_() [1/2]

template<typename Val>
ListBucket< Val > * gum::List< Val >::_createBucket_ ( const Val & val) const
private

Create a new bucket with a given value.

Parameters
valThe value of the new bucket.
Returns
Returns the bucket holding val.

Definition at line 1400 of file list_tpl.h.

1400 {
1401 return new ListBucket< Val >(val);
1402 }

Referenced by insert(), insert(), insert(), insert(), insert(), insert(), pushBack(), pushBack(), pushFront(), and pushFront().

Here is the caller graph for this function:

◆ _createBucket_() [2/2]

template<typename Val>
ListBucket< Val > * gum::List< Val >::_createBucket_ ( Val && val) const
private

Create a new bucket with a given value.

Parameters
valThe value of the new bucket.
Returns
Returns the bucket holding val.

Definition at line 1406 of file list_tpl.h.

1406 {
1407 return new ListBucket< Val >(std::move(val));
1408 }

◆ _createEmplaceBucket_()

template<typename Val>
template<typename... Args>
ListBucket< Val > * gum::List< Val >::_createEmplaceBucket_ ( Args &&... args) const
private

Create an emplace bucket.

Template Parameters
ArgsThe emplace arguments types.
Parameters
argsThe emplace arguments.
Returns
Returns the bucket holding the new value.

Definition at line 1413 of file list_tpl.h.

References gum::ListBucket< Val >::EMPLACE.

Referenced by emplace(), emplace(), emplaceBack(), and emplaceFront().

Here is the caller graph for this function:

◆ _erase_()

template<typename Val>
void gum::List< Val >::_erase_ ( ListBucket< Val > * bucket)
private

Removes an element from a chained list.

If parameter bucket is equal to 0, then the method does not perform anything, else the bucket is deleted. In the latter case, no test is ever performed to check that the bucket does actually belong to the List. The method runs in constant time.

Parameters
bucketA pointer on the bucket in the chained list we wish to remove.

Definition at line 1725 of file list_tpl.h.

1725 {
1726 // perform deletion only if there is a bucket to remove
1727 if (bucket != nullptr) {
1728 // update the iterators pointing on this element
1729 for (const auto ptr_iter: _safe_iterators_) {
1730 if (ptr_iter->_bucket_ == bucket) {
1731 ptr_iter->_next_current_bucket_ = bucket->_prev_;
1732 ptr_iter->_prev_current_bucket_ = bucket->_next_;
1733 ptr_iter->_bucket_ = nullptr;
1734 ptr_iter->_null_pointing_ = true;
1735 } else {
1736 if (ptr_iter->_null_pointing_) {
1737 if (ptr_iter->_next_current_bucket_ == bucket)
1738 ptr_iter->_next_current_bucket_ = bucket->_prev_;
1739
1740 if (ptr_iter->_prev_current_bucket_ == bucket)
1741 ptr_iter->_prev_current_bucket_ = bucket->_next_;
1742 }
1743 }
1744 }
1745
1746 // set properly the begin and end of the chained list (the other chainings
1747 // will be performed by operator delete)
1748 if (bucket->_prev_ == nullptr) _deb_list_ = bucket->_next_;
1749 else bucket->_prev_->_next_ = bucket->_next_;
1750
1751 if (bucket->_next_ == nullptr) _end_list_ = bucket->_prev_;
1752 else bucket->_next_->_prev_ = bucket->_prev_;
1753
1754 // remove the current element src the list
1755 delete bucket;
1756
1757 --_nb_elements_;
1758 }
1759 }

References _deb_list_, _end_list_, _nb_elements_, gum::ListBucket< Val >::_next_, gum::ListBucket< Val >::_prev_, and _safe_iterators_.

Referenced by erase(), erase(), erase(), eraseAllVal(), eraseByVal(), popBack(), and popFront().

Here is the caller graph for this function:

◆ _getBucket_()

template<typename Val>
ListBucket< Val > * gum::List< Val >::_getBucket_ ( const Val & val) const
privatenoexcept

Returns the bucket corresponding to a given value.

Actually, this is the first bucket of value val encountered in the list, if any, that is returned. If the element cannot be found, 0 is returned. This method enables fast removals of buckets. It runs in linear time.

Comparisons between Val instances are performed through == operators.

Parameters
valThe value of the element the bucket of which we wish to return.
Returns
Returns the bucket corresponding to a given value.

Definition at line 1784 of file list_tpl.h.

1784 {
1785 for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_)
1786 if (ptr->_val_ == val) return ptr;
1787
1788 return nullptr;
1789 }

References _deb_list_, gum::ListBucket< Val >::_next_, and gum::ListBucket< Val >::_val_.

Referenced by eraseByVal().

Here is the caller graph for this function:

◆ _getIthBucket_()

template<typename Val>
ListBucket< Val > * gum::List< Val >::_getIthBucket_ ( Size i) const
privatenoexcept

Returns the bucket corresponding to the ith position in the list.

This method assumes that the list contains at least i+1 elements. The index of the first element of the list is 0.

Parameters
iThe position of the returned element.
Returns
Returns the gum::ListBucket of the ith element.

Definition at line 1520 of file list_tpl.h.

1520 {
1522
1523 if (i < _nb_elements_ / 2) {
1524 for (ptr = _deb_list_; i; --i, ptr = ptr->_next_) {}
1525 } else {
1526 for (ptr = _end_list_, i = _nb_elements_ - i - 1; i; --i, ptr = ptr->_prev_) {}
1527 }
1528
1529 return ptr;
1530 }

References _deb_list_, _end_list_, _nb_elements_, gum::ListBucket< Val >::_next_, and gum::ListBucket< Val >::_prev_.

Referenced by erase(), insert(), insert(), operator[](), and operator[]().

Here is the caller graph for this function:

◆ _insert_() [1/2]

template<typename Val>
Val & gum::List< Val >::_insert_ ( const const_iterator & iter,
ListBucket< Val > * new_elt,
location place )
private

Inserts a new bucket before or after the location pointed to by an iterator.

Parameters
iterAn iterator pointing where to insert a new element.
new_eltThe new element ot insert in the gum::List.
placeWhere to insert the new element relatively to the iterator.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1620 of file list_tpl.h.

1622 {
1623 // find the location around which the new element should be inserted
1625
1626 if (ptr == nullptr) {
1627 // here, we are at the end of the list
1628 return _pushBack_(new_elt);
1629 } else {
1630 switch (place) {
1632
1633 case location::AFTER : return _insertAfter_(new_elt, ptr);
1634
1635 default : GUM_ERROR(FatalError, "List insertion for this location unimplemented")
1636 }
1637 }
1638 }
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition list_tpl.h:1437
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition list_tpl.h:1784
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition list_tpl.h:1551
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition list_tpl.h:1534
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References gum::ListConstIterator< Val >::_getBucket_(), _insertAfter_(), _insertBefore_(), _pushBack_(), AFTER, BEFORE, and GUM_ERROR.

Here is the call graph for this function:

◆ _insert_() [2/2]

template<typename Val>
Val & gum::List< Val >::_insert_ ( const const_iterator_safe & iter,
ListBucket< Val > * new_elt,
location place )
private

Inserts a new bucket before or after the location pointed to by an iterator.

Parameters
iterAn iterator pointing where to insert a new element.
new_eltThe new element ot insert in the gum::List.
placeWhere to insert the new element relatively to the iterator.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1587 of file list_tpl.h.

1589 {
1590 // find the location around which the new element should be inserted
1592
1593 if (iter._null_pointing_) {
1594 if (place == location::BEFORE) {
1595 ptr = iter._next_current_bucket_;
1596 } else {
1597 ptr = iter._prev_current_bucket_;
1598 }
1599 } else {
1600 ptr = iter._getBucket_();
1601 }
1602
1603 if (ptr == nullptr) {
1604 // here, we are at the end of the list
1605 return _pushBack_(new_elt);
1606 } else {
1607 switch (place) {
1609
1610 case location::AFTER : return _insertAfter_(new_elt, ptr);
1611
1612 default : GUM_ERROR(FatalError, "List insertion for this location unimplemented")
1613 }
1614 }
1615 }

References gum::ListConstIteratorSafe< Val >::_getBucket_(), _insertAfter_(), _insertBefore_(), gum::ListConstIteratorSafe< Val >::_next_current_bucket_, gum::ListConstIteratorSafe< Val >::_null_pointing_, gum::ListConstIteratorSafe< Val >::_prev_current_bucket_, _pushBack_(), AFTER, BEFORE, and GUM_ERROR.

Referenced by emplace(), emplace(), insert(), insert(), insert(), and insert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _insertAfter_()

template<typename Val>
Val & gum::List< Val >::_insertAfter_ ( ListBucket< Val > * new_elt,
ListBucket< Val > * current_elt )
private

Insert a new bucket after another one.

Parameters
new_eltThe new element to insert in the gum::List.
current_eltThe element before which new_elt will be inserted.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1551 of file list_tpl.h.

1551 {
1552 new_elt->_prev_ = current_elt;
1553 new_elt->_next_ = current_elt->_next_;
1554 current_elt->_next_ = new_elt;
1555
1556 if (new_elt->_next_ == nullptr) _end_list_ = new_elt;
1557 else new_elt->_next_->_prev_ = new_elt;
1558
1559 // update the number of elements
1560 ++_nb_elements_;
1561
1562 // returns the current value
1563 return new_elt->_val_;
1564 }

References _end_list_, _nb_elements_, gum::ListBucket< Val >::_next_, gum::ListBucket< Val >::_prev_, and gum::ListBucket< Val >::_val_.

Referenced by _insert_(), and _insert_().

Here is the caller graph for this function:

◆ _insertBefore_()

template<typename Val>
Val & gum::List< Val >::_insertBefore_ ( ListBucket< Val > * new_elt,
ListBucket< Val > * current_elt )
private

Insert a new bucket before another one.

Parameters
new_eltThe new element to insert in the gum::List.
current_eltThe element before which new_elt will be inserted.
Returns
Returns a reference over the value stored in the gum::List.

Definition at line 1534 of file list_tpl.h.

1534 {
1535 new_elt->_next_ = current_elt;
1536 new_elt->_prev_ = current_elt->_prev_;
1537 current_elt->_prev_ = new_elt;
1538
1539 if (new_elt->_prev_ == nullptr) _deb_list_ = new_elt;
1540 else new_elt->_prev_->_next_ = new_elt;
1541
1542 // update the number of elements
1543 ++_nb_elements_;
1544
1545 // returns the current value
1546 return new_elt->_val_;
1547 }

References _deb_list_, _nb_elements_, gum::ListBucket< Val >::_next_, gum::ListBucket< Val >::_prev_, and gum::ListBucket< Val >::_val_.

Referenced by _insert_(), _insert_(), insert(), and insert().

Here is the caller graph for this function:

◆ _pushBack_()

template<typename Val>
Val & gum::List< Val >::_pushBack_ ( ListBucket< Val > * new_elt)
private

Insert a bucket at the end of the list.

Parameters
new_eltThe new element pushed at the end of the gum::List.
Returns
Returns a refefence over the value stored in the gum::List.

Definition at line 1437 of file list_tpl.h.

1437 {
1438 // place the bucket at the end of the list
1439 new_elt->_prev_ = _end_list_;
1440
1441 if (_end_list_ != nullptr) _end_list_->_next_ = new_elt;
1442 else _deb_list_ = new_elt;
1443
1445
1446 // update the number of elements
1447 ++_nb_elements_;
1448
1449 // returns the current value
1450 return new_elt->_val_;
1451 }

References _deb_list_, _end_list_, _nb_elements_, gum::ListBucket< Val >::_prev_, and gum::ListBucket< Val >::_val_.

Referenced by _insert_(), _insert_(), emplaceBack(), pushBack(), and pushBack().

Here is the caller graph for this function:

◆ _pushFront_()

template<typename Val>
Val & gum::List< Val >::_pushFront_ ( ListBucket< Val > * new_elt)
private

Insert a bucket at the front of the list.

Parameters
new_eltThe new element pushed at the front of the gum::List.
Returns
Returns a refefence over the value stored in the gum::List.

Definition at line 1420 of file list_tpl.h.

1420 {
1421 new_elt->_next_ = _deb_list_;
1422
1423 if (_deb_list_ != nullptr) _deb_list_->_prev_ = new_elt;
1424 else _end_list_ = new_elt;
1425
1427
1428 // update the number of elements
1429 ++_nb_elements_;
1430
1431 // return the inserted element
1432 return new_elt->_val_;
1433 }

References _deb_list_, _end_list_, _nb_elements_, gum::ListBucket< Val >::_next_, and gum::ListBucket< Val >::_val_.

Referenced by emplaceFront(), pushFront(), and pushFront().

Here is the caller graph for this function:

◆ back()

template<typename Val>
Val & gum::List< Val >::back ( ) const

Returns a reference to last element of a list, if any.

Exceptions
NotFoundexception is thrown if the list is empty.

Definition at line 1702 of file list_tpl.h.

1702 {
1703 if (_nb_elements_ == Size(0)) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1704
1705 return _end_list_->_val_;
1706 }

References _end_list_, _nb_elements_, and GUM_ERROR.

◆ begin() [1/2]

template<typename Val>
ListIterator< Val > gum::List< Val >::begin ( )

Returns an unsafe iterator pointing to the beginning of the List.

Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe iterator pointing to the beginning of the List.

Definition at line 1353 of file list_tpl.h.

1353 {
1354 return ListIterator< Val >{*this};
1355 }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1388

References ListIterator< Val >.

Referenced by map(), map(), and map().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [2/2]

template<typename Val>
ListConstIterator< Val > gum::List< Val >::begin ( ) const

Returns an unsafe const iterator pointing to the beginning of the List.

Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns an unsafe const iterator pointing to the beginning of the List.

Definition at line 1359 of file list_tpl.h.

1359 {
1360 return ListConstIterator< Val >{*this};
1361 }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1389

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ beginSafe()

template<typename Val>
ListIteratorSafe< Val > gum::List< Val >::beginSafe ( )

Returns a safe iterator pointing to the beginning of the List.

Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Returns
Returns a safe iterator pointing to the beginning of the List.

Definition at line 1341 of file list_tpl.h.

1341 {
1342 return ListIteratorSafe< Val >{*this};
1343 }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1390

◆ cbegin()

template<typename Val>
ListConstIterator< Val > gum::List< Val >::cbegin ( ) const

Returns an unsafe const iterator pointing to the beginning of the List.

Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe const iterator pointing to the beginning of the List.

Definition at line 1347 of file list_tpl.h.

1347 {
1348 return ListConstIterator< Val >{*this};
1349 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ cbeginSafe()

template<typename Val>
ListConstIteratorSafe< Val > gum::List< Val >::cbeginSafe ( ) const

Returns a safe const iterator pointing to the beginning of the List.

Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Returns
Returns a safe const iterator pointing to the beginning of the List.

Definition at line 1335 of file list_tpl.h.

1335 {
1336 return ListConstIteratorSafe< Val >{*this};
1337 }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1391

References ListConstIteratorSafe< Val >.

Here is the call graph for this function:

◆ cend()

template<typename Val>
const ListConstIterator< Val > & gum::List< Val >::cend ( ) const
noexcept

Returns an unsafe const iterator pointing to the end of the List.

Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns an unsafe const iterator pointing to the end of the List.

Definition at line 1287 of file list_tpl.h.

1287 {
1288 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1289 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ cendSafe()

template<typename Val>
const ListConstIteratorSafe< Val > & gum::List< Val >::cendSafe ( ) const
noexcept

Returns a safe const iterator pointing to the end of the List.

Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step

Returns a safe const iterator pointing to the end of the List.

Definition at line 1275 of file list_tpl.h.

1275 {
1276 return *(reinterpret_cast< const ListConstIteratorSafe< Val >* >(_list_end_safe_));
1277 }

References ListConstIteratorSafe< Val >.

Here is the call graph for this function:

◆ clear()

template<typename Val>
void gum::List< Val >::clear ( )

Deletes all the elements of a chained list.

All the iterators of the list will be resetted to rend. The method runs in linear time of both the size of the list and the number of iterators attached to the List.

Definition at line 1147 of file list_tpl.h.

1147 {
1148 // first we update all the safe iterators of the list : they should now
1149 // point to end/rend
1150 for (const auto ptr_iter: _safe_iterators_) {
1151 ptr_iter->clear();
1152 }
1153
1154 // clear all the values
1155 for (ListBucket< Val >*ptr = _deb_list_, *next_ptr = nullptr; ptr != nullptr; ptr = next_ptr) {
1156 next_ptr = ptr->_next_;
1157 delete ptr;
1158 }
1159
1160 _nb_elements_ = 0;
1161 _deb_list_ = nullptr;
1162 _end_list_ = nullptr;
1163 }

References _deb_list_, _end_list_, _nb_elements_, gum::ListBucket< Val >::_next_, and _safe_iterators_.

Referenced by ~List(), and operator=().

Here is the caller graph for this function:

◆ crbegin()

template<typename Val>
ListConstIterator< Val > gum::List< Val >::crbegin ( ) const

Returns an unsafe const iterator pointing to the last element of the List.

Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe const iterator pointing to the last element of the List.

Definition at line 1379 of file list_tpl.h.

1379 {
1381 else return ListConstIterator< Val >{};
1382 }

References _nb_elements_, and ListConstIterator< Val >.

Here is the call graph for this function:

◆ crbeginSafe()

template<typename Val>
ListConstIteratorSafe< Val > gum::List< Val >::crbeginSafe ( ) const

Returns a safe const iterator pointing to the last element of the List.

Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Returns
Returns a safe const iterator pointing to the last element of the List.

Definition at line 1365 of file list_tpl.h.

1365 {
1367 else return ListConstIteratorSafe< Val >{};
1368 }

References _nb_elements_, and ListConstIteratorSafe< Val >.

Here is the call graph for this function:

◆ crend()

template<typename Val>
const ListConstIterator< Val > & gum::List< Val >::crend ( ) const
noexcept

Returns an unsafe const iterator pointing just before the beginning of the List.

Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe const iterator pointing just before the beginning of the List

Definition at line 1317 of file list_tpl.h.

1317 {
1318 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1319 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ crendSafe()

template<typename Val>
const ListConstIteratorSafe< Val > & gum::List< Val >::crendSafe ( ) const
noexcept

Return a safe const iterator pointing just before the beginning of the List.

Safe const iterators are const iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Return a safe const iterator pointing just before the beginning of the List.

Definition at line 1305 of file list_tpl.h.

1305 {
1306 return *(reinterpret_cast< const ListConstIteratorSafe< Val >* >(_list_end_safe_));
1307 }

References ListConstIteratorSafe< Val >.

Here is the call graph for this function:

◆ emplace() [1/2]

template<typename Val>
template<typename... Args>
Val & gum::List< Val >::emplace ( const const_iterator & iter,
Args &&... args )

Emplace a new element before a given iterator.

Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs. The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.

Parameters
iterThe position in the list
argsThe arguments passed to the constructor
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1681 of file list_tpl.h.

1681 {
1683 }
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.
Definition list_tpl.h:1587
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.
Definition list_tpl.h:1413

References _createEmplaceBucket_(), _insert_(), and BEFORE.

Here is the call graph for this function:

◆ emplace() [2/2]

template<typename Val>
template<typename... Args>
Val & gum::List< Val >::emplace ( const const_iterator_safe & iter,
Args &&... args )

Emplace a new element before a given safe iterator.

Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs. The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.

Parameters
iterThe position in the list.
argsthe arguments passed to the constructor.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1688 of file list_tpl.h.

References _createEmplaceBucket_(), _insert_(), and BEFORE.

Here is the call graph for this function:

◆ emplaceBack()

template<typename Val>
template<typename... Args>
Val & gum::List< Val >::emplaceBack ( Args &&... args)

Emplace elements at the end of the chained list.

Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs

Template Parameters
ArgsThe emplaced arguments types.
Parameters
argsThe arguments passed to the constructor
Returns
A reference on the copy inserted into the list.

Definition at line 1501 of file list_tpl.h.

1501 {
1503 }

References _createEmplaceBucket_(), and _pushBack_().

Here is the call graph for this function:

◆ emplaceFront()

template<typename Val>
template<typename... Args>
Val & gum::List< Val >::emplaceFront ( Args &&... args)

Emplace elements at the beginning of the chained list.

Emplace is a method that allows to construct directly an element of type Val by passing to its constructor all the arguments it needs

Parameters
argsThe arguments passed to the constructor.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1475 of file list_tpl.h.

1475 {
1477 }
Val & _pushFront_(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition list_tpl.h:1420

References _createEmplaceBucket_(), and _pushFront_().

Here is the call graph for this function:

◆ empty()

◆ end() [1/2]

template<typename Val>
const ListConstIterator< Val > & gum::List< Val >::end ( ) const
noexcept

Returns an unsafe const iterator pointing to the end of the List.

Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe const iterator pointing to the end of the List.

Definition at line 1299 of file list_tpl.h.

1299 {
1300 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1301 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ end() [2/2]

template<typename Val>
const ListIterator< Val > & gum::List< Val >::end ( )
noexcept

Returns an unsafe iterator pointing to the end of the List.

Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe iterator pointing to the end of the List.

Definition at line 1293 of file list_tpl.h.

1293 {
1294 return *(reinterpret_cast< const ListIterator< Val >* >(_list_end_));
1295 }

References ListIterator< Val >.

Referenced by map(), map(), and map().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endSafe()

template<typename Val>
const ListIteratorSafe< Val > & gum::List< Val >::endSafe ( )
noexcept

Returns a safe iterator pointing to the end of the List.

Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Ceturns a safe iterator pointing to the end of the List.

Definition at line 1281 of file list_tpl.h.

1281 {
1282 return *(reinterpret_cast< const ListIteratorSafe< Val >* >(_list_end_safe_));
1283 }

References ListIteratorSafe< Val >.

Here is the call graph for this function:

◆ erase() [1/3]

template<typename Val>
void gum::List< Val >::erase ( const const_iterator_safe & iter)

Erases the element of the List pointed to by the safe const iterator.

If the element cannot be found, i.e., it has already been erased or the iterator points to end/rend, the function returns without throwing any exception. It runs in linear time in the size of the list.

Parameters
iterAn iterator pointing to the element to remove.

Definition at line 1778 of file list_tpl.h.

1778 {
1780 }
void _erase_(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition list_tpl.h:1725

References _erase_(), and gum::ListConstIteratorSafe< Val >::_getBucket_().

Here is the call graph for this function:

◆ erase() [2/3]

template<typename Val>
void gum::List< Val >::erase ( const iterator_safe & iter)

Erases the element of the List pointed to by the safe iterator.

If the element cannot be found, i.e., it has already been erased or the iterator points to end/rend, the function returns without throwing any exception. It runs in linear time in the size of the list.

Parameters
iterAn iterator pointing to the element to remove.

Definition at line 1772 of file list_tpl.h.

1772 {
1774 }

References _erase_(), and gum::ListConstIteratorSafe< Val >::_getBucket_().

Here is the call graph for this function:

◆ erase() [3/3]

template<typename Val>
void gum::List< Val >::erase ( Size i)

Erases the ith element of the List (the first one is in position 0).

If the element cannot be found, the function returns without throwing any exception. It runs in linear time in the size of the list.

Parameters
iThe position in the list of the element we wish to remove.

Definition at line 1763 of file list_tpl.h.

1763 {
1764 if (i >= _nb_elements_) return;
1765
1766 // erase the ith bucket
1768 }
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition list_tpl.h:1520

References _erase_(), _getIthBucket_(), and _nb_elements_.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseAllVal()

template<typename Val>
void gum::List< Val >::eraseAllVal ( const Val & val)

erases all the elements encountered with a given value

If no element equal to val can be found, the function returns without throwing any exception.

Comparisons between Val instances are performed through == operators.

Parameters
valthe value of the element we wish to remove.

Definition at line 1799 of file list_tpl.h.

1799 {
1800 for (ListBucket< Val >*iter = _deb_list_, *next_bucket = nullptr; iter != nullptr;
1801 iter = next_bucket) {
1802 next_bucket = iter->_next_;
1803
1804 if (val == iter->_val_) _erase_(iter);
1805 }
1806 }

References _deb_list_, and _erase_().

Here is the call graph for this function:

◆ eraseByVal()

template<typename Val>
void gum::List< Val >::eraseByVal ( const Val & val)

erases the first element encountered with a given value.

If no element equal to val can be found, the function returns without throwing any exception. It runs in linear time both in the size of the list and in the number of iterators referenced in the list. Comparisons between Val instances are performed through == operators.

Parameters
valThe value of the element we wish to remove.

Definition at line 1793 of file list_tpl.h.

1793 {
1795 }

References _erase_(), and _getBucket_().

Here is the call graph for this function:

◆ exists()

template<typename Val>
bool gum::List< Val >::exists ( const Val & val) const

Checks whether there exists a given element in the list.

This method runs in linear time.

Comparisons between Val instances are performed through == operators.

Parameters
valthe value of the element we wish to check the existence of.
Returns
Returns true if val is in the gum::List.

Definition at line 1716 of file list_tpl.h.

1716 {
1717 for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_)
1718 if (ptr->_val_ == val) return true;
1719
1720 return false;
1721 }

References _deb_list_, gum::ListBucket< Val >::_next_, and gum::ListBucket< Val >::_val_.

Referenced by gum::EssentialGraph::toDot(), gum::PDAG::toDot(), and gum::UndiGraph::toDot().

Here is the caller graph for this function:

◆ front()

template<typename Val>
Val & gum::List< Val >::front ( ) const

◆ insert() [1/8]

template<typename Val>
Val & gum::List< Val >::insert ( const const_iterator & iter,
const Val & val,
location place = location::BEFORE )

Inserts a new element before or after a given iterator.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1667 of file list_tpl.h.

1667 {
1669 }
ListBucket< Val > * _createBucket_(const Val &val) const
Create a new bucket with a given value.
Definition list_tpl.h:1400

References _createBucket_(), and _insert_().

Here is the call graph for this function:

◆ insert() [2/8]

template<typename Val>
Val & gum::List< Val >::insert ( const const_iterator & iter,
Val && val,
location place = location::BEFORE )

Inserts an rvalue before or after a given iterator.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1674 of file list_tpl.h.

1674 {
1676 }

References _createBucket_(), and _insert_().

Here is the call graph for this function:

◆ insert() [3/8]

template<typename Val>
Val & gum::List< Val >::insert ( const const_iterator_safe & iter,
const Val & val,
location place = location::BEFORE )

Inserts a new element before or after a given iterator.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1643 of file list_tpl.h.

1643 {
1644 // if the iterator does not point to the list, raise an exception
1645 if (iter._list_ != this) {
1646 GUM_ERROR(InvalidArgument, "the iterator does not point to the correct list")
1647 }
1648
1650 }

References _createBucket_(), _insert_(), gum::ListConstIteratorSafe< Val >::_list_, and GUM_ERROR.

Here is the call graph for this function:

◆ insert() [4/8]

template<typename Val>
Val & gum::List< Val >::insert ( const const_iterator_safe & iter,
Val && val,
location place = location::BEFORE )

Inserts an rvalue before or after a given iterator.

Parameters
iterThe iterator pointing where to inser the new element.
valThe value to insert.
placeDefines where to insert the new element relatively to iter.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1655 of file list_tpl.h.

1655 {
1656 // if the iterator does not point to the list, raise an exception
1657 if (iter._list_ != this) {
1658 GUM_ERROR(InvalidArgument, "the iterator does not point to the correct list")
1659 }
1660
1662 }

References _createBucket_(), _insert_(), gum::ListConstIteratorSafe< Val >::_list_, and GUM_ERROR.

Here is the call graph for this function:

◆ insert() [5/8]

template<typename Val>
Val & gum::List< Val >::insert ( const Val & val)

Inserts a new element at the end of the chained list (alias of pushBack).

Parameters
valThe value inserted.
Returns
a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1508 of file list_tpl.h.

1508 {
1509 return pushBack(val);
1510 }

References pushBack().

Referenced by gum::graph::_bayesBall_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesDownward_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesUpward_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_elimination_cost_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_insertEvidence_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenNodes(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::dSeparationAlgorithm::requisiteNodes(), gum::DAGCycleDetector::setDAG(), gum::EssentialGraph::toDot(), gum::PDAG::toDot(), and gum::UndiGraph::toDot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [6/8]

template<typename Val>
Val & gum::List< Val >::insert ( Size pos,
const Val & val )

Inserts a new element at the ith pos of the chained list.

The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.

Parameters
posThe position where to inser the new element.
valThe value to insert.
Returns
a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1568 of file list_tpl.h.

1568 {
1569 // if ther are fewer elements than pos, put the value at the end of the list
1570 if (_nb_elements_ <= pos) { return pushBack(val); }
1571
1573 }

References _createBucket_(), _getIthBucket_(), _insertBefore_(), _nb_elements_, and pushBack().

Here is the call graph for this function:

◆ insert() [7/8]

template<typename Val>
Val & gum::List< Val >::insert ( Size pos,
Val && val )

Insert an rvalue at the ith pos of the chained list.

The first element of the list is at pos 0. After the insert, the element is placed precisely at pos if pos is less than the size of the list before insertion, else it is inserted at the end of the list.

Parameters
posThe position where to inser the new element.
valThe value to insert.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1577 of file list_tpl.h.

1577 {
1578 // if ther are fewer elements than pos, put the value at the end of the list
1579 if (_nb_elements_ <= pos) { return pushBack(std::move(val)); }
1580
1582 }

References _createBucket_(), _getIthBucket_(), _insertBefore_(), _nb_elements_, and pushBack().

Here is the call graph for this function:

◆ insert() [8/8]

template<typename Val>
Val & gum::List< Val >::insert ( Val && val)

Inserts a new element at the end of the chained list (alias of pushBack).

Parameters
valThe value inserted.
Returns
a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1514 of file list_tpl.h.

1514 {
1515 return pushBack(std::move(val));
1516 }

References pushBack().

Here is the call graph for this function:

◆ map() [1/4]

template<typename Val>
template<typename Mount>
List< Mount > gum::List< Val >::map ( const Mount & mount) const

Creates a list of mountains with a given value from a list of val.

Parameters
mountthe value taken by all the elements of the resulting list
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.

Definition at line 1892 of file list_tpl.h.

1892 {
1893 // create a new empty list
1895
1896 // fill the new list
1897 for (Size i = Size(0); i < _nb_elements_; ++i)
1899
1900 return list;
1901 }

References List(), _nb_elements_, and pushBack().

Here is the call graph for this function:

◆ map() [2/4]

template<typename Val>
template<typename Mount>
List< Mount > gum::List< Val >::map ( Mount(* )(const Val &)) const

Creates a list of mountains from a list of val.

Parameters
fA function that maps any Val element into a Mount
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.

Definition at line 1877 of file list_tpl.h.

1877 {
1878 // create a new empty list
1880
1881 // fill the new list
1882 for (const_iterator iter = begin(); iter != end(); ++iter) {
1883 list.pushBack(f(*iter));
1884 }
1885
1886 return list;
1887 }

References List(), begin(), end(), and pushBack().

Here is the call graph for this function:

◆ map() [3/4]

template<typename Val>
template<typename Mount>
List< Mount > gum::List< Val >::map ( Mount(* )(Val &)) const

Creates a list of mountains from a list of val.

Parameters
fA function that maps any Val element into a Mount
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.

Definition at line 1862 of file list_tpl.h.

1862 {
1863 // create a new empty list
1865
1866 // fill the new list
1867 for (const_iterator iter = begin(); iter != end(); ++iter) {
1868 list.pushBack(f(*iter));
1869 }
1870
1871 return list;
1872 }

References List(), begin(), end(), and pushBack().

Here is the call graph for this function:

◆ map() [4/4]

template<typename Val>
template<typename Mount>
List< Mount > gum::List< Val >::map ( Mount(* )(Val)) const

Creates a list of mountains from a list of val.

Parameters
fA function that maps any Val element into a Mount
Returns
Returns a lsit of mountains.
Template Parameters
MountThe type of mountains.

Definition at line 1847 of file list_tpl.h.

1847 {
1848 // create a new empty list
1850
1851 // fill the new list
1852 for (const_iterator iter = begin(); iter != end(); ++iter) {
1853 list.pushBack(f(*iter));
1854 }
1855
1856 return list;
1857 }

References List(), begin(), end(), and pushBack().

Here is the call graph for this function:

◆ operator!=()

template<typename Val>
bool gum::List< Val >::operator!= ( const List< Val > & src) const

Checks whether two lists are different (different elements or orders).

This method runs in time linear in the number of elements of the list.

Returns
Returns true if src and this gum::List are identical.

Definition at line 1933 of file list_tpl.h.

1933 {
1934 return !operator==(src);
1935 }
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:243

References List(), and gum::operator==().

Here is the call graph for this function:

◆ operator+=() [1/2]

template<typename Val>
Val & gum::List< Val >::operator+= ( const Val & val)

Inserts a new element at the end of the list (alias of pushBack).

This enables writing code like list += xxx; to add element xxx to the list.

Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.
Parameters
valTha value inserted int the list.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1906 of file list_tpl.h.

1906 {
1907 return pushBack(val);
1908 }

References pushBack().

Here is the call graph for this function:

◆ operator+=() [2/2]

template<typename Val>
Val & gum::List< Val >::operator+= ( Val && val)

Inserts a new element at the end of the list (alias of pushBack).

This enables writing code like list += xxx; to add element xxx to the list.

Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.
Parameters
valTha value inserted int the list.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1913 of file list_tpl.h.

1913 {
1914 return pushBack(std::move(val));
1915 }

References pushBack().

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename Val>
List< Val > & gum::List< Val >::operator= ( const List< Val > & src)

Copy operator.

The new list and that which is copied do not share the elements: the new list contains new instances of the values stored in the list to be copied. Of course if these values are pointers, the new values point toward the same elements. The List on which the operator is applied keeps its iterator's list. Of course, if it previously contained some elements, those are removed prior to the copy. This operator runs in linear time.

Warning
If the current List previously contained iterators, those will be resetted to end()/rend().
Parameters
srcthe list the content of which will be copied into the current List.
Returns
Returns this gum::List.

Definition at line 1231 of file list_tpl.h.

1231 {
1232 // avoid self assignment
1233 if (this != &src) {
1234 // for debugging purposes
1236
1237 // remove the old content of 'this' and update accordingly the iterators
1238 clear();
1239
1240 // perform the copy
1242 }
1243
1244 return *this;
1245 }

References List().

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename Val>
List< Val > & gum::List< Val >::operator= ( List< Val > && src)

Move operator.

Parameters
srcThe gum::List to move.
Returns
Returns this gum::List.

Definition at line 1249 of file list_tpl.h.

1249 {
1250 // avoid self assignment
1251 if (this != &src) {
1252 // for debugging purposes
1254
1255 // remove the old content of 'this' and update accordingly the iterators
1256 clear();
1257
1258 // perform the move
1263
1264 src._deb_list_ = nullptr;
1265 src._end_list_ = nullptr;
1266 src._nb_elements_ = 0;
1267 src._safe_iterators_.clear();
1268 }
1269
1270 return *this;
1271 }

References List(), _deb_list_, _end_list_, _nb_elements_, _safe_iterators_, and clear().

Here is the call graph for this function:

◆ operator==()

template<typename Val>
bool gum::List< Val >::operator== ( const List< Val > & src) const

Checks whether two lists are identical (same elements in the same order).

This method runs in time linear in the number of elements of the list.

Returns
Returns true if src and this gum::List are identical.

Definition at line 1919 of file list_tpl.h.

1919 {
1920 // check if the two lists have at least the same number of elements
1921 if (_nb_elements_ != src._nb_elements_) return false;
1922
1923 // parse the two lists
1925 iter1 = iter1->_next_, iter2 = iter2->_next_)
1926 if (*iter1 != *iter2) return false;
1927
1928 return true;
1929 }

References List(), _deb_list_, and _nb_elements_.

Here is the call graph for this function:

◆ operator[]() [1/2]

template<typename Val>
Val & gum::List< Val >::operator[] ( const Size i)

Returns the ith element in the current chained list.

The first of the list element has index 0.

This method runs in linear time.

Parameters
iThe position of the element in the list (0 = first element).
Exceptions
NotFoundRaised if the element to be retrieved does not exist.
Returns
Returns a reference on the element stored at the ith position in the list.

Definition at line 1939 of file list_tpl.h.

1939 {
1940 // check if we can return the element we ask for
1941 if (i >= _nb_elements_) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1942
1943 return **_getIthBucket_(i);
1944 }

References _getIthBucket_(), _nb_elements_, and GUM_ERROR.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename Val>
const Val & gum::List< Val >::operator[] ( const Size i) const

Returns the const ith element in the current chained list.

The first of the list element has index 0.

This method runs in linear time.

Parameters
ithe position of the element in the list (0 = first element).
Exceptions
NotFoundRaised if the element to be retrieved does not exist.
Returns
Returns a reference on the element stored at the ith position in the list.

Definition at line 1948 of file list_tpl.h.

1948 {
1949 // check if we can return the element we ask for
1950 if (i >= _nb_elements_) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1951
1952 return **_getIthBucket_(i);
1953 }

References _getIthBucket_(), _nb_elements_, and GUM_ERROR.

Here is the call graph for this function:

◆ popBack()

template<typename Val>
void gum::List< Val >::popBack ( )

Removes the last element of a List, if any.

When the list is empty, it does not do anything.

Definition at line 1810 of file list_tpl.h.

1810 {
1812 }

References _end_list_, and _erase_().

Here is the call graph for this function:

◆ popFront()

template<typename Val>
void gum::List< Val >::popFront ( )

◆ push_back()

template<typename Val>
template<typename... Args>
Val & gum::List< Val >::push_back ( Args &&... args)

An alias for pushBack used for STL compliance.

Defining push_back allows using, for instance, BackInserters.

Template Parameters
ArgsThe emplace arguments type.
Parameters
argsThe emplace arguments values.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1494 of file list_tpl.h.

1494 {
1496 }

References pushBack().

Referenced by gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::AggregatorDecomposition< GUM_SCALAR >::addDepthLayer_(), and gum::AggregatorDecomposition< GUM_SCALAR >::decomposeAggregator_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_front()

template<typename Val>
template<typename... Args>
Val & gum::List< Val >::push_front ( Args &&... args)

An alias for pushFront used for STL compliance.

Defining push_front allows using, for instance, FrontInserters.

Template Parameters
ArgsThe emplace values type.
Parameters
argsThe emplace values.
Returns
Returns a reference on the copy inserted into the list.

Definition at line 1468 of file list_tpl.h.

1468 {
1470 }

References pushFront().

Here is the call graph for this function:

◆ pushBack() [1/2]

template<typename Val>
Val & gum::List< Val >::pushBack ( const Val & val)

Inserts a new element (a copy) at the end of the chained list.

The value passed in argument is not actually inserted into the list: this is a copy of this value that is inserted. The method runs in constant time.

Parameters
valThe value pushed back.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1481 of file list_tpl.h.

1481 {
1482 return _pushBack_(_createBucket_(val));
1483 }

References _createBucket_(), and _pushBack_().

Referenced by gum::learning::ConstraintBasedLearning::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::graph::directedPath(), gum::graph::directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_(), gum::graph::hasDirectedPath(), gum::graph::hasUndirectedCycle(), insert(), insert(), insert(), insert(), gum::Set< Key >::listMap(), map(), map(), map(), map(), gum::graph::mixedOrientedPath(), gum::graph::mixedUnorientedPath(), operator+=(), operator+=(), push_back(), and gum::graph::undirectedPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushBack() [2/2]

template<typename Val>
Val & gum::List< Val >::pushBack ( Val && val)

Inserts a new element (a move) at the end of the chained list.

The value passed in argument is not actually inserted into the list: this is a copy of this value that is inserted. The method runs in constant time.

Parameters
valThe value pushed back.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1487 of file list_tpl.h.

1487 {
1489 }

References _createBucket_(), and _pushBack_().

Here is the call graph for this function:

◆ pushFront() [1/2]

template<typename Val>
Val & gum::List< Val >::pushFront ( const Val & val)

Inserts a new element (a copy) at the beginning of the chained list.

The value passed in argument is not actually inserted into the list: this is a copy of this value that is inserted. The method runs in constant time.

Parameters
valThe valus pushed at the front.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1455 of file list_tpl.h.

1455 {
1457 }

References _createBucket_(), and _pushFront_().

Referenced by push_front().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushFront() [2/2]

template<typename Val>
Val & gum::List< Val >::pushFront ( Val && val)

Inserts a new element (a move) at the beginning of the chained list.

Parameters
valThe valus pushed at the front.
Returns
Returns a reference on the copy inserted into the list.
Warning
Note that val is not actually inserted into the list. Rather, it is a copy of val that is inserted.

Definition at line 1461 of file list_tpl.h.

1461 {
1463 }

References _createBucket_(), and _pushFront_().

Here is the call graph for this function:

◆ rbegin() [1/2]

template<typename Val>
ListIterator< Val > gum::List< Val >::rbegin ( )

Returns an unsafe iterator pointing to the last element of the List.

Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe iterator pointing to the last element of the List.

Definition at line 1386 of file list_tpl.h.

1386 {
1387 if (_nb_elements_) return ListIterator< Val >{*this, _nb_elements_ - 1};
1388 else return ListIterator< Val >{};
1389 }

References _nb_elements_, and ListIterator< Val >.

Here is the call graph for this function:

◆ rbegin() [2/2]

template<typename Val>
ListConstIterator< Val > gum::List< Val >::rbegin ( ) const

Returns an unsafe const iterator pointing to the last element of the List.

Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe const iterator pointing to the last element of the List.

Definition at line 1393 of file list_tpl.h.

1393 {
1395 else return ListConstIterator< Val >{};
1396 }

References _nb_elements_, and ListConstIterator< Val >.

Here is the call graph for this function:

◆ rbeginSafe()

template<typename Val>
ListIteratorSafe< Val > gum::List< Val >::rbeginSafe ( )

Returns a safe iterator pointing to the last element of the List.

Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Returns
Returns a safe iterator pointing to the last element of the List.

Definition at line 1372 of file list_tpl.h.

1372 {
1373 if (_nb_elements_) return ListIteratorSafe< Val >{*this, _nb_elements_ - 1};
1374 else return ListIteratorSafe< Val >{};
1375 }

References _nb_elements_, and ListIteratorSafe< Val >.

Here is the call graph for this function:

◆ rend() [1/2]

template<typename Val>
const ListConstIterator< Val > & gum::List< Val >::rend ( ) const
noexcept

Returns an unsafe const iterator pointing just before the beginning of the List.

Unsafe const iterators are a little bit faster than safe const iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns
Returns an unsafe const iterator pointing just before the beginning of the List.

Definition at line 1329 of file list_tpl.h.

1329 {
1330 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1331 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ rend() [2/2]

template<typename Val>
const ListIterator< Val > & gum::List< Val >::rend ( )
noexcept

Returns an unsafe iterator pointing just before the beginning of the List.

Unsafe iterators are a little bit faster than safe iterators and they consume less memory. However, if the element they point to is erased, their dereference or their increment/decrement will produce a mess, probably a segfault. You should use them only when performance is an issue and if you are sure that they will never point to an element erased.

Returns an unsafe iterator pointing just before the beginning of the List.

Definition at line 1323 of file list_tpl.h.

1323 {
1324 return *(reinterpret_cast< const ListIterator< Val >* >(_list_end_));
1325 }

References ListIterator< Val >.

Here is the call graph for this function:

◆ rendSafe()

template<typename Val>
const ListIteratorSafe< Val > & gum::List< Val >::rendSafe ( )
noexcept

Returns a safe iterator pointing just before the beginning of the List.

Safe iterators are iterators whose state is updated by the list when the element they point to is erased. As such, in this case, they can throw an exception when we try to derefence them and they are able to perform a valid ++ or – step.

Returns
Returns a safe iterator pointing just before the beginning of the List.

Definition at line 1311 of file list_tpl.h.

1311 {
1312 return *(reinterpret_cast< const ListIteratorSafe< Val >* >(_list_end_safe_));
1313 }

◆ size()

template<typename Val>
Size gum::List< Val >::size ( ) const
noexcept

Returns the number of elements in the list.

This method runs in constant time.

Definition at line 1710 of file list_tpl.h.

1710 {
1711 return _nb_elements_;
1712 }

References _nb_elements_.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::BayesNetFactory< GUM_SCALAR >::_increment_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_insertEvidence_(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

Here is the caller graph for this function:

◆ swap()

template<typename Val>
void gum::List< Val >::swap ( List< Val > & other_list)

Swap the current list with another one.

Parameters
other_listThe list to swap elements with.

Definition at line 1957 of file list_tpl.h.

References List(), _deb_list_, _end_list_, _nb_elements_, and _safe_iterators_.

Here is the call graph for this function:

◆ toString()

template<typename Val>
std::string gum::List< Val >::toString ( ) const

Converts a list into a string.

Returns
Returns a std::string representation of the gum::List.

Definition at line 1828 of file list_tpl.h.

1828 {
1829 bool deja = false;
1831 stream << "[";
1832
1833 for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_, deja = true) {
1834 if (deja) stream << " --> ";
1835
1836 stream << ptr->_val_;
1837 }
1838
1839 stream << "]";
1840
1841 return stream.str();
1842 }

References _deb_list_, gum::ListBucket< Val >::_next_, and gum::ListBucket< Val >::_val_.

Referenced by gum::operator<<().

Here is the caller graph for this function:

◆ ListConstIterator< Val >

template<typename Val>
friend class ListConstIterator< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1384 of file list.h.

Referenced by begin(), cbegin(), cend(), crbegin(), crend(), end(), rbegin(), and rend().

◆ ListConstIteratorSafe< Val >

template<typename Val>
friend class ListConstIteratorSafe< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1384 of file list.h.

Referenced by cbeginSafe(), cendSafe(), crbeginSafe(), and crendSafe().

◆ ListIterator< Val >

template<typename Val>
friend class ListIterator< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1384 of file list.h.

Referenced by begin(), end(), rbegin(), and rend().

◆ ListIteratorSafe< Val >

template<typename Val>
friend class ListIteratorSafe< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1384 of file list.h.

Referenced by endSafe(), and rbeginSafe().

Member Data Documentation

◆ _deb_list_

template<typename Val>
ListBucket< Val >* gum::List< Val >::_deb_list_ {nullptr}
private

A pointer on the first element of the chained list.

Definition at line 1253 of file list.h.

1253{nullptr};

Referenced by List(), _erase_(), _getBucket_(), _getIthBucket_(), _insertBefore_(), _pushBack_(), _pushFront_(), clear(), eraseAllVal(), exists(), front(), gum::List< gum::Instantiation * >::map(), operator=(), operator==(), popFront(), swap(), and toString().

◆ _end_list_

template<typename Val>
ListBucket< Val >* gum::List< Val >::_end_list_ {nullptr}
private

A pointer on the last element of the chained list.

Definition at line 1256 of file list.h.

1256{nullptr};

Referenced by _erase_(), _getIthBucket_(), _insertAfter_(), _pushBack_(), _pushFront_(), back(), clear(), operator=(), popBack(), and swap().

◆ _nb_elements_

◆ _safe_iterators_

template<typename Val>
std::vector< const_iterator_safe* > gum::List< Val >::_safe_iterators_
mutableprivate

The list of "safe" iterators attached to the list.

Definition at line 1262 of file list.h.

Referenced by List(), _erase_(), clear(), operator=(), and swap().


The documentation for this class was generated from the following files: