aGrUM  0.14.2
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 369 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 380 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 389 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 382 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 384 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 377 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 375 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 379 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 381 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 383 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 376 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 374 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 378 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 373 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 393 of file list.h.

393 { 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 1183 of file list_tpl.h.

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

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

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

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

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

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

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

◆ ~List()

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

Class destructor.

Definition at line 1251 of file list_tpl.h.

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

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

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

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

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

◆ __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 1472 of file list_tpl.h.

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

◆ __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 1488 of file list_tpl.h.

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

◆ __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 1506 of file list_tpl.h.

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

◆ __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 1863 of file list_tpl.h.

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

◆ __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 1927 of file list_tpl.h.

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

◆ __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 1628 of file list_tpl.h.

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

◆ __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 1703 of file list_tpl.h.

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

◆ __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 1737 of file list_tpl.h.

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

◆ __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 1664 of file list_tpl.h.

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

◆ __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 1644 of file list_tpl.h.

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

◆ __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 1543 of file list_tpl.h.

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

◆ __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 1524 of file list_tpl.h.

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

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

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

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

1414  {
1415  return ListIterator< Val >{*this};
1416  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1444

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

1420  {
1421  return ListConstIterator< Val >{*this};
1422  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1445

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

1402  {
1403  return ListIteratorSafe< Val >{*this};
1404  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1446

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

1408  {
1409  return ListConstIterator< Val >{*this};
1410  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1445

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

1396  {
1397  return ListConstIteratorSafe< Val >{*this};
1398  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

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

1344  {
1345  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1346  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1445

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

1330  {
1331  return *(
1332  reinterpret_cast< const ListConstIteratorSafe< Val >* >(__list_end_safe));
1333  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

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

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

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

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

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

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

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

1377  {
1378  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1379  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1445

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

1363  {
1364  return *(
1365  reinterpret_cast< const ListConstIteratorSafe< Val >* >(__list_end_safe));
1366  }
friend class ListConstIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1447

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

1810  {
1811  return __insert(iter,
1812  __createEmplaceBucket(std::forward< Args >(args)...),
1814  }
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:1703
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 1819 of file list_tpl.h.

1820  {
1821  return __insert(iter,
1822  __createEmplaceBucket(std::forward< Args >(args)...),
1824  }
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:1703
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 1609 of file list_tpl.h.

1609  {
1610  return __pushBack(__createEmplaceBucket(std::forward< Args >(args)...));
1611  }
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:1543

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

1583  {
1584  return __pushFront(__createEmplaceBucket(std::forward< Args >(args)...));
1585  }
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:1524

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

1350  {
1351  return *(reinterpret_cast< const ListIterator< Val >* >(__list_end));
1352  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1444

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

1356  {
1357  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1358  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1445

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

1337  {
1338  return *(reinterpret_cast< const ListIteratorSafe< Val >* >(__list_end_safe));
1339  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1446

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

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

1906  {
1907  if (i >= __nb_elements) return;
1908 
1909  // erase the ith bucket
1910  __erase(__getIthBucket(i));
1911  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1863
Size __nb_elements
The number of elements in the list.
Definition: list.h:1305
ListBucket< Val > * __getIthBucket(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1628
+ 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 1915 of file list_tpl.h.

1915  {
1916  __erase(iter.__getBucket());
1917  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1863

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

1921  {
1922  __erase(iter.__getBucket());
1923  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1863

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

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

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

1937  {
1938  __erase(__getBucket(val));
1939  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1863
ListBucket< Val > * __getBucket(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition: list_tpl.h:1927

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

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

1854  {
1855  for (ListBucket< Val >* ptr = __deb_list; ptr != nullptr; ptr = ptr->__next)
1856  if (ptr->__val == val) return true;
1857 
1858  return false;
1859  }
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1299
+ 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 1828 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::DAG::__hasDirectedPath(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), 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().

1828  {
1829  if (__nb_elements == Size(0)) {
1830  GUM_ERROR(NotFound, "not enough elements in the chained list");
1831  }
1832 
1833  return __deb_list->__val;
1834  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1305
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1299
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 1616 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().

1616  {
1617  return pushBack(val);
1618  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1589
+ 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 1622 of file list_tpl.h.

1622  {
1623  return pushBack(std::move(val));
1624  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1589

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

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

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

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

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

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

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

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

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

1793  {
1794  return __insert(iter, __createBucket(val), place);
1795  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1472
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:1703

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

1802  {
1803  return __insert(iter, __createBucket(std::move(val)), place);
1804  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1472
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:1703

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

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

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

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

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

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

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

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

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

2084  {
2085  return !operator==(src);
2086  }
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 2052 of file list_tpl.h.

2052  {
2053  return pushBack(val);
2054  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1589

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

2059  {
2060  return pushBack(std::move(val));
2061  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1589

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

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

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

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

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

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

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

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

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

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

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

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

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

1955  {
1957  }
void __erase(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1863
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1302

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

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

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

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

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

Referenced by gum::learning::Miic::__existsDirectedPath(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::DAG::__hasDirectedPath(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), 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().

1589  {
1590  return __pushBack(__createBucket(val));
1591  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1472
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1543
+ 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 1595 of file list_tpl.h.

1595  {
1596  return __pushBack(__createBucket(std::move(val)));
1597  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1472
Val & __pushBack(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1543

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

1563  {
1564  return __pushFront(__createBucket(val));
1565  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1472
Val & __pushFront(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1524

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

1569  {
1570  return __pushFront(__createBucket(std::move(val)));
1571  }
ListBucket< Val > * __createBucket(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1472
Val & __pushFront(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1524

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

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

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

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

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

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

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

1383  {
1384  return *(reinterpret_cast< const ListIterator< Val >* >(__list_end));
1385  }
friend class ListIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1444

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

1390  {
1391  return *(reinterpret_cast< const ListConstIterator< Val >* >(__list_end));
1392  }
friend class ListConstIterator< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1445

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

1370  {
1371  return *(reinterpret_cast< const ListIteratorSafe< Val >* >(__list_end_safe));
1372  }
friend class ListIteratorSafe< Val >
ListIterator should be a friend to optimize access to elements.
Definition: list.h:1446

◆ 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 1848 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().

1848  {
1849  return __nb_elements;
1850  }
Size __nb_elements
The number of elements in the list.
Definition: list.h:1305
+ 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 2112 of file list_tpl.h.

2112  {
2113  std::swap(__deb_list, other_list.__deb_list);
2114  std::swap(__end_list, other_list.__end_list);
2115  std::swap(__nb_elements, other_list.__nb_elements);
2116  std::swap(__safe_iterators, other_list.__safe_iterators);
2117  std::swap(__alloc_bucket, other_list.__alloc_bucket);
2118  }
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:1305
std::vector< const_iterator_safe *> __safe_iterators
The list of "safe" iterators attached to the list.
Definition: list.h:1308
ListBucket< Val > * __deb_list
A pointer on the first element of the chained list.
Definition: list.h:1299
BucketAllocator __alloc_bucket
The allocator for the buckets.
Definition: list.h:1311
ListBucket< Val > * __end_list
A pointer on the last element of the chained list.
Definition: list.h:1302

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

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

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 1445 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 1447 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 1444 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 1446 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 1311 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: