aGrUM 2.3.2
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

template<typename... Args>
INLINE ListBucket< Val > * _createEmplaceBucket_ (Args &&... args) const
template<typename... Args>
INLINE Val & push_front (Args &&... args)
template<typename... Args>
INLINE Val & emplaceFront (Args &&... args)
template<typename... Args>
INLINE Val & push_back (Args &&... args)
template<typename... Args>
INLINE Val & emplaceBack (Args &&... args)
template<typename... Args>
INLINE Val & emplace (const const_iterator &iter, Args &&... args)
template<typename... Args>
INLINE Val & emplace (const const_iterator_safe &iter, Args &&... args)
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:379
void eraseByVal(const Val &val)
erases the first element encountered with a given value.
Definition list_tpl.h:1802
const_iterator cbegin() const
Returns an unsafe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1354
const_iterator crbegin() const
Returns an unsafe const iterator pointing to the last element of the List.
Definition list_tpl.h:1386
const iterator_safe & endSafe() noexcept
Returns a safe iterator pointing to the end of the List.
Definition list_tpl.h:1288
Val & front() const
Returns a reference to first element of a list, if any.
Definition list_tpl.h:1703
ListConstIteratorSafe< Val > const_iterator_safe
Types for STL compliance.
Definition list.h:393
const const_iterator_safe & crendSafe() const noexcept
Return a safe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1312
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
Definition list_tpl.h:1462
List()
A basic constructor that creates an empty list.
Definition list_tpl.h:1174
void popBack()
Removes the last element of a List, if any.
Definition list_tpl.h:1819
Size size() const noexcept
Returns the number of elements in the list.
Definition list_tpl.h:1719
void clear()
Deletes all the elements of a chained list.
Definition list_tpl.h:1154
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition list_tpl.h:1831
ListIterator< Val > iterator
Types for STL compliance.
Definition list.h:390
iterator_safe rbeginSafe()
Returns a safe iterator pointing to the last element of the List.
Definition list_tpl.h:1379
List< Mount > map(Mount(*f)(Val)) const
Creates a list of mountains from a list of val.
Definition list_tpl.h:1856
iterator rbegin()
Returns an unsafe iterator pointing to the last element of the List.
Definition list_tpl.h:1393
const iterator & rend() noexcept
Returns an unsafe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1330
const const_iterator & cend() const noexcept
Returns an unsafe const iterator pointing to the end of the List.
Definition list_tpl.h:1294
const iterator_safe & rendSafe() noexcept
Returns a safe iterator pointing just before the beginning of the List.
Definition list_tpl.h:1318
void popFront()
Removes the first element of a List, if any.
Definition list_tpl.h:1825
const const_iterator & crend() const noexcept
Returns an unsafe const iterator pointing just before the beginning of the List.
Definition list_tpl.h:1324
const_iterator_safe crbeginSafe() const
Returns a safe const iterator pointing to the last element of the List.
Definition list_tpl.h:1372
const const_iterator_safe & cendSafe() const noexcept
Returns a safe const iterator pointing to the end of the List.
Definition list_tpl.h:1282
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
Definition list.h:392
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition list_tpl.h:1300
iterator_safe beginSafe()
Returns a safe iterator pointing to the beginning of the List.
Definition list_tpl.h:1348
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Definition list_tpl.h:1515
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition list_tpl.h:1360
const_iterator_safe cbeginSafe() const
Returns a safe const iterator pointing to the beginning of the List.
Definition list_tpl.h:1342
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1488
Val & back() const
Returns a reference to last element of a list, if any.
Definition list_tpl.h:1711
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
Definition list_tpl.h:1772
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition list.h:391
Template Parameters
ValThe values type stored in the gum::List.

Definition at line 379 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 391 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 393 of file list.h.

◆ const_pointer

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

Types for STL compliance.

Definition at line 387 of file list.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 385 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 389 of file list.h.

◆ iterator

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

Types for STL compliance.

Definition at line 390 of file list.h.

◆ iterator_safe

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

Types for STL compliance.

Definition at line 392 of file list.h.

◆ pointer

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

Types for STL compliance.

Definition at line 386 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 384 of file list.h.

◆ size_type

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

Types for STL compliance.

Definition at line 388 of file list.h.

◆ value_type

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

Types for STL compliance.

Definition at line 383 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 398 of file list.h.

398{ BEFORE, AFTER };

