aGrUM  0.16.0
gum::List< Val, Alloc > Class Template Reference

Generic doubly linked lists. More...

#include <agrum/core/list.h>

Public Member Functions

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

Public Types

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

Friends

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

Detailed Description

template<typename Val, typename Alloc = std::allocator< Val >>
class gum::List< Val, Alloc >

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;
for (List<int>::iterator_safe iter = list2.rbeginSafe();
iter != list2.rendSafe(); --iter)
cerr << *iter << endl;
for (List<int>::const_iterator_safe iter = list2.cbeginSafe();
iter != list2.cendSafe(); ++iter)
cerr << *iter << endl;
for (List<int>::const_iterator_safe iter = list2.crbeginSafe();
iter != list2.crendSafe(); --iter)
cerr << *iter << endl;
// use an iterator to point the element we wish to erase
List<int>::iterator_safe iter = list2.beginSafe();
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);
Template Parameters
ValThe values type stored in the gum::List.
AllocThe allocator for the values stored in the gum::List.

Definition at line 372 of file list.h.

Member Typedef Documentation

◆ allocator_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::allocator_type = Alloc

Types for STL compliance.

Definition at line 383 of file list.h.

◆ BucketAllocator

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::BucketAllocator = typename Alloc::template rebind< ListBucket< Val > >::other

Type of the allocator for ListBuckets.

Definition at line 392 of file list.h.

◆ const_iterator

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_iterator = ListConstIterator< Val >

Types for STL compliance.

Definition at line 385 of file list.h.

◆ const_iterator_safe

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_iterator_safe = ListConstIteratorSafe< Val >

Types for STL compliance.

Definition at line 387 of file list.h.

◆ const_pointer

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_pointer = const Val*

Types for STL compliance.

Definition at line 380 of file list.h.

◆ const_reference

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::const_reference = const Val&

Types for STL compliance.

Definition at line 378 of file list.h.

◆ difference_type

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

Types for STL compliance.

Definition at line 382 of file list.h.

◆ iterator

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::iterator = ListIterator< Val >

Types for STL compliance.

Definition at line 384 of file list.h.

◆ iterator_safe

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::iterator_safe = ListIteratorSafe< Val >

Types for STL compliance.

Definition at line 386 of file list.h.

◆ pointer

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::pointer = Val*

Types for STL compliance.

Definition at line 379 of file list.h.

◆ reference

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::reference = Val&

Types for STL compliance.

Definition at line 377 of file list.h.

◆ size_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::size_type = Size

Types for STL compliance.

Definition at line 381 of file list.h.

◆ value_type

template<typename Val, typename Alloc = std::allocator< Val >>
using gum::List< Val, Alloc >::value_type = Val

Types for STL compliance.

Definition at line 376 of file list.h.

Member Enumeration Documentation

◆ location

template<typename Val, typename Alloc = std::allocator< Val >>
enum gum::List::location
strong

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

Enumerator
BEFORE 
AFTER 

Definition at line 396 of file list.h.

396 { BEFORE, AFTER };

Constructor & Destructor Documentation

◆ List() [1/6]

template<typename Val , typename Alloc >
INLINE gum::List< Val, Alloc >::List ( )

A basic constructor that creates an empty list.

Definition at line 1186 of file list_tpl.h.

1186  {
1187  // for debugging purposes
1188  GUM_CONSTRUCTOR(List);
1189 
1190  // reserve space for only the default number of iterators
1192  }
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:42
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186

◆ List() [2/6]

