45template<
class E,
bool isConst,
bool isReverse>
46class ListIteratorBase;
85 template<
class...
Args>
102template<
class E,
bool isConst,
bool isReverse>
111 using Elem =
typename std::conditional<isConst, const E, E>::type;
243 for (
const E& x : init) {
257 L.m_head =
L.m_tail =
nullptr;
541 L.m_head =
L.m_tail =
nullptr;
549 while (
pX !=
nullptr &&
pY !=
nullptr) {
550 if (
pX->m_x !=
pY->m_x) {
556 return pX ==
nullptr &&
pY ==
nullptr;
584 template<
class...
Args>
610 template<
class...
Args>
788 if (!std::is_trivially_destructible<E>::value) {
815 std::swap(
pX->m_next,
pY->m_next);
816 std::swap(
pX->m_prev,
pY->m_prev);
818 std::swap(
pX->m_list,
pY->m_list);
821 if (
pX->m_next ==
pX) {
825 if (
pX->m_prev ==
pX) {
831 pX->m_prev->m_next =
pX;
837 pY->m_prev->m_next =
pY;
843 pX->m_next->m_prev =
pX;
849 pY->m_next->m_prev =
pY;
878 pX->m_prev =
nullptr;
907 pX->m_next =
nullptr;
939 (
pX->m_prev =
pY)->m_next =
pX;
975 (
pX->m_next =
pY)->m_prev =
pX;
1003 pX->m_prev =
nullptr;
1004 if ((
pX->m_next =
L2.m_head) !=
nullptr) {
1005 L2.m_head =
L2.m_head->m_prev =
pX;
1007 L2.m_head =
L2.m_tail =
pX;
1035 pX->m_next =
nullptr;
1036 if ((
pX->m_prev =
L2.m_tail) !=
nullptr) {
1037 L2.m_tail =
L2.m_tail->m_next =
pX;
1039 L2.m_head =
L2.m_tail =
pX;
1071 (
pX->m_prev =
pY)->m_next =
pX;
1107 (
pX->m_next =
pY)->m_prev =
pX;
1134 L2.m_head =
L2.m_tail =
nullptr;
1152 L2.m_head =
L2.m_tail =
nullptr;
1161 other.reassignListRefs();
1188 L1.m_tail =
L2.m_head->m_prev;
1191 L2.m_head =
L1.m_tail->m_next;
1193 L2.m_head->m_prev =
L1.m_tail->m_next =
nullptr;
1196 L1.m_head =
L1.m_tail =
nullptr;
1201 if (
this != &
L1 &&
this != &
L2) {
1205 L1.reassignListRefs();
1206 L2.reassignListRefs();
1216 (
L2.m_head =
pX->m_next)->m_prev =
nullptr;
1217 pX->m_next =
nullptr;
1222 L2.reassignListRefs();
1233 if ((
m_tail =
pX->m_prev) ==
nullptr) {
1236 m_tail->m_next =
nullptr;
1238 pX->m_prev =
nullptr;
1240 L2.reassignListRefs();
1250 pX->m_next =
pX->m_prev;
1289 template<
class COMPARER>
1293 if (
comp.equal(*i, e)) {
1303 template<
class COMPARER>
1307 if (
comp.equal(*i, e)) {
1318 template<
class COMPARER>
1349 std::function<
bool(
const E&)>
includeElement = [](
const E&) {
return true; },
1356 std::function<
bool(
const E&)>
includeElement = [](
const E&) {
return true; },
1370 std::function<
bool(
const E&)>
includeElement = [](
const E&) {
return true; },
1379 std::function<
bool(
const E&)>
includeElement = [](
const E&) {
return true; },
1415 for (
auto e = start ==
nullptr ?
m_head : start; e !=
nullptr; e = e->m_next) {
1524 template<
class...
Args>
1537 template<
class...
Args>
1680 if (this->m_head ==
nullptr) {
1718 if (m_head == m_tail) {
1725 for (
pX = m_head;
pX;
pX =
pX->m_next) {
1726 int i =
f.getBucket(
pX->m_x);
1728 tail[i] = ((
pX->m_prev = tail[i])->m_next =
pX);
1730 head[i] = tail[i] =
pX;
1735 for (
int i =
l; i <=
h; i++) {
1739 (
pY->m_next =
pX)->m_prev =
pY;
1741 (m_head =
pX)->m_prev =
nullptr;
1748 pY->m_next =
nullptr;
1760 A[0] =
A[n + 1] =
nullptr;
1764 for (
pX = m_head;
pX;
pX =
pX->m_next) {
1768 A.permute(1, n,
rng);
1770 for (i = 1; i <= n; i++) {
1772 pX->m_next =
A[i + 1];
1773 pX->m_prev =
A[i - 1];
1786 for (++
pX;
pX.valid(); ++
pX) {
1808 return os <<
L.getListPure();
1811template<
class E,
class Master>
Implementation of the Reverse class for the reverse iteration of containers.
The parameterized class Array implements dynamic arrays of type E.
Abstract base class for bucket functions.
iterator begin() const
Returns an iterator to the first element in the container.
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
typename List< E >::const_reverse_iterator reverse_iterator
Provides a bidirectional reverse iterator to an object in the container.
iterator end() const
Returns an iterator to the one-past-last element in the container.
reverse_iterator rend() const
Returns a reverse iterator to the one-before-first element in the container.
int size() const
Returns the number of elements in the container.
typename List< E >::const_iterator iterator
Provides a bidirectional iterator to an object in the container.
Structure for elements of doubly linked lists.
ListElement(ListPure< E > *list, const E &x)
Constructs a ListElement.
ListElement(ListPure< E > *list, const E &x, ListElement< E > *next, ListElement< E > *prev)
Constructs a ListElement.
ListElement< E > * m_next
Pointer to successor element.
ListElement< E > * m_prev
Pointer to predecessor element.
ListElement(ListPure< E > *list, ListElement< E > *next, ListElement< E > *prev, Args &&... args)
Constructs a ListElement with given arguments args for constructor of element type.
Doubly linked lists (maintaining the length of the list).
void popFront()
Removes the first element from the list.
List(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
List(const List< E > &L)
Constructs a doubly linked list that is a copy of L.
int size() const
Returns the number of elements in the list.
const ListPure< E > & getListPure() const
Conversion to const ListPure.
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
List()
Constructs an empty doubly linked list.
void clear()
Removes all elements from the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
void moveToFront(iterator it, List< E > &L2)
Moves it to the begin of the list.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
void del(iterator it)
Removes it from the list.
void moveToPrec(iterator it, List< E > &L2, iterator itAfter)
Moves it before itAfter.
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
void split(iterator it, List< E > &L1, List< E > &L2, Direction dir=Direction::before)
Splits the list at element it into lists L1 and L2.
List< E > & operator=(const List< E > &L)
Assignment operator.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
int m_count
The length of the list.
List(List< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
E popBackRet()
Removes the last element from the list and returns it.
void swap(List< E > &other)
Exchanges the contents of this list and other in constant time.
bool operator==(const List< E > &L) const
Equality operator.
void moveToBack(iterator it, List< E > &L2)
Moves it to the end of the list.
List< E > & operator=(List< E > &&L)
Assignment operator (move semantics).
bool operator!=(const List< E > &L) const
Inequality operator.
void moveToSucc(iterator it, List< E > &L2, iterator itBefore)
Moves it after itBefore.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
void popBack()
Removes the last element from the list.
E popFrontRet()
Removes the first element from the list and returns it.
void concFront(List< E > &L2)
Prepends L2 to this list and makes L2 empty.
void conc(List< E > &L2)
Appends L2 to this list and makes L2 empty.
Encapsulates a pointer to a list element.
ListIteratorBase(const ListIteratorBase< E, isConst, isReverse > &it)
Copy constructor.
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
bool operator==(const ListIteratorBase< E, isConst, isReverse > &it) const
Equality operator.
bool operator!=(const ListIteratorBase< E, isConst, isReverse > &it) const
Inequality operator.
bool valid() const
Returns true iff the iterator points to an element.
ListIteratorBase< E, isConst, isReverse > operator--(int)
Decrement operator (postfix).
ListIteratorBase()
Constructs an invalid iterator.
ListIteratorBase< E, isConst, isReverse > operator++(int)
Increment operator (postfix).
ListIteratorBase< E, isConst, isReverse > & operator++()
Increment operator (prefix).
typename std::conditional< isConst, const E, E >::type Elem
The underlying type, depending on isConst.
ListElem * m_pX
pointer to list element
ListIteratorBase< E, isConst, isReverse > & operator=(const ListIteratorBase< E, isConst, isReverse > &it)
Assignment operator.
ListIteratorBase< E, isConst, isReverse > & operator--()
Decrement operator (prefix).
typename std::conditional< isConst, const ListElement< E >, ListElement< E > >::type ListElem
The underlying list element, depending on isConst.
ListIteratorBase(const ListIteratorBase< E, isArgConst, isArgReverse > &it)
Constructs an iterator that is a copy of it.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Elem & operator*() const
Returns a reference to the element content.
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
iterator begin()
Returns an iterator to the first element of the list.
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
E & reference
Provides a reference to an element stored in a list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
void moveToFront(iterator it, ListPure< E > &L2)
Moves it to the begin of L2.
const_iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns an iterator to a random element.
ListIterator< E > search(const E &e)
Scans the list for the specified element and returns an iterator to the first occurrence in the list,...
void splitAfter(iterator it, ListPure< E > &L2)
Splits the list after it.
ListIterator< E > iterator
Provides a bidirectional iterator that can read or modify any element in a list.
virtual ~ListPure()
Destructor.
const_iterator begin() const
Returns a const iterator to the first element of the list.
void concFront(ListPure< E > &L2)
Prepends L2 to this list and makes L2 empty.
void reverse()
Reverses the order of the list elements.
const_iterator cyclicSucc(const_iterator it) const
Returns a const iterator to the cyclic successor of it.
const_reverse_iterator rend() const
Returns a const iterator to one-before-first element of the list.
ListConstIterator< E > const_iterator
Provides a bidirectional iterator that can read a const element in a list.
void moveToBack(iterator it)
Moves it to the end of the list.
ListIterator< E > search(const E &e, const COMPARER &comp)
Scans the list for the specified element (using the user-defined comparer) and returns an iterator to...
ListPure(const ListPure< E > &L)
Constructs a doubly linked list that is a copy of L.
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
const_reverse_iterator cyclicPred(const_reverse_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
ListPure(ListPure< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
const_reference front() const
Returns a const reference to the first element.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
const_reverse_iterator cyclicSucc(const_reverse_iterator it) const
Returns a const iterator to the cyclic successor of it.
ListPure< E > & operator=(const ListPure< E > &L)
Assignment operator.
const_iterator get(int pos) const
Returns a const iterator pointing to the element at position pos.
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
reverse_iterator cyclicSucc(reverse_iterator it)
Returns a const iterator to the cyclic successor of it.
const_reference back() const
Returns a const reference to the last element.
E value_type
Represents the data type stored in a list element.
reference back()
Returns a reference to the last element.
void permute()
Randomly permutes the elements in the list.
void moveToBack(iterator it, ListPure< E > &L2)
Moves it to the end of L2.
void copy(const ListPure< E > &L)
iterator cyclicPred(iterator it)
Returns an iterator to the cyclic predecessor of it.
iterator get(int pos)
Returns an iterator pointing to the element at position pos.
E popFrontRet()
Removes the first element from the list and returns it.
const_reverse_iterator crbegin() const
Returns a const iterator to the last element of the list.
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
void exchange(iterator it1, iterator it2)
Exchanges the positions of it1 and it2 in the list.
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
virtual int size() const
Returns the number of elements in the list.
void clear()
Removes all elements from the list.
void split(iterator it, ListPure< E > &L1, ListPure< E > &L2, Direction dir=Direction::before)
Splits the list at element it into lists L1 and L2.
void del(iterator it)
Removes it from the list.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
void moveToPrec(iterator it, iterator itAfter)
Moves it before itAfter.
ListPure< E > & operator=(ListPure< E > &&L)
Assignment operator (move semantics).
ListConstReverseIterator< E > const_reverse_iterator
Provides a bidirectional reverse iterator that can read a const element in a list.
bool operator==(const ListPure< E > &L) const
Equality operator.
void popBack()
Removes the last element from the list.
ListPure()
Constructs an empty doubly linked list.
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
ListElement< E > * m_tail
Pointer to last element.
ListPure(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
const_reverse_iterator crend() const
Returns a const iterator to one-before-first element of the list.
void reassignListRefs(ListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
void conc(ListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
void splitBefore(iterator it, ListPure< E > &L2)
Splits the list before it.
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
ListConstIterator< E > search(const E &e, const COMPARER &comp) const
Scans the list for the specified element (using the user-defined comparer) and returns an iterator to...
bool operator!=(const ListPure< E > &L) const
Inequality operator.
void moveToFront(iterator it)
Moves it to the begin of the list.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
void permute(const int n, RNG &rng)
permutes elements in list randomly; n is the length of the list
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
const_reverse_iterator rbegin() const
Returns a const iterator to the last element of the list.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
E popBackRet()
Removes the last element from the list and returns it.
void swap(ListPure< E > &other)
Exchanges the contents of this list and other in constant time.
ListReverseIterator< E > reverse_iterator
Provides a bidirectional reverse iterator that can read or modify any element in a list.
reference front()
Returns a reference to the first element.
bool empty() const
Returns true iff the list is empty.
reverse_iterator cyclicPred(reverse_iterator it)
Returns a const iterator to the cyclic predecessor of it.
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations.
void moveToSucc(iterator it, iterator itBefore)
Moves it after itBefore.
reverse_iterator rend()
Returns an iterator to one-before-first element of the list.
void quicksort()
Sorts the list using Quicksort.
ListElement< E > * m_head
Pointer to first element.
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
ListConstIterator< E > search(const E &e) const
Scans the list for the specified element and returns an iterator to the first occurrence in the list,...
iterator end()
Returns an iterator to one-past-last element of the list.
void moveToSucc(iterator it, ListPure< E > &L2, iterator itBefore)
Moves it to list L2 and inserts it after itBefore.
void moveToPrec(iterator it, ListPure< E > &L2, iterator itAfter)
Moves it to list L2 and inserts it before itAfter.
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
void popFront()
Removes the first element from the list.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
Implementation of algorithms as templates working with different list types.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
CONTAINER::iterator chooseIteratorFrom(CONTAINER &container, std::function< bool(const TYPE &)> includeElement=[](const TYPE &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element in the container.
void quicksortTemplate(LIST &L)
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.