Constructor & Destructor Documentation

◆ List() [1/4]

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

A basic constructor that creates an empty list.

Definition at line 1174 of file list_tpl.h.

1174 {
1175 // for debugging purposes
1177
1178 // reserve space for only the default number of iterators
1180 }
std::vector< const_iterator_safe * > _safe_iterators_
The list of "safe" iterators attached to the list.
Definition list.h:1263

References List(), _safe_iterators_, and GUM_DEFAULT_ITERATOR_NUMBER.

Referenced by List(), List(), List(), List(), ~List(), _copy_elements_(), emplace(), 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>
INLINE 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 1184 of file list_tpl.h.

1184 {
1185 // for debugging purposes
1187
1188 // copy the elements
1190
1191 // reserve space for only the default number of iterators
1193 }
void _copy_elements_(const List< Val > &src)
A function used to perform copies of elements of Lists.
Definition list_tpl.h:1115

References List().

Here is the call graph for this function:

◆ List() [3/4]

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

Move constructor.

Parameters
srcThe gum::List to move.

Definition at line 1197 of file list_tpl.h.

1197 :
1201 // for debugging purposes
1203
1204 src._deb_list_ = nullptr;
1205 src._end_list_ = nullptr;
1206 src._nb_elements_ = 0;
1207 src._safe_iterators_.clear();
1208 }
ListBucket< Val > * _deb_list_
A pointer on the first element of the chained list.
Definition list.h:1254
Size _nb_elements_
The number of elements in the list.
Definition list.h:1260
ListBucket< Val > * _end_list_
A pointer on the last element of the chained list.
Definition list.h:1257

References List(), and _deb_list_.

Here is the call graph for this function:

◆ List() [4/4]

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

Initializer_list constructor.

Parameters
listThe initializer list.

Definition at line 1212 of file list_tpl.h.

1212 {
1213 // for debugging purposes
1215
1216 // adding all the elements
1217 for (const auto& val: list) {
1218 pushBack(val);
1219 }
1220
1221 // reserve space for only the default number of iterators
1223 }

References List(), and pushBack().

Here is the call graph for this function:

◆ ~List()

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

Class destructor.

Definition at line 1227 of file list_tpl.h.

1227 {
1228 // for debugging (although this program is bug-free)
1230
1231 // we detach all the safe iterators attached to the current List and we
1232 // remove all the elements from the list
1233 clear();
1234 }

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 1115 of file list_tpl.h.

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

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

Referenced by operator=().

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

◆ _createBucket_() [1/2]

template<typename Val>
INLINE 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 1407 of file list_tpl.h.

1407 {
1408 return new ListBucket< Val >(val);
1409 }

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>
INLINE 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 1413 of file list_tpl.h.

1413 {
1414 return new ListBucket< Val >(std::move(val));
1415 }

◆ _createEmplaceBucket_() [1/2]

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.

◆ _createEmplaceBucket_() [2/2]

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

Definition at line 1420 of file list_tpl.h.

◆ _erase_()

template<typename Val>
INLINE 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 1734 of file list_tpl.h.

1734 {
1735 // perform deletion only if there is a bucket to remove
1736 if (bucket != nullptr) {
1737 // update the iterators pointing on this element
1738 for (const auto ptr_iter: _safe_iterators_) {
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;
1744 } else {
1745 if (ptr_iter->_null_pointing_) {
1746 if (ptr_iter->_next_current_bucket_ == bucket)
1747 ptr_iter->_next_current_bucket_ = bucket->_prev_;
1748
1749 if (ptr_iter->_prev_current_bucket_ == bucket)
1750 ptr_iter->_prev_current_bucket_ = bucket->_next_;
1751 }
1752 }
1753 }
1754
1755 // set properly the begin and end of the chained list (the other chainings
1756 // will be performed by operator delete)
1757 if (bucket->_prev_ == nullptr) _deb_list_ = bucket->_next_;
1758 else bucket->_prev_->_next_ = bucket->_next_;
1759
1760 if (bucket->_next_ == nullptr) _end_list_ = bucket->_prev_;
1761 else bucket->_next_->_prev_ = bucket->_prev_;
1762
1763 // remove the current element src the list
1764 delete bucket;
1765
1766 --_nb_elements_;
1767 }
1768 }

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>
INLINE 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 1793 of file list_tpl.h.