template<typename Val, typename Alloc>
INLINE gum::List< Val, Alloc >::List ( const List< Val, Alloc > &  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 1196 of file list_tpl.h.

1196  {
1197  // for debugging purposes
1198  GUM_CONS_CPY(List);
1199 
1200  // copy the elements
1201  __copy_elements(src);
1202 
1203  // reserve space for only the default number of iterators
1205  }
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:42
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
void __copy_elements(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1114

◆ List() [3/6]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
gum::List< Val, Alloc >::List ( const List< Val, OtherAlloc > &  src)

Ceneralized 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.
Template Parameters
OtherAllocThe other allocator.

◆ List() [4/6]

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

Move constructor.

Parameters
srcThe gum::List to move.

Definition at line 1223 of file list_tpl.h.

1223  :
1224  __deb_list{std::move(src.__deb_list)}, __end_list{std::move(src.__end_list)},
1225  __nb_elements{std::move(src.__nb_elements)},
1226  __safe_iterators{std::move(src.__safe_iterators)}, __alloc_bucket{std::move(
1227  src.__alloc_bucket)} {
1228  // for debugging purposes
1229  GUM_CONS_MOV(List);
1230 
1231  src.__deb_list = nullptr;
1232  src.__end_list = nullptr;
1233  src.__nb_elements = 0;
1234  src.__safe_iterators.clear();
1235  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ List() [5/6]

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

Initializer_list constructor.

Parameters
listThe initializer list.

Definition at line 1239 of file list_tpl.h.

1239  {
1240  // for debugging purposes
1241  GUM_CONSTRUCTOR(List);
1242 
1243  // adding all the elements
1244  for (const auto& val : list) {
1245  pushBack(val);
1246  }
1247 
1248  // reserve space for only the default number of iterators
1250  }
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:42
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186

◆ ~List()

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

Class destructor.

Definition at line 1254 of file list_tpl.h.

1254  {
1255  // for debugging (although this program is bug-free)
1256  GUM_DESTRUCTOR(List);
1257 
1258  // we detach all the safe iterators attached to the current List and we
1259  // remove all the elements from the list
1260  clear();
1261  }
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1164

◆ List() [6/6]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE gum::List< Val, Alloc >::List ( const List< Val, OtherAlloc > &  src)

Definition at line 1210 of file list_tpl.h.

1210  {
1211  // for debugging purposes
1212  GUM_CONS_CPY(List);
1213 
1214  // copy the elements
1215  __copy_elements(src);
1216 
1217  // reserve space for only the default number of iterators
1219  }
#define GUM_DEFAULT_ITERATOR_NUMBER
Definition: list.h:42
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
void __copy_elements(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1114

Member Function Documentation

◆ __copy_elements()

template<typename Val, typename Alloc >
template<typename OtherAlloc >
void gum::List< Val, Alloc >::__copy_elements ( const List< Val, OtherAlloc > &  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).

Template Parameters
OtherAllocThe other allocator.
Parameters
srcThe gum::List to copy.

Definition at line 1114 of file list_tpl.h.

1114  {
1115  ListBucket< Val >* ptr;
1116  ListBucket< Val >* old_ptr = nullptr;
1117  ListBucket< Val >* new_elt = nullptr;
1118 
1119  // copy src's list
1120  try {
1121  for (ptr = src.__deb_list; ptr != nullptr; ptr = ptr->__next) {
1122  // create a copy bucket
1123  new_elt = __alloc_bucket.allocate(1);
1124 
1125  try {
1126  __alloc_bucket.construct(new_elt, *ptr);
1127  } catch (...) {
1128  __alloc_bucket.deallocate(new_elt, 1);
1129  throw;
1130  }
1131 
1132  // rechain properly the new list (the next field is already initialized
1133  // with nullptr)
1134  new_elt->__prev = old_ptr;
1135 
1136  if (old_ptr)
1137  old_ptr->__next = new_elt;
1138  else
1139  __deb_list = new_elt;
1140 
1141  old_ptr = new_elt;
1142  }
1143  } catch (...) {
1144  // problem: we could not allocate an element in the list => we delete
1145  // the elements created so far and we throw an exception
1146  for (; __deb_list != nullptr;
1147  __deb_list = const_cast< ListBucket< Val >* >(ptr)) {
1148  ptr = __deb_list->__next;
1149  __alloc_bucket.destroy(__deb_list);
1150  __alloc_bucket.deallocate(__deb_list, 1);
1151  }
1152 
1153  __deb_list = nullptr;
1154  throw;
1155  }
1156 
1157  // update properly the end of the chained list and the number of elements
1158  __end_list = old_ptr;
1159  __nb_elements = src.__nb_elements;
1160  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ __createBucket() [1/2]

template<typename Val, typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::__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 1475 of file list_tpl.h.

1475  {
1476  // create a new bucket (catch allocation and construction exceptions)
1477  ListBucket< Val >* new_elt = __alloc_bucket.allocate(1);
1478 
1479  try {
1480  __alloc_bucket.construct(new_elt, val);
1481  } catch (...) {
1482  __alloc_bucket.deallocate(new_elt, 1);
1483  throw;
1484  }
1485 
1486  return new_elt;
1487  }
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314

◆ __createBucket() [2/2]

template<typename Val, typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::__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 1491 of file list_tpl.h.

1491  {
1492  // create a new bucket (catch allocation and construction exceptions)
1493  ListBucket< Val >* new_elt = __alloc_bucket.allocate(1);
1494 
1495  try {
1496  __alloc_bucket.construct(new_elt, std::move(val));
1497  } catch (...) {
1498  __alloc_bucket.deallocate(new_elt, 1);
1499  throw;
1500  }
1501 
1502  return new_elt;
1503  }
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314

◆ __createEmplaceBucket() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
ListBucket< Val >* gum::List< Val, Alloc >::__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, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE ListBucket< Val >* gum::List< Val, Alloc >::__createEmplaceBucket ( Args &&...  args) const

Definition at line 1509 of file list_tpl.h.

1509  {
1510  // create a new bucket (catch allocation and construction exceptions)
1511  ListBucket< Val >* new_elt = __alloc_bucket.allocate(1);
1512 
1513  try {
1514  __alloc_bucket.construct(new_elt,
1516  std::forward< Args >(args)...);
1517  } catch (...) {
1518  __alloc_bucket.deallocate(new_elt, 1);
1519  throw;
1520  }
1521 
1522  return new_elt;
1523  }
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314

◆ __erase()

template<typename Val, typename Alloc >
INLINE void gum::List< Val, Alloc >::__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 1866 of file list_tpl.h.

1866  {
1867  // perform deletion only if there is a bucket to remove
1868  if (bucket != nullptr) {
1869  // update the iterators pointing on this element
1870  for (const auto ptr_iter : __safe_iterators) {
1871  if (ptr_iter->__bucket == bucket) {
1872  ptr_iter->__next_current_bucket = bucket->__prev;
1873  ptr_iter->__prev_current_bucket = bucket->__next;
1874  ptr_iter->__bucket = nullptr;
1875  ptr_iter->__null_pointing = true;
1876  } else {
1877  if (ptr_iter->__null_pointing) {
1878  if (ptr_iter->__next_current_bucket == bucket)
1879  ptr_iter->__next_current_bucket = bucket->__prev;
1880 
1881  if (ptr_iter->__prev_current_bucket == bucket)
1882  ptr_iter->__prev_current_bucket = bucket->__next;
1883  }
1884  }
1885  }
1886 
1887  // set properly the begin and end of the chained list (the other chainings
1888  // will be performed by operator delete)
1889  if (bucket->__prev == nullptr)
1890  __deb_list = bucket->__next;
1891  else
1892  bucket->__prev->__next = bucket->__next;
1893 
1894  if (bucket->__next == nullptr)
1895  __end_list = bucket->__prev;
1896  else
1897  bucket->__next->__prev = bucket->__prev;
1898 
1899  // remove the current element src the list
1900  __alloc_bucket.destroy(bucket);
1901  __alloc_bucket.deallocate(bucket, 1);
1902 
1903  --__nb_elements;
1904  }
1905  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ __getBucket()

template<typename Val, typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::__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 1930 of file list_tpl.h.

1931  {
1932  for (ListBucket< Val >* ptr = __deb_list; ptr != nullptr; ptr = ptr->__next)
1933  if (ptr->__val == val) return ptr;
1934 
1935  return nullptr;
1936  }
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302

◆ __getIthBucket()

template<typename Val , typename Alloc >
INLINE ListBucket< Val > * gum::List< Val, Alloc >::__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 1631 of file list_tpl.h.

1632  {
1633  ListBucket< Val >* ptr;
1634 
1635  if (i < __nb_elements / 2) {
1636  for (ptr = __deb_list; i; --i, ptr = ptr->__next) {}
1637  } else {
1638  for (ptr = __end_list, i = __nb_elements - i - 1; i;
1639  --i, ptr = ptr->__prev) {}
1640  }
1641 
1642  return ptr;
1643  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ __insert() [1/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::__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 1706 of file list_tpl.h.

1708  {
1709  // find the location around which the new element should be inserted
1710  ListBucket< Val >* ptr;
1711 
1712  if (iter.__null_pointing) {
1713  if (place == location::BEFORE) {
1714  ptr = iter.__next_current_bucket;
1715  } else {
1716  ptr = iter.__prev_current_bucket;
1717  }
1718  } else {
1719  ptr = iter.__getBucket();
1720  }
1721 
1722  if (ptr == nullptr) {
1723  // here, we are at the end of the list
1724  return __pushBack(new_elt);
1725  } else {
1726  switch (place) {
1727  case location::BEFORE: return __insertBefore(new_elt, ptr);
1728 
1729  case location::AFTER: return __insertAfter(new_elt, ptr);
1730 
1731  default:
1732  GUM_ERROR(FatalError, "List insertion for this location unimplemented");
1733  }
1734  }
1735  }
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1546
Val & __insertAfter(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition: list_tpl.h:1667
Val & __insertBefore(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1647
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ __insert() [2/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::__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 1740 of file list_tpl.h.

1742  {
1743  // find the location around which the new element should be inserted
1744  ListBucket< Val >* ptr = iter.__getBucket();
1745 
1746  if (ptr == nullptr) {
1747  // here, we are at the end of the list
1748  return __pushBack(new_elt);
1749  } else {
1750  switch (place) {
1751  case location::BEFORE: return __insertBefore(new_elt, ptr);
1752 
1753  case location::AFTER: return __insertAfter(new_elt, ptr);
1754 
1755  default:
1756  GUM_ERROR(FatalError, "List insertion for this location unimplemented");
1757  }
1758  }
1759  }
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1546
Val & __insertAfter(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition: list_tpl.h:1667
Val & __insertBefore(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1647
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ __insertAfter()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::__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 1667 of file list_tpl.h.

1668  {
1669  new_elt->__prev = current_elt;
1670  new_elt->__next = current_elt->__next;
1671  current_elt->__next = new_elt;
1672 
1673  if (new_elt->__next == nullptr)
1674  __end_list = new_elt;
1675  else
1676  new_elt->__next->__prev = new_elt;
1677 
1678  // update the number of elements
1679  ++__nb_elements;
1680 
1681  // returns the current value
1682  return new_elt->__val;
1683  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ __insertBefore()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::__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 1647 of file list_tpl.h.

1648  {
1649  new_elt->__next = current_elt;
1650  new_elt->__prev = current_elt->__prev;
1651  current_elt->__prev = new_elt;
1652 
1653  if (new_elt->__prev == nullptr)
1654  __deb_list = new_elt;
1655  else
1656  new_elt->__prev->__next = new_elt;
1657 
1658  // update the number of elements
1659  ++__nb_elements;
1660 
1661  // returns the current value
1662  return new_elt->__val;
1663  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302

◆ __pushBack()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::__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 1546 of file list_tpl.h.

1546  {
1547  // place the bucket at the end of the list
1548  new_elt->__prev = __end_list;
1549 
1550  if (__end_list != nullptr)
1551  __end_list->__next = new_elt;
1552  else
1553  __deb_list = new_elt;
1554 
1555  __end_list = new_elt;
1556 
1557  // update the number of elements
1558  ++__nb_elements;
1559 
1560  // returns the current value
1561  return new_elt->__val;
1562  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ __pushFront()

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::__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 1527 of file list_tpl.h.

1527  {
1528  new_elt->__next = __deb_list;
1529 
1530  if (__deb_list != nullptr)
1531  __deb_list->__prev = new_elt;
1532  else
1533  __end_list = new_elt;
1534 
1535  __deb_list = new_elt;
1536 
1537  // update the number of elements
1538  ++__nb_elements;
1539 
1540  // return the inserted element
1541  return new_elt->__val;
1542  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ back()

template<typename Val , typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1841 of file list_tpl.h.

1841  {
1842  if (__nb_elements == Size(0)) {
1843  GUM_ERROR(NotFound, "not enough elements in the chained list");
1844  }
1845 
1846  return __end_list->__val;
1847  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ begin() [1/2]

template<typename Val , typename Alloc >
INLINE ListIterator< Val > gum::List< Val, Alloc >::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 1417 of file list_tpl.h.

1417  {
1418  return ListIterator< Val >{*this};
1419  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

◆ begin() [2/2]

template<typename Val , typename Alloc >
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::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 1423 of file list_tpl.h.

1423  {
1424  return ListConstIterator< Val >{*this};
1425  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448

◆ beginSafe()

template<typename Val , typename Alloc >
INLINE ListIteratorSafe< Val > gum::List< Val, Alloc >::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 1405 of file list_tpl.h.

1405  {
1406  return ListIteratorSafe< Val >{*this};
1407  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1449

◆ cbegin()

template<typename Val , typename Alloc >
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::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 1411 of file list_tpl.h.

1411  {
1412  return ListConstIterator< Val >{*this};
1413  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448

◆ cbeginSafe()

template<typename Val , typename Alloc >
INLINE ListConstIteratorSafe< Val > gum::List< Val, Alloc >::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 1399 of file list_tpl.h.

1399  {
1400  return ListConstIteratorSafe< Val >{*this};
1401  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1450

◆ cend()

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::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 1346 of file list_tpl.h.

1347  {
1348  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1349  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448

◆ cendSafe()

template<typename Val , typename Alloc >
INLINE const ListConstIteratorSafe< Val > & gum::List< Val, Alloc >::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 1332 of file list_tpl.h.

1333  {
1334  return *(
1335  reinterpret_cast< const ListConstIteratorSafe< Val >* >(__list_end_safe));
1336  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1450

◆ clear()

template<typename Val , typename Alloc >
void gum::List< Val, Alloc >::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 1164 of file list_tpl.h.

1164  {
1165  // first we update all the safe iterators of the list : they should now
1166  // point to end/rend
1167  for (const auto ptr_iter : __safe_iterators) {
1168  ptr_iter->clear();
1169  }
1170 
1171  // clear all the values
1172  for (ListBucket< Val >*ptr = __deb_list, *next_ptr = nullptr; ptr != nullptr;
1173  ptr = next_ptr) {
1174  next_ptr = ptr->__next;
1175  __alloc_bucket.destroy(ptr);
1176  __alloc_bucket.deallocate(ptr, 1);
1177  }
1178 
1179  __nb_elements = 0;
1180  __deb_list = nullptr;
1181  __end_list = nullptr;
1182  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ crbegin()

template<typename Val , typename Alloc >
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::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 1447 of file list_tpl.h.

1447  {
1448  if (__nb_elements)
1449  return ListConstIterator< Val >{*this, __nb_elements - 1};
1450  else
1451  return ListConstIterator< Val >{};
1452  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308

◆ crbeginSafe()

template<typename Val , typename Alloc >
INLINE ListConstIteratorSafe< Val > gum::List< Val, Alloc >::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 1429 of file list_tpl.h.

1429  {
1430  if (__nb_elements)
1431  return ListConstIteratorSafe< Val >{*this, __nb_elements - 1};
1432  else
1434  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1450
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308

◆ crend()

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::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 1379 of file list_tpl.h.

1380  {
1381  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1382  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448

◆ crendSafe()

template<typename Val , typename Alloc >
INLINE const ListConstIteratorSafe< Val > & gum::List< Val, Alloc >::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 1365 of file list_tpl.h.

1366  {
1367  return *(
1368  reinterpret_cast< const ListConstIteratorSafe< Val >* >(__list_end_safe));
1369  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1450

◆ emplace() [1/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
Val& gum::List< Val, Alloc >::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.

◆ emplace() [2/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
Val& gum::List< Val, Alloc >::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.

◆ emplace() [3/4]

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

Definition at line 1812 of file list_tpl.h.

1813  {
1814  return __insert(iter,
1815  __createEmplaceBucket(std::forward< Args >(args)...),
1817  }
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:1706
ListBucket< Val > * __createEmplaceBucket(Args &&... args) const
Create an emplace bucket.

◆ emplace() [4/4]

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

Definition at line 1822 of file list_tpl.h.

1823  {
1824  return __insert(iter,
1825  __createEmplaceBucket(std::forward< Args >(args)...),
1827  }
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:1706
ListBucket< Val > * __createEmplaceBucket(Args &&... args) const
Create an emplace bucket.

◆ emplaceBack() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
Val& gum::List< Val, Alloc >::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.

◆ emplaceBack() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::emplaceBack ( Args &&...  args)

Definition at line 1612 of file list_tpl.h.

1612  {
1613  return __pushBack(__createEmplaceBucket(std::forward< Args >(args)...));
1614  }
ListBucket< Val > * __createEmplaceBucket(Args &&... args) const
Create an emplace bucket.
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1546

◆ emplaceFront() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
Val& gum::List< Val, Alloc >::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.

◆ emplaceFront() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::emplaceFront ( Args &&...  args)

Definition at line 1586 of file list_tpl.h.

1586  {
1587  return __pushFront(__createEmplaceBucket(std::forward< Args >(args)...));
1588  }
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.
Definition: list_tpl.h:1527

◆ empty()

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

◆ end() [1/2]

template<typename Val , typename Alloc >
INLINE const ListIterator< Val > & gum::List< Val, Alloc >::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 1353 of file list_tpl.h.

1353  {
1354  return *(reinterpret_cast< const ListIterator< Val >* >(__list_end));
1355  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

◆ end() [2/2]

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::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 1359 of file list_tpl.h.

1359  {
1360  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1361  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448

◆ endSafe()

template<typename Val , typename Alloc >
INLINE const ListIteratorSafe< Val > & gum::List< Val, Alloc >::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 1340 of file list_tpl.h.

1340  {
1341  return *(reinterpret_cast< const ListIteratorSafe< Val >* >(__list_end_safe));
1342  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1449

◆ erase() [1/3]

template<typename Val , typename Alloc >
INLINE void gum::List< Val, Alloc >::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 1909 of file list_tpl.h.

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

1909  {
1910  if (i >= __nb_elements) return;
1911 
1912  // erase the ith bucket
1913  __erase(__getIthBucket(i));
1914  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1866
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __getIthBucket(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1631
+ Here is the caller graph for this function:

◆ erase() [2/3]

template<typename Val , typename Alloc >
INLINE void gum::List< Val, Alloc >::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 1918 of file list_tpl.h.

1918  {
1919  __erase(iter.__getBucket());
1920  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1866

◆ erase() [3/3]

template<typename Val , typename Alloc >
INLINE void gum::List< Val, Alloc >::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 1924 of file list_tpl.h.

1924  {
1925  __erase(iter.__getBucket());
1926  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1866

◆ eraseAllVal()

template<typename Val, typename Alloc >
INLINE void gum::List< Val, Alloc >::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 1946 of file list_tpl.h.

1946  {
1947  for (ListBucket< Val >*iter = __deb_list, *next_bucket = nullptr;
1948  iter != nullptr;
1949  iter = next_bucket) {
1950  next_bucket = iter->__next;
1951 
1952  if (val == iter->__val) __erase(iter);
1953  }
1954  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1866
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302

◆ eraseByVal()

template<typename Val, typename Alloc >
INLINE void gum::List< Val, Alloc >::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 1940 of file list_tpl.h.

1940  {
1941  __erase(__getBucket(val));
1942  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1866
ListBucket< Val > * __getBucket(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition: list_tpl.h:1930

◆ exists()

template<typename Val, typename Alloc >
INLINE bool gum::List< Val, Alloc >::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 1857 of file list_tpl.h.

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

1857  {
1858  for (ListBucket< Val >* ptr = __deb_list; ptr != nullptr; ptr = ptr->__next)
1859  if (ptr->__val == val) return true;
1860 
1861  return false;
1862  }
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
+ Here is the caller graph for this function:

◆ front()

template<typename Val , typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1831 of file list_tpl.h.

Referenced by gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesDownward(), gum::learning::Miic::__existsDirectedPath(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::DiGraph::hasDirectedPath(), gum::UndiGraph::hasUndirectedCycle(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::DAGCycleDetector::setDAG(), and gum::EdgeGraphPart::undirectedPath().

1831  {
1832  if (__nb_elements == Size(0)) {
1833  GUM_ERROR(NotFound, "not enough elements in the chained list");
1834  }
1835 
1836  return __deb_list->__val;
1837  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ insert() [1/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1619 of file list_tpl.h.

Referenced by gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesUpward(), 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::UndiGraph::hasUndirectedCycle(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::DAGCycleDetector::setDAG(), gum::EssentialGraph::toDot(), gum::UndiGraph::toDot(), and gum::MixedGraph::toDot().

1619  {
1620  return pushBack(val);
1621  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592
+ Here is the caller graph for this function:

◆ insert() [2/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1625 of file list_tpl.h.

1625  {
1626  return pushBack(std::move(val));
1627  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592

◆ insert() [3/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1687 of file list_tpl.h.

1687  {
1688  // if ther are fewer elements than pos, put the value at the end of the list
1689  if (__nb_elements <= pos) { return pushBack(val); }
1690 
1691  return __insertBefore(__createBucket(val), __getIthBucket(pos));
1692  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __getIthBucket(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1631
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592
Val & __insertBefore(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1647

◆ insert() [4/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1696 of file list_tpl.h.

1696  {
1697  // if ther are fewer elements than pos, put the value at the end of the list
1698  if (__nb_elements <= pos) { return pushBack(std::move(val)); }
1699 
1700  return __insertBefore(__createBucket(std::move(val)), __getIthBucket(pos));
1701  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __getIthBucket(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1631
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592
Val & __insertBefore(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1647

◆ insert() [5/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1764 of file list_tpl.h.

1766  {
1767  // if the iterator does not point to the list, raise an exception
1768  if (iter.__list != this) {
1769  GUM_ERROR(InvalidArgument,
1770  "the iterator does not point to the correct list");
1771  }
1772 
1773  return __insert(iter, __createBucket(val), place);
1774  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
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:1706
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ insert() [6/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1779 of file list_tpl.h.

1781  {
1782  // if the iterator does not point to the list, raise an exception
1783  if (iter.__list != this) {
1784  GUM_ERROR(InvalidArgument,
1785  "the iterator does not point to the correct list");
1786  }
1787 
1788  return __insert(iter, __createBucket(std::move(val)), place);
1789  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
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:1706
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ insert() [7/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1794 of file list_tpl.h.

1796  {
1797  return __insert(iter, __createBucket(val), place);
1798  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
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:1706

◆ insert() [8/8]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1803 of file list_tpl.h.

1805  {
1806  return __insert(iter, __createBucket(std::move(val)), place);
1807  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
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:1706

◆ map() [1/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map ( Mount(*)(Val)  f) 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.
OtherAllocThe mountains type allocator.

Definition at line 1996 of file list_tpl.h.

1996  {
1997  // create a new empty list
1998  List< Mount, OtherAlloc > list;
1999 
2000  // fill the new list
2001  for (const_iterator iter = begin(); iter != end(); ++iter) {
2002  list.pushBack(f(*iter));
2003  }
2004 
2005  return list;
2006  }
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition: list_tpl.h:1353
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition: list.h:385
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition: list_tpl.h:1417

◆ map() [2/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map ( Mount(*)(Val &)  f) 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.
OtherAllocThe mountains type allocator.

Definition at line 2011 of file list_tpl.h.

2011  {
2012  // create a new empty list
2013  List< Mount, OtherAlloc > list;
2014 
2015  // fill the new list
2016  for (const_iterator iter = begin(); iter != end(); ++iter) {
2017  list.pushBack(f(*iter));
2018  }
2019 
2020  return list;
2021  }
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition: list_tpl.h:1353
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition: list.h:385
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition: list_tpl.h:1417

◆ map() [3/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::map ( Mount(*)(const Val &)  f) 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.
OtherAllocThe mountains type allocator.

Definition at line 2026 of file list_tpl.h.

2026  {
2027  // create a new empty list
2028  List< Mount, OtherAlloc > list;
2029 
2030  // fill the new list
2031  for (const_iterator iter = begin(); iter != end(); ++iter) {
2032  list.pushBack(f(*iter));
2033  }
2034 
2035  return list;
2036  }
const iterator & end() noexcept
Returns an unsafe iterator pointing to the end of the List.
Definition: list_tpl.h:1353
ListConstIterator< Val > const_iterator
Types for STL compliance.
Definition: list.h:385
iterator begin()
Returns an unsafe iterator pointing to the beginning of the List.
Definition: list_tpl.h:1417

◆ map() [4/4]

template<typename Val, typename Alloc >
template<typename Mount , typename OtherAlloc >
List< Mount, OtherAlloc > gum::List< Val, Alloc >::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.
OtherAllocThe mountains type allocator.

Definition at line 2041 of file list_tpl.h.

2041  {
2042  // create a new empty list
2043  List< Mount, OtherAlloc > list;
2044 
2045  // fill the new list
2046  for (Size i = Size(0); i < __nb_elements; ++i)
2047  list.pushBack(mount);
2048 
2049  return list;
2050  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

◆ operator!=() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
bool gum::List< Val, Alloc >::operator!= ( const List< Val, OtherAlloc > &  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.
Template Parameters
OtherAllocThe other allocator.

◆ operator!=() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE bool gum::List< Val, Alloc >::operator!= ( const List< Val, OtherAlloc > &  src) const

Definition at line 2087 of file list_tpl.h.

2087  {
2088  return !operator==(src);
2089  }
bool operator==(const List< Val, OtherAlloc > &src) const
Checks whether two lists are identical (same elements in the same order).

◆ operator+=() [1/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 2055 of file list_tpl.h.

2055  {
2056  return pushBack(val);
2057  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592

◆ operator+=() [2/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 2062 of file list_tpl.h.

2062  {
2063  return pushBack(std::move(val));
2064  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592

◆ operator=() [1/4]

template<typename Val, typename Alloc>
INLINE List< Val, Alloc > & gum::List< Val, Alloc >::operator= ( const List< Val, Alloc > &  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 1266 of file list_tpl.h.

1266  {
1267  // avoid self assignment
1268  if (this != &src) {
1269  // for debugging purposes
1270  GUM_OP_CPY(List);
1271 
1272  // remove the old content of 'this' and update accordingly the iterators
1273  clear();
1274 
1275  // perform the copy
1276  __copy_elements(src);
1277  }
1278 
1279  return *this;
1280  }
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
void __copy_elements(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1114
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1164

◆ operator=() [2/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
List< Val, Alloc >& gum::List< Val, Alloc >::operator= ( const List< Val, OtherAlloc > &  src)

Generalized 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.

◆ operator=() [3/4]

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

Move operator.

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

Definition at line 1305 of file list_tpl.h.

1305  {
1306  // avoid self assignment
1307  if (this != &src) {
1308  // for debugging purposes
1309  GUM_OP_MOV(List);
1310 
1311  // remove the old content of 'this' and update accordingly the iterators
1312  clear();
1313 
1314  // perform the move
1315  __deb_list = std::move(src.__deb_list);
1316  __end_list = std::move(src.__end_list);
1317  __nb_elements = std::move(src.__nb_elements);
1318  __safe_iterators = std::move(src.__safe_iterators);
1319  __alloc_bucket = std::move(src.__alloc_bucket);
1320 
1321  src.__deb_list = nullptr;
1322  src.__end_list = nullptr;
1323  src.__nb_elements = 0;
1324  src.__safe_iterators.clear();
1325  }
1326 
1327  return *this;
1328  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1164
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ operator=() [4/4]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE List< Val, Alloc >& gum::List< Val, Alloc >::operator= ( const List< Val, OtherAlloc > &  src)

Definition at line 1286 of file list_tpl.h.

1286  {
1287  // avoid self assignment
1288  if (this != reinterpret_cast< List< Val, Alloc >* >(&src)) {
1289  // for debugging purposes
1290  GUM_OP_CPY(List);
1291 
1292  // remove the old content of 'this' and update accordingly the iterators
1293  clear();
1294 
1295  // perform the copy
1296  __copy_elements(src);
1297  }
1298 
1299  return *this;
1300  }
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1186
void __copy_elements(const List< Val, OtherAlloc > &src)
A function used to perform copies of elements of Lists.
Definition: list_tpl.h:1114
void clear()
Deletes all the elements of a chained list.
Definition: list_tpl.h:1164

◆ operator==() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
bool gum::List< Val, Alloc >::operator== ( const List< Val, OtherAlloc > &  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.
Template Parameters
OtherAllocThe other allocator.

◆ operator==() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename OtherAlloc >
INLINE bool gum::List< Val, Alloc >::operator== ( const List< Val, OtherAlloc > &  src) const

Definition at line 2070 of file list_tpl.h.

2070  {
2071  // check if the two lists have at least the same number of elements
2072  if (__nb_elements != src.__nb_elements) return false;
2073 
2074  // parse the two lists
2075  for (ListBucket< Val >*iter1 = __deb_list, *iter2 = src.__deb_list;
2076  iter1 != nullptr;
2077  iter1 = iter1->__next, iter2 = iter2->__next)
2078  if (*iter1 != *iter2) return false;
2079 
2080  return true;
2081  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302

◆ operator[]() [1/2]

template<typename Val , typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 2093 of file list_tpl.h.

2093  {
2094  // check if we can return the element we ask for
2095  if (i >= __nb_elements) {
2096  GUM_ERROR(NotFound, "not enough elements in the chained list");
2097  }
2098 
2099  return **__getIthBucket(i);
2100  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __getIthBucket(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1631
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ operator[]() [2/2]

template<typename Val , typename Alloc >
INLINE const Val & gum::List< Val, Alloc >::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 2104 of file list_tpl.h.

2104  {
2105  // check if we can return the element we ask for
2106  if (i >= __nb_elements) {
2107  GUM_ERROR(NotFound, "not enough elements in the chained list");
2108  }
2109 
2110  return **__getIthBucket(i);
2111  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
ListBucket< Val > * __getIthBucket(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1631
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ popBack()

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

Removes the last element of a List, if any.

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

Definition at line 1958 of file list_tpl.h.

1958  {
1960  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1866
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ popFront()

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

◆ push_back() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
Val& gum::List< Val, Alloc >::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.

Referenced by gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), and gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances().

+ Here is the caller graph for this function:

◆ push_back() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::push_back ( Args &&...  args)

Definition at line 1605 of file list_tpl.h.

1605  {
1606  return pushBack(std::forward< Args >(args)...);
1607  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592

◆ push_front() [1/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
Val& gum::List< Val, Alloc >::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.

◆ push_front() [2/2]

template<typename Val, typename Alloc = std::allocator< Val >>
template<typename... Args>
INLINE Val& gum::List< Val, Alloc >::push_front ( Args &&...  args)

Definition at line 1579 of file list_tpl.h.

1579  {
1580  return pushFront(std::forward< Args >(args)...);
1581  }
Val & pushFront(const Val &val)
Inserts a new element (a copy) at the beginning of the chained list.
Definition: list_tpl.h:1566

◆ pushBack() [1/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1592 of file list_tpl.h.

Referenced by gum::learning::Miic::__existsDirectedPath(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::DiGraph::hasDirectedPath(), gum::Set< gum::Potential< GUM_SCALAR > * >::listMap(), gum::List< const gum::Potential< GUM_SCALAR > * >::map(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), and gum::EdgeGraphPart::undirectedPath().

1592  {
1593  return __pushBack(__createBucket(val));
1594  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1546
+ Here is the caller graph for this function:

◆ pushBack() [2/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1598 of file list_tpl.h.

1598  {
1599  return __pushBack(__createBucket(std::move(val)));
1600  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1546

◆ pushFront() [1/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1566 of file list_tpl.h.

1566  {
1567  return __pushFront(__createBucket(val));
1568  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
Val & __pushFront(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1527

◆ pushFront() [2/2]

template<typename Val, typename Alloc >
INLINE Val & gum::List< Val, Alloc >::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 1572 of file list_tpl.h.

1572  {
1573  return __pushFront(__createBucket(std::move(val)));
1574  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1475
Val & __pushFront(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1527

◆ rbegin() [1/2]

template<typename Val , typename Alloc >
INLINE ListIterator< Val > gum::List< Val, Alloc >::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 1456 of file list_tpl.h.

1456  {
1457  if (__nb_elements)
1458  return ListIterator< Val >{*this, __nb_elements - 1};
1459  else
1460  return ListIterator< Val >{};
1461  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

◆ rbegin() [2/2]

template<typename Val , typename Alloc >
INLINE ListConstIterator< Val > gum::List< Val, Alloc >::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 1465 of file list_tpl.h.

1465  {
1466  if (__nb_elements)
1467  return ListConstIterator< Val >{*this, __nb_elements - 1};
1468  else
1469  return ListConstIterator< Val >{};
1470  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308

◆ rbeginSafe()

template<typename Val , typename Alloc >
INLINE ListIteratorSafe< Val > gum::List< Val, Alloc >::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 1438 of file list_tpl.h.

1438  {
1439  if (__nb_elements)
1440  return ListIteratorSafe< Val >{*this, __nb_elements - 1};
1441  else
1442  return ListIteratorSafe< Val >{};
1443  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1449

◆ rend() [1/2]

template<typename Val , typename Alloc >
INLINE const ListIterator< Val > & gum::List< Val, Alloc >::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 1386 of file list_tpl.h.

1386  {
1387  return *(reinterpret_cast< const ListIterator< Val >* >(__list_end));
1388  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

◆ rend() [2/2]

template<typename Val , typename Alloc >
INLINE const ListConstIterator< Val > & gum::List< Val, Alloc >::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 1392 of file list_tpl.h.

1393  {
1394  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1395  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1448

◆ rendSafe()

template<typename Val , typename Alloc >
INLINE const ListIteratorSafe< Val > & gum::List< Val, Alloc >::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 1373 of file list_tpl.h.

1373  {
1374  return *(reinterpret_cast< const ListIteratorSafe< Val >* >(__list_end_safe));
1375  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1449

◆ size()

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

Returns the number of elements in the list.

This method runs in constant time.

Definition at line 1851 of file list_tpl.h.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::BayesNetFactory< GUM_SCALAR >::__increment(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__insertEvidence(), and gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances().

1851  {
1852  return __nb_elements;
1853  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
+ Here is the caller graph for this function:

◆ swap()

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

Swap the current list with another one.

Parameters
other_listThe list to swap elements with.

Definition at line 2115 of file list_tpl.h.

2115  {
2116  std::swap(__deb_list, other_list.__deb_list);
2117  std::swap(__end_list, other_list.__end_list);
2118  std::swap(__nb_elements, other_list.__nb_elements);
2119  std::swap(__safe_iterators, other_list.__safe_iterators);
2120  std::swap(__alloc_bucket, other_list.__alloc_bucket);
2121  }
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
Size __nb_elements
The number of elements in the list.
Definition: list.h:1308
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1311
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1314
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1305

◆ toString()

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

Converts a list into a string.

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

Definition at line 1976 of file list_tpl.h.

1976  {
1977  bool deja = false;
1978  std::stringstream stream;
1979  stream << "[";
1980 
1981  for (ListBucket< Val >* ptr = __deb_list; ptr != nullptr;
1982  ptr = ptr->__next, deja = true) {
1983  if (deja) stream << " --> ";
1984 
1985  stream << ptr->__val;
1986  }
1987 
1988  stream << "]";
1989 
1990  return stream.str();
1991  }
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1302

Friends And Related Function Documentation

◆ ListConstIterator< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListConstIterator< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1448 of file list.h.

◆ ListConstIteratorSafe< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListConstIteratorSafe< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1450 of file list.h.

◆ ListIterator< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListIterator< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1447 of file list.h.

◆ ListIteratorSafe< Val >

template<typename Val, typename Alloc = std::allocator< Val >>
friend class ListIteratorSafe< Val >
friend

ListIterator should be a friend to optimize access to elements.

Definition at line 1449 of file list.h.

Member Data Documentation

◆ __alloc_bucket

template<typename Val, typename Alloc = std::allocator< Val >>
BucketAllocator gum::List< Val, Alloc >::__alloc_bucket
mutableprivate

The allocator for the buckets.

Definition at line 1314 of file list.h.

Referenced by gum::List< const gum::Potential< GUM_SCALAR > * >::swap().

◆ __deb_list

template<typename Val, typename Alloc = std::allocator< Val >>
ListBucket< Val >* gum::List< Val, Alloc >::__deb_list {nullptr}
private

◆ __end_list

template<typename Val, typename Alloc = std::allocator< Val >>
ListBucket< Val >* gum::List< Val, Alloc >::__end_list {nullptr}
private

◆ __nb_elements

◆ __safe_iterators

template<typename Val, typename Alloc = std::allocator< Val >>
std::vector< const_iterator_safe* > gum::List< Val, Alloc >::__safe_iterators
mutableprivate

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