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

Generic doubly linked lists. More...

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

Public Member Functions

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

Public Types

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

Friends

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

Detailed Description

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

Generic doubly linked lists.

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

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

Usage example:
// creation of an empty list
List<int> list1;
List<int> list2 { 3, 4, 5 }; // initializer list
// adding elements to the list
list1.pushFront (23);
list1.pushBack (10);
list1 += 25;
list1.insert (12);
// getting the second element of the list
cerr << "10 = " << list1[1] << endl;
// getting the first and last elements
cerr << "first = " << list1.front() << " last = " << list1.back() << endl;
// get the number of elements in the list
cerr << "number of elements = " << list1.size () << endl;
// display the content of the list
cerr << list1 << endl;
// copy the list
List<int> list2 = list1, list3;
list3 = list1;
// delete the second element from the list
list1.erase (1);
// delete the first and last elements
list1.popFront ();
list1.popBack ();
// delete element whose value is 25
list1.eraseByVal (25);
// check whether the list is empty
if (list1.empty()) cerr << "empty list" << endl;
// remove all elements from the list
list1.clear ();
// parse all the elements of a list using unsafe iterators
for (List<int>::iterator iter = list2.begin();
iter != list2.end(); ++iter)
cerr << *iter << endl;
for (List<int>::iterator iter = list2.rbegin();
iter != list2.rend(); --iter)
cerr << *iter << endl;
for (List<int>::const_iterator iter = list2.cbegin();
iter != list2.cend(); ++iter)
cerr << *iter << endl;
for (List<int>::const_iterator iter = list2.crbegin();
iter != list2.crend(); --iter)
cerr << *iter << endl;
// parse all the elements of a list using safe iterators
for (List<int>::iterator_safe iter = list2.beginSafe();
iter != list2.endSafe(); ++iter)
cerr << *iter << endl;
for (List<int>::iterator_safe iter = list2.rbeginSafe();
iter != list2.rendSafe(); --iter)
cerr << *iter << endl;
for (List<int>::const_iterator_safe iter = list2.cbeginSafe();
iter != list2.cendSafe(); ++iter)
cerr << *iter << endl;
for (List<int>::const_iterator_safe iter = list2.crbeginSafe();
iter != list2.crendSafe(); --iter)
cerr << *iter << endl;
// use an iterator to point the element we wish to erase
List<int>::iterator_safe iter = list2.beginSafe();
List2.erase ( iter );
List<int>::iterator iter2 = list2.begin() + 4; // 5th element of the list
iter2 = iter + 4;
// map a list into another list (assuming function f is defined as
// float f (int x) { return (2.5 * x); } )
List<float> flist = list2.map (f);
Template Parameters
ValThe values type stored in the gum::List.
AllocThe allocator for the values stored in the gum::List.

Definition at line 372 of file list.h.

Member Typedef Documentation

◆ allocator_type

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

Types for STL compliance.

Definition at line 383 of file list.h.

◆ BucketAllocator

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

Type of the allocator for ListBuckets.

Definition at line 392 of file list.h.

◆ const_iterator

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

Types for STL compliance.

Definition at line 385 of file list.h.

◆ const_iterator_safe

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

Types for STL compliance.

Definition at line 387 of file list.h.

◆ const_pointer

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

Types for STL compliance.

Definition at line 380 of file list.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 378 of file list.h.

◆ difference_type

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

Types for STL compliance.

Definition at line 382 of file list.h.

◆ iterator

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

Types for STL compliance.

Definition at line 384 of file list.h.

◆ iterator_safe

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

Types for STL compliance.

Definition at line 386 of file list.h.

◆ pointer

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

Types for STL compliance.

Definition at line 379 of file list.h.

◆ reference

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

Types for STL compliance.

Definition at line 377 of file list.h.

◆ size_type

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

Types for STL compliance.

Definition at line 381 of file list.h.

◆ value_type

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

Types for STL compliance.

Definition at line 376 of file list.h.

Member Enumeration Documentation

◆ location

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

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

Enumerator
BEFORE 
AFTER 

Definition at line 396 of file list.h.

397  {
398  BEFORE,
399  AFTER
400  };

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

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

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

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

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