1793 {
1794 for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_)
1795 if (ptr->_val_ == val) return ptr;
1796
1797 return nullptr;
1798 }

References _deb_list_.

Referenced by eraseByVal().

Here is the caller graph for this function:

◆ _getIthBucket_()

template<typename Val>
INLINE 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 1527 of file list_tpl.h.

1527 {
1529
1530 if (i < _nb_elements_ / 2) {
1531 for (ptr = _deb_list_; i; --i, ptr = ptr->_next_) {}
1532 } else {
1533 for (ptr = _end_list_, i = _nb_elements_ - i - 1; i; --i, ptr = ptr->_prev_) {}
1534 }
1535
1536 return ptr;
1537 }

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>
INLINE 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 1629 of file list_tpl.h.

1631 {
1632 // find the location around which the new element should be inserted
1634
1635 if (ptr == nullptr) {
1636 // here, we are at the end of the list
1637 return _pushBack_(new_elt);
1638 } else {
1639 switch (place) {
1641
1642 case location::AFTER : return _insertAfter_(new_elt, ptr);
1643
1644 default : GUM_ERROR(FatalError, "List insertion for this location unimplemented")
1645 }
1646 }
1647 }
ListBucket< Val > * _getBucket_(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition list_tpl.h:1793
Val & _insertBefore_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition list_tpl.h:1541
Val & _insertAfter_(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition list_tpl.h:1559
Val & _pushBack_(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition list_tpl.h:1444
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

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>
INLINE 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 1596 of file list_tpl.h.

1598 {
1599 // find the location around which the new element should be inserted
1601
1602 if (iter._null_pointing_) {
1603 if (place == location::BEFORE) {
1604 ptr = iter._next_current_bucket_;
1605 } else {
1606 ptr = iter._prev_current_bucket_;
1607 }
1608 } else {
1609 ptr = iter._getBucket_();
1610 }
1611
1612 if (ptr == nullptr) {
1613 // here, we are at the end of the list
1614 return _pushBack_(new_elt);
1615 } else {
1616 switch (place) {
1618
1619 case location::AFTER : return _insertAfter_(new_elt, ptr);
1620
1621 default : GUM_ERROR(FatalError, "List insertion for this location unimplemented")
1622 }
1623 }
1624 }

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 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>
INLINE 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 1559 of file list_tpl.h.

1560 {
1561 new_elt->_prev_ = current_elt;
1562 new_elt->_next_ = current_elt->_next_;
1563 current_elt->_next_ = new_elt;
1564
1565 if (new_elt->_next_ == nullptr) _end_list_ = new_elt;
1566 else new_elt->_next_->_prev_ = new_elt;
1567
1568 // update the number of elements
1569 ++_nb_elements_;
1570
1571 // returns the current value
1572 return new_elt->_val_;
1573 }

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>
INLINE 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 1541 of file list_tpl.h.

1542 {
1543 new_elt->_next_ = current_elt;
1544 new_elt->_prev_ = current_elt->_prev_;
1545 current_elt->_prev_ = new_elt;
1546
1547 if (new_elt->_prev_ == nullptr) _deb_list_ = new_elt;
1548 else new_elt->_prev_->_next_ = new_elt;
1549
1550 // update the number of elements
1551 ++_nb_elements_;
1552
1553 // returns the current value
1554 return new_elt->_val_;
1555 }

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>
INLINE 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 1444 of file list_tpl.h.

1444 {
1445 // place the bucket at the end of the list
1446 new_elt->_prev_ = _end_list_;
1447
1448 if (_end_list_ != nullptr) _end_list_->_next_ = new_elt;
1449 else _deb_list_ = new_elt;
1450
1452
1453 // update the number of elements
1454 ++_nb_elements_;
1455
1456 // returns the current value
1457 return new_elt->_val_;
1458 }

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

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

Here is the caller graph for this function:

◆ _pushFront_()

template<typename Val>
INLINE 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 1427 of file list_tpl.h.

1427 {
1428 new_elt->_next_ = _deb_list_;
1429
1430 if (_deb_list_ != nullptr) _deb_list_->_prev_ = new_elt;
1431 else _end_list_ = new_elt;
1432
1434
1435 // update the number of elements
1436 ++_nb_elements_;
1437
1438 // return the inserted element
1439 return new_elt->_val_;
1440 }

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

Referenced by pushFront(), and pushFront().

Here is the caller graph for this function:

◆ back()

template<typename Val>
INLINE 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 1711 of file list_tpl.h.

1711 {
1712 if (_nb_elements_ == Size(0)) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1713
1714 return _end_list_->_val_;
1715 }

References _end_list_, _nb_elements_, and GUM_ERROR.

Referenced by emplace().

Here is the caller graph for this function:

◆ begin() [1/2]

template<typename Val>
INLINE 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 1360 of file list_tpl.h.

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

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>
INLINE 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 1366 of file list_tpl.h.

1366 {
1367 return ListConstIterator< Val >{*this};
1368 }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1390

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ beginSafe()

template<typename Val>
INLINE 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 1348 of file list_tpl.h.

1348 {
1349 return ListIteratorSafe< Val >{*this};
1350 }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition list.h:1391

References ListIteratorSafe< Val >.

Here is the call graph for this function:

◆ cbegin()

template<typename Val>
INLINE 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 1354 of file list_tpl.h.

1354 {
1355 return ListConstIterator< Val >{*this};
1356 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ cbeginSafe()

template<typename Val>
INLINE 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 1342 of file list_tpl.h.

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

◆ cend()

template<typename Val>
INLINE 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 1294 of file list_tpl.h.

1294 {
1295 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1296 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ cendSafe()

template<typename Val>
INLINE 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 1282 of file list_tpl.h.

1282 {
1283 return *(reinterpret_cast< const ListConstIteratorSafe< Val >* >(_list_end_safe_));
1284 }

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 1154 of file list_tpl.h.

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

References _deb_list_, and _safe_iterators_.

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

Here is the caller graph for this function:

◆ crbegin()

template<typename Val>
INLINE 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 1386 of file list_tpl.h.

1386 {
1388 else return ListConstIterator< Val >{};
1389 }

References _nb_elements_, and ListConstIterator< Val >.

Here is the call graph for this function:

◆ crbeginSafe()

template<typename Val>
INLINE 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 1372 of file list_tpl.h.

1372 {
1374 else return ListConstIteratorSafe< Val >{};
1375 }

References _nb_elements_, and ListConstIteratorSafe< Val >.

Here is the call graph for this function:

◆ crend()

template<typename Val>
INLINE 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 1324 of file list_tpl.h.

1324 {
1325 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1326 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ crendSafe()

template<typename Val>
INLINE 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 1312 of file list_tpl.h.

1312 {
1313 return *(reinterpret_cast< const ListConstIteratorSafe< Val >* >(_list_end_safe_));
1314 }

◆ emplace() [1/4]

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.

References emplace().

Referenced by emplace(), and emplace().

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

◆ emplace() [2/4]

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

Definition at line 1690 of file list_tpl.h.

1690 {
1692 }
ListBucket< Val > * _createEmplaceBucket_(Args &&... args) const
Create an emplace bucket.
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:1596

◆ emplace() [3/4]

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.

References List(), back(), clear(), emplace(), empty(), erase(), eraseAllVal(), eraseByVal(), exists(), front(), map(), popBack(), popFront(), size(), swap(), and toString().

Here is the call graph for this function:

◆ emplace() [4/4]

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

Definition at line 1697 of file list_tpl.h.

◆ emplaceBack() [1/2]

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.

References emplaceBack(), and insert().

Referenced by emplaceBack().

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

◆ emplaceBack() [2/2]

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

Definition at line 1508 of file list_tpl.h.

1508 {
1510 }

◆ emplaceFront() [1/2]

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.

References emplaceFront(), and pushBack().

Referenced by emplaceFront().

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

◆ emplaceFront() [2/2]

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

Definition at line 1482 of file list_tpl.h.

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

◆ empty()

template<typename Val>
INLINE bool gum::List< Val >::empty ( ) const
noexcept

◆ end() [1/2]

template<typename Val>
INLINE 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 1306 of file list_tpl.h.

1306 {
1307 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1308 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ end() [2/2]

template<typename Val>
INLINE 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 1300 of file list_tpl.h.

1300 {
1301 return *(reinterpret_cast< const ListIterator< Val >* >(_list_end_));
1302 }

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>
INLINE 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 1288 of file list_tpl.h.

1288 {
1289 return *(reinterpret_cast< const ListIteratorSafe< Val >* >(_list_end_safe_));
1290 }

References ListIteratorSafe< Val >.

Here is the call graph for this function:

◆ erase() [1/3]

template<typename Val>
INLINE 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 1787 of file list_tpl.h.

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

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

Here is the call graph for this function:

◆ erase() [2/3]

template<typename Val>
INLINE 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 1781 of file list_tpl.h.

1781 {
1783 }

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

Here is the call graph for this function:

◆ erase() [3/3]

template<typename Val>
INLINE 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 1772 of file list_tpl.h.

1772 {
1773 if (i >= _nb_elements_) return;
1774
1775 // erase the ith bucket
1777 }
ListBucket< Val > * _getIthBucket_(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition list_tpl.h:1527

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

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

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

◆ eraseAllVal()

template<typename Val>
INLINE 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 1808 of file list_tpl.h.

1808 {
1809 for (ListBucket< Val >*iter = _deb_list_, *next_bucket = nullptr; iter != nullptr;
1810 iter = next_bucket) {
1811 next_bucket = iter->_next_;
1812
1813 if (val == iter->_val_) _erase_(iter);
1814 }
1815 }

References _deb_list_, and _erase_().

Referenced by emplace().

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

◆ eraseByVal()

template<typename Val>
INLINE 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 1802 of file list_tpl.h.

1802 {
1804 }

References _erase_(), and _getBucket_().

Referenced by emplace().

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

◆ exists()

template<typename Val>
INLINE 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 1725 of file list_tpl.h.

1725 {
1726 for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_)
1727 if (ptr->_val_ == val) return true;
1728
1729 return false;
1730 }

References _deb_list_.

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

Here is the caller graph for this function:

◆ front()

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

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

Exceptions
NotFoundexception is thrown if the list is empty.

Definition at line 1703 of file list_tpl.h.

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

References _deb_list_, _nb_elements_, and GUM_ERROR.

Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesDownward_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), emplace(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_(), gum::DiGraph::hasDirectedPath(), gum::MixedGraph::hasMixedOrientedPath(), gum::UndiGraph::hasUndirectedCycle(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::DAGCycleDetector::setDAG(), and gum::EdgeGraphPart::undirectedPath().

Here is the caller graph for this function:

◆ insert() [1/8]

template<typename Val>
INLINE 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 1676 of file list_tpl.h.

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

References _createBucket_(), and _insert_().

Here is the call graph for this function:

◆ insert() [2/8]

template<typename Val>
INLINE 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 1683 of file list_tpl.h.

1683 {
1685 }

References _createBucket_(), and _insert_().

Here is the call graph for this function:

◆ insert() [3/8]

template<typename Val>
INLINE 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 1652 of file list_tpl.h.

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

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

Here is the call graph for this function:

◆ insert() [4/8]

template<typename Val>
INLINE 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 1664 of file list_tpl.h.

1664 {
1665 // if the iterator does not point to the list, raise an exception
1666 if (iter._list_ != this) {
1667 GUM_ERROR(InvalidArgument, "the iterator does not point to the correct list")
1668 }
1669
1671 }

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

Here is the call graph for this function:

◆ insert() [5/8]

template<typename Val>
INLINE 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 1515 of file list_tpl.h.

1515 {
1516 return pushBack(val);
1517 }

References pushBack().

Referenced by 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(), emplaceBack(), gum::UndiGraph::hasUndirectedCycle(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::BayesBall::requisiteNodes(), 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>
INLINE 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 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(val); }
1580
1582 }

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

Here is the call graph for this function:

◆ insert() [7/8]

template<typename Val>
INLINE 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 1586 of file list_tpl.h.

1586 {
1587 // if ther are fewer elements than pos, put the value at the end of the list
1588 if (_nb_elements_ <= pos) { return pushBack(std::move(val)); }
1589
1591 }

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

Here is the call graph for this function:

◆ insert() [8/8]

template<typename Val>
INLINE 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 1521 of file list_tpl.h.

1521 {
1522 return pushBack(std::move(val));
1523 }

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 1901 of file list_tpl.h.

1901 {
1902 // create a new empty list
1904
1905 // fill the new list
1906 for (Size i = Size(0); i < _nb_elements_; ++i)
1908
1909 return list;
1910 }

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 1886 of file list_tpl.h.

1886 {
1887 // create a new empty list
1889
1890 // fill the new list
1891 for (const_iterator iter = begin(); iter != end(); ++iter) {
1892 list.pushBack(f(*iter));
1893 }
1894
1895 return list;
1896 }

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 1871 of file list_tpl.h.

1871 {
1872 // create a new empty list
1874
1875 // fill the new list
1876 for (const_iterator iter = begin(); iter != end(); ++iter) {
1877 list.pushBack(f(*iter));
1878 }
1879
1880 return list;
1881 }

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 1856 of file list_tpl.h.

1856 {
1857 // create a new empty list
1859
1860 // fill the new list
1861 for (const_iterator iter = begin(); iter != end(); ++iter) {
1862 list.pushBack(f(*iter));
1863 }
1864
1865 return list;
1866 }

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

Referenced by emplace().

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

◆ operator!=()

template<typename Val>
INLINE 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 1942 of file list_tpl.h.

1942 {
1943 return !operator==(src);
1944 }
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>
INLINE 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 1915 of file list_tpl.h.

1915 {
1916 return pushBack(val);
1917 }

References pushBack().

Here is the call graph for this function:

◆ operator+=() [2/2]

template<typename Val>
INLINE 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 1922 of file list_tpl.h.

1922 {
1923 return pushBack(std::move(val));
1924 }

References pushBack().

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename Val>
INLINE 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 1238 of file list_tpl.h.

1238 {
1239 // avoid self assignment
1240 if (this != &src) {
1241 // for debugging purposes
1243
1244 // remove the old content of 'this' and update accordingly the iterators
1245 clear();
1246
1247 // perform the copy
1249 }
1250
1251 return *this;
1252 }

References List(), _copy_elements_(), and clear().

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename Val>
INLINE 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 1256 of file list_tpl.h.

1256 {
1257 // avoid self assignment
1258 if (this != &src) {
1259 // for debugging purposes
1261
1262 // remove the old content of 'this' and update accordingly the iterators
1263 clear();
1264
1265 // perform the move
1270
1271 src._deb_list_ = nullptr;
1272 src._end_list_ = nullptr;
1273 src._nb_elements_ = 0;
1274 src._safe_iterators_.clear();
1275 }
1276
1277 return *this;
1278 }

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

Here is the call graph for this function:

◆ operator==()

template<typename Val>
INLINE 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 1928 of file list_tpl.h.

1928 {
1929 // check if the two lists have at least the same number of elements
1930 if (_nb_elements_ != src._nb_elements_) return false;
1931
1932 // parse the two lists
1934 iter1 = iter1->_next_, iter2 = iter2->_next_)
1935 if (*iter1 != *iter2) return false;
1936
1937 return true;
1938 }

References List(), _deb_list_, and _nb_elements_.

Here is the call graph for this function:

◆ operator[]() [1/2]

template<typename Val>
INLINE 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 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:

◆ operator[]() [2/2]

template<typename Val>
INLINE 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 1957 of file list_tpl.h.

1957 {
1958 // check if we can return the element we ask for
1959 if (i >= _nb_elements_) { GUM_ERROR(NotFound, "not enough elements in the chained list") }
1960
1961 return **_getIthBucket_(i);
1962 }

References _getIthBucket_(), _nb_elements_, and GUM_ERROR.

Here is the call graph for this function:

◆ popBack()

template<typename Val>
INLINE 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 1819 of file list_tpl.h.

1819 {
1821 }

References _end_list_, and _erase_().

Referenced by emplace().

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

◆ popFront()

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

Removes the first element of a List, if any.

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

Definition at line 1825 of file list_tpl.h.

1825 {
1827 }

References _deb_list_, and _erase_().

Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesDownward_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), emplace(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_(), gum::DiGraph::hasDirectedPath(), gum::MixedGraph::hasMixedOrientedPath(), gum::UndiGraph::hasUndirectedCycle(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::DAGCycleDetector::setDAG(), and gum::EdgeGraphPart::undirectedPath().

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

◆ push_back() [1/2]

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.

References push_back().

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

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

◆ push_back() [2/2]

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

Definition at line 1501 of file list_tpl.h.

1501 {
1503 }

◆ push_front() [1/2]

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.

References push_front().

Referenced by push_front().

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

◆ push_front() [2/2]

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

Definition at line 1475 of file list_tpl.h.

1475 {
1477 }

◆ pushBack() [1/2]

template<typename Val>
INLINE 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 1488 of file list_tpl.h.

1488 {
1489 return _pushBack_(_createBucket_(val));
1490 }

References _createBucket_(), and _pushBack_().

Referenced by List(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), emplaceFront(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_(), gum::DiGraph::hasDirectedPath(), gum::MixedGraph::hasMixedOrientedPath(), insert(), insert(), insert(), insert(), gum::Set< Key >::listMap(), map(), map(), map(), map(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), operator+=(), operator+=(), and gum::EdgeGraphPart::undirectedPath().

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

◆ pushBack() [2/2]

template<typename Val>
INLINE 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 1494 of file list_tpl.h.

1494 {
1496 }

References _createBucket_(), and _pushBack_().

Here is the call graph for this function:

◆ pushFront() [1/2]

template<typename Val>
INLINE 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 1462 of file list_tpl.h.

1462 {
1464 }

References _createBucket_(), and _pushFront_().

Here is the call graph for this function:

◆ pushFront() [2/2]

template<typename Val>
INLINE 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 1468 of file list_tpl.h.

1468 {
1470 }

References _createBucket_(), and _pushFront_().

Here is the call graph for this function:

◆ rbegin() [1/2]

template<typename Val>
INLINE 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 1393 of file list_tpl.h.

1393 {
1394 if (_nb_elements_) return ListIterator< Val >{*this, _nb_elements_ - 1};
1395 else return ListIterator< Val >{};
1396 }

References _nb_elements_, and ListIterator< Val >.

Here is the call graph for this function:

◆ rbegin() [2/2]

template<typename Val>
INLINE 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 1400 of file list_tpl.h.

1400 {
1402 else return ListConstIterator< Val >{};
1403 }

References _nb_elements_, and ListConstIterator< Val >.

Here is the call graph for this function:

◆ rbeginSafe()

template<typename Val>
INLINE 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 1379 of file list_tpl.h.

1379 {
1380 if (_nb_elements_) return ListIteratorSafe< Val >{*this, _nb_elements_ - 1};
1381 else return ListIteratorSafe< Val >{};
1382 }

References _nb_elements_, and ListIteratorSafe< Val >.

Here is the call graph for this function:

◆ rend() [1/2]

template<typename Val>
INLINE 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 1336 of file list_tpl.h.

1336 {
1337 return *(reinterpret_cast< const ListConstIterator< Val >* >(_list_end_));
1338 }

References ListConstIterator< Val >.

Here is the call graph for this function:

◆ rend() [2/2]

template<typename Val>
INLINE 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 1330 of file list_tpl.h.

1330 {
1331 return *(reinterpret_cast< const ListIterator< Val >* >(_list_end_));
1332 }

References ListIterator< Val >.

Here is the call graph for this function:

◆ rendSafe()

template<typename Val>
INLINE 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 1318 of file list_tpl.h.

1318 {
1319 return *(reinterpret_cast< const ListIteratorSafe< Val >* >(_list_end_safe_));
1320 }

References ListIteratorSafe< Val >.

Here is the call graph for this function:

◆ size()

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

Returns the number of elements in the list.

This method runs in constant time.

Definition at line 1719 of file list_tpl.h.

1719 {
1720 return _nb_elements_;
1721 }

References _nb_elements_.

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

Here is the caller graph for this function:

◆ swap()

template<typename Val>
INLINE 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 1966 of file list_tpl.h.

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

Referenced by emplace().

Here is the call graph for this function:
Here is the caller 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 1837 of file list_tpl.h.

1837 {
1838 bool deja = false;
1840 stream << "[";
1841
1842 for (ListBucket< Val >* ptr = _deb_list_; ptr != nullptr; ptr = ptr->_next_, deja = true) {
1843 if (deja) stream << " --> ";
1844
1845 stream << ptr->_val_;
1846 }
1847
1848 stream << "]";
1849
1850 return stream.str();
1851 }

References _deb_list_.

Referenced by emplace(), and 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 1385 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 1385 of file list.h.

Referenced by cendSafe(), and crbeginSafe().

◆ ListIterator< Val >

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

ListIterator should be a friend to optimize access to elements.

Definition at line 1385 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 1385 of file list.h.

Referenced by beginSafe(), endSafe(), rbeginSafe(), and rendSafe().

Member Data Documentation

◆ _deb_list_

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

◆ _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 1257 of file list.h.

1257{nullptr};

Referenced by _copy_elements_(), _erase_(), _getIthBucket_(), _insertAfter_(), _pushBack_(), _pushFront_(), back(), 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 1263 of file list.h.

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


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