1224  :
1225  deb_list__{std::move(src.deb_list__)}, end_list__{std::move(src.end_list__)},
1226  nb_elements__{std::move(src.nb_elements__)},
1227  safe_iterators__{std::move(src.safe_iterators__)}, alloc_bucket__{std::move(
1228  src.alloc_bucket__)} {
1229  // for debugging purposes
1230  GUM_CONS_MOV(List);
1231 
1232  src.deb_list__ = nullptr;
1233  src.end_list__ = nullptr;
1234  src.nb_elements__ = 0;
1235  src.safe_iterators__.clear();
1236  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
BucketAllocator alloc_bucket__
The allocator for the buckets.
Definition: list.h:1318
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
List()
A basic constructor that creates an empty list.
Definition: list_tpl.h:1187
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

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

◆ ~List()

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

Class destructor.

Definition at line 1255 of file list_tpl.h.

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

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

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

Member Function Documentation

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

1846  {
1847  if (nb_elements__ == Size(0)) {
1848  GUM_ERROR(NotFound, "not enough elements in the chained list");
1849  }
1850 
1851  return end_list__->val__;
1852  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1165  {
1166  // first we update all the safe iterators of the list : they should now
1167  // point to end/rend
1168  for (const auto ptr_iter: safe_iterators__) {
1169  ptr_iter->clear();
1170  }
1171 
1172  // clear all the values
1173  for (ListBucket< Val >*ptr = deb_list__, *next_ptr = nullptr; ptr != nullptr;
1174  ptr = next_ptr) {
1175  next_ptr = ptr->next__;
1176  alloc_bucket__.destroy(ptr);
1177  alloc_bucket__.deallocate(ptr, 1);
1178  }
1179 
1180  nb_elements__ = 0;
1181  deb_list__ = nullptr;
1182  end_list__ = nullptr;
1183  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
BucketAllocator alloc_bucket__
The allocator for the buckets.
Definition: list.h:1318
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1818  {
1819  return insert__(iter,
1820  createEmplaceBucket__(std::forward< Args >(args)...),
1822  }
ListBucket< Val > * createEmplaceBucket__(Args &&... args) const
Create an emplace bucket.
Val & insert__(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1707

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

1828  {
1829  return insert__(iter,
1830  createEmplaceBucket__(std::forward< Args >(args)...),
1832  }
ListBucket< Val > * createEmplaceBucket__(Args &&... args) const
Create an emplace bucket.
Val & insert__(const const_iterator_safe &iter, ListBucket< Val > *new_elt, location place)
Inserts a new bucket before or after the location pointed to by an iterator.
Definition: list_tpl.h:1707

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

1613  {
1614  return pushBack__(createEmplaceBucket__(std::forward< Args >(args)...));
1615  }
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:1547

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

1587  {
1588  return pushFront__(createEmplaceBucket__(std::forward< Args >(args)...));
1589  }
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:1528

◆ empty()

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

Returns a boolean indicating whether the chained list is empty.

Returns
Returns a boolean indicating whether the chained list is empty.

Definition at line 1975 of file list_tpl.h.

1975  {
1976  return (nb_elements__ == Size(0));
1977  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

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

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

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

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

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

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

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

1914  {
1915  if (i >= nb_elements__) return;
1916 
1917  // erase the ith bucket
1918  erase__(getIthBucket__(i));
1919  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871
ListBucket< Val > * getIthBucket__(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1633

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

1923  {
1924  erase__(iter.getBucket__());
1925  }
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871

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

1929  {
1930  erase__(iter.getBucket__());
1931  }
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871

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

1871  {
1872  // perform deletion only if there is a bucket to remove
1873  if (bucket != nullptr) {
1874  // update the iterators pointing on this element
1875  for (const auto ptr_iter: safe_iterators__) {
1876  if (ptr_iter->bucket__ == bucket) {
1877  ptr_iter->next_current_bucket__ = bucket->prev__;
1878  ptr_iter->prev_current_bucket__ = bucket->next__;
1879  ptr_iter->bucket__ = nullptr;
1880  ptr_iter->null_pointing__ = true;
1881  } else {
1882  if (ptr_iter->null_pointing__) {
1883  if (ptr_iter->next_current_bucket__ == bucket)
1884  ptr_iter->next_current_bucket__ = bucket->prev__;
1885 
1886  if (ptr_iter->prev_current_bucket__ == bucket)
1887  ptr_iter->prev_current_bucket__ = bucket->next__;
1888  }
1889  }
1890  }
1891 
1892  // set properly the begin and end of the chained list (the other chainings
1893  // will be performed by operator delete)
1894  if (bucket->prev__ == nullptr)
1895  deb_list__ = bucket->next__;
1896  else
1897  bucket->prev__->next__ = bucket->next__;
1898 
1899  if (bucket->next__ == nullptr)
1900  end_list__ = bucket->prev__;
1901  else
1902  bucket->next__->prev__ = bucket->prev__;
1903 
1904  // remove the current element src the list
1905  alloc_bucket__.destroy(bucket);
1906  alloc_bucket__.deallocate(bucket, 1);
1907 
1908  --nb_elements__;
1909  }
1910  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
BucketAllocator alloc_bucket__
The allocator for the buckets.
Definition: list.h:1318
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1951  {
1952  for (ListBucket< Val >*iter = deb_list__, *next_bucket = nullptr;
1953  iter != nullptr;
1954  iter = next_bucket) {
1955  next_bucket = iter->next__;
1956 
1957  if (val == iter->val__) erase__(iter);
1958  }
1959  }
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1945  {
1946  erase__(getBucket__(val));
1947  }
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871
ListBucket< Val > * getBucket__(const Val &val) const noexcept
Returns the bucket corresponding to a given value.
Definition: list_tpl.h:1936

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

1862  {
1863  for (ListBucket< Val >* ptr = deb_list__; ptr != nullptr; ptr = ptr->next__)
1864  if (ptr->val__ == val) return true;
1865 
1866  return false;
1867  }
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1836  {
1837  if (nb_elements__ == Size(0)) {
1838  GUM_ERROR(NotFound, "not enough elements in the chained list");
1839  }
1840 
1841  return deb_list__->val__;
1842  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1936  {
1937  for (ListBucket< Val >* ptr = deb_list__; ptr != nullptr; ptr = ptr->next__)
1938  if (ptr->val__ == val) return ptr;
1939 
1940  return nullptr;
1941  }
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1633  {
1634  ListBucket< Val >* ptr;
1635 
1636  if (i < nb_elements__ / 2) {
1637  for (ptr = deb_list__; i; --i, ptr = ptr->next__) {}
1638  } else {
1639  for (ptr = end_list__, i = nb_elements__ - i - 1; i;
1640  --i, ptr = ptr->prev__) {}
1641  }
1642 
1643  return ptr;
1644  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1620  {
1621  return pushBack(val);
1622  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1593

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

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

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

1688  {
1689  // if ther are fewer elements than pos, put the value at the end of the list
1690  if (nb_elements__ <= pos) { return pushBack(val); }
1691 
1692  return insertBefore__(createBucket__(val), getIthBucket__(pos));
1693  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
ListBucket< Val > * getIthBucket__(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1633
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1593
Val & insertBefore__(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1648

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

1697  {
1698  // if ther are fewer elements than pos, put the value at the end of the list
1699  if (nb_elements__ <= pos) { return pushBack(std::move(val)); }
1700 
1701  return insertBefore__(createBucket__(std::move(val)), getIthBucket__(pos));
1702  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
ListBucket< Val > * getIthBucket__(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1633
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1593
Val & insertBefore__(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1648

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

1771  {
1772  // if the iterator does not point to the list, raise an exception
1773  if (iter.list__ != this) {
1774  GUM_ERROR(InvalidArgument,
1775  "the iterator does not point to the correct list");
1776  }
1777 
1778  return insert__(iter, createBucket__(val), place);
1779  }
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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:1707

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

1786  {
1787  // if the iterator does not point to the list, raise an exception
1788  if (iter.list__ != this) {
1789  GUM_ERROR(InvalidArgument,
1790  "the iterator does not point to the correct list");
1791  }
1792 
1793  return insert__(iter, createBucket__(std::move(val)), place);
1794  }
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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:1707

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

1801  {
1802  return insert__(iter, createBucket__(val), place);
1803  }
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
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:1707

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

1810  {
1811  return insert__(iter, createBucket__(std::move(val)), place);
1812  }
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
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:1707

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

1709  {
1710  // find the location around which the new element should be inserted
1711  ListBucket< Val >* ptr;
1712 
1713  if (iter.null_pointing__) {
1714  if (place == location::BEFORE) {
1715  ptr = iter.next_current_bucket__;
1716  } else {
1717  ptr = iter.prev_current_bucket__;
1718  }
1719  } else {
1720  ptr = iter.getBucket__();
1721  }
1722 
1723  if (ptr == nullptr) {
1724  // here, we are at the end of the list
1725  return pushBack__(new_elt);
1726  } else {
1727  switch (place) {
1728  case location::BEFORE:
1729  return insertBefore__(new_elt, ptr);
1730 
1731  case location::AFTER:
1732  return insertAfter__(new_elt, ptr);
1733 
1734  default:
1735  GUM_ERROR(FatalError, "List insertion for this location unimplemented");
1736  }
1737  }
1738  }
Val & insertAfter__(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition: list_tpl.h:1668
Val & pushBack__(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1547
Val & insertBefore__(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1648
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1745  {
1746  // find the location around which the new element should be inserted
1747  ListBucket< Val >* ptr = iter.getBucket__();
1748 
1749  if (ptr == nullptr) {
1750  // here, we are at the end of the list
1751  return pushBack__(new_elt);
1752  } else {
1753  switch (place) {
1754  case location::BEFORE:
1755  return insertBefore__(new_elt, ptr);
1756 
1757  case location::AFTER:
1758  return insertAfter__(new_elt, ptr);
1759 
1760  default:
1761  GUM_ERROR(FatalError, "List insertion for this location unimplemented");
1762  }
1763  }
1764  }
Val & insertAfter__(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket after another one.
Definition: list_tpl.h:1668
Val & pushBack__(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1547
Val & insertBefore__(ListBucket< Val > *new_elt, ListBucket< Val > *current_elt)
Insert a new bucket before another one.
Definition: list_tpl.h:1648
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1669  {
1670  new_elt->prev__ = current_elt;
1671  new_elt->next__ = current_elt->next__;
1672  current_elt->next__ = new_elt;
1673 
1674  if (new_elt->next__ == nullptr)
1675  end_list__ = new_elt;
1676  else
1677  new_elt->next__->prev__ = new_elt;
1678 
1679  // update the number of elements
1680  ++nb_elements__;
1681 
1682  // returns the current value
1683  return new_elt->val__;
1684  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309

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

1649  {
1650  new_elt->next__ = current_elt;
1651  new_elt->prev__ = current_elt->prev__;
1652  current_elt->prev__ = new_elt;
1653 
1654  if (new_elt->prev__ == nullptr)
1655  deb_list__ = new_elt;
1656  else
1657  new_elt->prev__->next__ = new_elt;
1658 
1659  // update the number of elements
1660  ++nb_elements__;
1661 
1662  // returns the current value
1663  return new_elt->val__;
1664  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

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

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

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

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

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

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

2046  {
2047  // create a new empty list
2048  List< Mount, OtherAlloc > list;
2049 
2050  // fill the new list
2051  for (Size i = Size(0); i < nb_elements__; ++i)
2052  list.pushBack(mount);
2053 
2054  return list;
2055  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

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

2092  {
2093  return !operator==(src);
2094  }
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 2060 of file list_tpl.h.

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

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

2067  {
2068  return pushBack(std::move(val));
2069  }
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1593

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

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

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

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

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

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

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

2075  {
2076  // check if the two lists have at least the same number of elements
2077  if (nb_elements__ != src.nb_elements__) return false;
2078 
2079  // parse the two lists
2080  for (ListBucket< Val >*iter1 = deb_list__, *iter2 = src.deb_list__;
2081  iter1 != nullptr;
2082  iter1 = iter1->next__, iter2 = iter2->next__)
2083  if (*iter1 != *iter2) return false;
2084 
2085  return true;
2086  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

2098  {
2099  // check if we can return the element we ask for
2100  if (i >= nb_elements__) {
2101  GUM_ERROR(NotFound, "not enough elements in the chained list");
2102  }
2103 
2104  return **getIthBucket__(i);
2105  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * getIthBucket__(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1633
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

2109  {
2110  // check if we can return the element we ask for
2111  if (i >= nb_elements__) {
2112  GUM_ERROR(NotFound, "not enough elements in the chained list");
2113  }
2114 
2115  return **getIthBucket__(i);
2116  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * getIthBucket__(Size i) const noexcept
Returns the bucket corresponding to the ith position in the list.
Definition: list_tpl.h:1633
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1963  {
1965  }
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309

◆ popFront()

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

Removes the first element of a List, if any.

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

Definition at line 1969 of file list_tpl.h.

1969  {
1971  }
void erase__(ListBucket< Val > *bucket)
Removes an element from a chained list.
Definition: list_tpl.h:1871
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

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

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

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

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

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

1593  {
1594  return pushBack__(createBucket__(val));
1595  }
Val & pushBack__(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1547
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476

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

1599  {
1600  return pushBack__(createBucket__(std::move(val)));
1601  }
Val & pushBack__(ListBucket< Val > *new_elt)
Insert a bucket at the end of the list.
Definition: list_tpl.h:1547
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476

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

1547  {
1548  // place the bucket at the end of the list
1549  new_elt->prev__ = end_list__;
1550 
1551  if (end_list__ != nullptr)
1552  end_list__->next__ = new_elt;
1553  else
1554  deb_list__ = new_elt;
1555 
1556  end_list__ = new_elt;
1557 
1558  // update the number of elements
1559  ++nb_elements__;
1560 
1561  // returns the current value
1562  return new_elt->val__;
1563  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1567  {
1568  return pushFront__(createBucket__(val));
1569  }
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
Val & pushFront__(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1528

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

1573  {
1574  return pushFront__(createBucket__(std::move(val)));
1575  }
ListBucket< Val > * createBucket__(const Val &val) const
Create a new bucket with a given value.
Definition: list_tpl.h:1476
Val & pushFront__(ListBucket< Val > *new_elt)
Insert a bucket at the front of the list.
Definition: list_tpl.h:1528

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

1528  {
1529  new_elt->next__ = deb_list__;
1530 
1531  if (deb_list__ != nullptr)
1532  deb_list__->prev__ = new_elt;
1533  else
1534  end_list__ = new_elt;
1535 
1536  deb_list__ = new_elt;
1537 
1538  // update the number of elements
1539  ++nb_elements__;
1540 
1541  // return the inserted element
1542  return new_elt->val__;
1543  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

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

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

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

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

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

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

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

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

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

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

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

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

1856  {
1857  return nb_elements__;
1858  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312

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

2120  {
2121  std::swap(deb_list__, other_list.deb_list__);
2122  std::swap(end_list__, other_list.end_list__);
2123  std::swap(nb_elements__, other_list.nb_elements__);
2124  std::swap(safe_iterators__, other_list.safe_iterators__);
2125  std::swap(alloc_bucket__, other_list.alloc_bucket__);
2126  }
Size nb_elements__
The number of elements in the list.
Definition: list.h:1312
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
ListBucket< Val > * end_list__
A pointer on the last element of the chained list.
Definition: list.h:1309
BucketAllocator alloc_bucket__
The allocator for the buckets.
Definition: list.h:1318
std::vector< const_iterator_safe *> safe_iterators__
The list of "safe" iterators attached to the list.
Definition: list.h:1315
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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

1981  {
1982  bool deja = false;
1983  std::stringstream stream;
1984  stream << "[";
1985 
1986  for (ListBucket< Val >* ptr = deb_list__; ptr != nullptr;
1987  ptr = ptr->next__, deja = true) {
1988  if (deja) stream << " --> ";
1989 
1990  stream << ptr->val__;
1991  }
1992 
1993  stream << "]";
1994 
1995  return stream.str();
1996  }
ListBucket< Val > * deb_list__
A pointer on the first element of the chained list.
Definition: list.h:1306

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 1452 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 1454 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 1451 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 1453 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 1318 of file list.h.

◆ deb_list__

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

A pointer on the first element of the chained list.

Definition at line 1306 of file list.h.

◆ end_list__

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

A pointer on the last element of the chained list.

Definition at line 1309 of file list.h.

◆ nb_elements__

template<typename Val, typename Alloc = std::allocator< Val >>
Size gum::List< Val, Alloc >::nb_elements__ {Size(0)}
private

The number of elements in the list.

Definition at line 1312 of file list.h.

◆ safe_iterators__

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

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

Definition at line 1315 of file list.h.


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