36#include <ogdf/basic/internal/config_autogen.h>
41#include <initializer_list>
50template<
class E,
bool isConst,
bool isReverse>
51class ListIteratorBase;
95 template<
class... Args>
97 :
ListElement(list, E(
std::forward<Args>(args)...), next, prev) { }
112template<
class E,
bool isConst,
bool isReverse>
121 using Elem =
typename std::conditional<isConst, const E, E>::type;
143 template<bool isArgConst, typename std::enable_if<isConst || !isArgConst, int>::type = 0,
bool isArgReverse>
175 return isReverse ?
m_pX->m_prev :
m_pX->m_next;
180 return isReverse ?
m_pX->m_next :
m_pX->m_prev;
259 for (
const E& x : init) {
272 L.m_head = L.m_tail =
nullptr;
557 L.m_head = L.m_tail =
nullptr;
565 while (pX !=
nullptr && pY !=
nullptr) {
566 if (pX->
m_x != pY->m_x) {
572 return pX ==
nullptr && pY ==
nullptr;
600 template<
class... Args>
626 template<
class... Args>
775 pNext->m_prev = pPrev;
804 if (!std::is_trivially_destructible<E>::value) {
831 std::swap(pX->
m_next, pY->m_next);
832 std::swap(pX->
m_prev, pY->m_prev);
834 std::swap(pX->
m_list, pY->m_list);
886 pPrev->m_next = pNext;
889 pNext->m_prev = pPrev;
914 pPrev->m_next = pNext;
919 pNext->m_prev = pPrev;
938 if (pX == pY || pPrev == pY) {
944 pPrev->m_next = pNext;
949 pNext->m_prev = pPrev;
955 (pX->
m_prev = pY)->m_next = pX;
974 if (pX == pY || pNext == pY) {
980 pPrev->m_next = pNext;
985 pNext->m_prev = pPrev;
991 (pX->
m_next = pY)->m_prev = pX;
1009 pPrev->m_next = pNext;
1014 pNext->m_prev = pPrev;
1041 pPrev->m_next = pNext;
1046 pNext->m_prev = pPrev;
1075 pPrev->m_next = pNext;
1080 pNext->m_prev = pPrev;
1087 (pX->
m_prev = pY)->m_next = pX;
1111 pPrev->m_next = pNext;
1116 pNext->m_prev = pPrev;
1123 (pX->
m_next = pY)->m_prev = pX;
1217 if (
this != &L1 &&
this != &L2) {
1252 m_tail->m_next =
nullptr;
1305 template<
class COMPARER>
1309 if (comp.equal(*i, e)) {
1319 template<
class COMPARER>
1323 if (comp.equal(*i, e)) {
1334 template<
class COMPARER>
1365 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1366 bool isFastTest =
true)
const {
1372 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1373 bool isFastTest =
true) {
1386 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1387 bool isFastTest =
true)
const {
1395 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1396 bool isFastTest =
true) {
1431 for (
auto e = start ==
nullptr ?
m_head : start; e !=
nullptr; e = e->m_next) {
1540 template<
class... Args>
1553 template<
class... Args>
1689 int countL =
m_count, countL1 = 0;
1695 L2.
m_count = countL - countL1;
1696 if (this->m_head ==
nullptr) {
1734 if (m_head == m_tail) {
1741 for (pX = m_head; pX; pX = pX->
m_next) {
1744 tail[i] = ((pX->
m_prev = tail[i])->m_next = pX);
1746 head[i] = tail[i] = pX;
1751 for (
int i = l; i <= h; i++) {
1755 (pY->
m_next = pX)->m_prev = pY;
1757 (m_head = pX)->m_prev =
nullptr;
1776 A[0] =
A[n + 1] =
nullptr;
1780 for (pX = m_head; pX; pX = pX->
m_next) {
1784 A.permute(1, n, rng);
1786 for (i = 1; i <= n; i++) {
1802 for (++pX; pX.valid(); ++pX) {
1827template<
class E,
class Master>
Declaration and implementation of Array class and Array algorithms.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Abstract base class for bucket functions.
virtual int getBucket(const E &x)=0
Returns the bucket of x.
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.
ListPure< E > * m_list
List object that the element belongs to.
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.
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.
List(List< E > &&L) noexcept
Constructs a doubly linked list containing the elements of L (move semantics).
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.
std::bidirectional_iterator_tag iterator_category
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
bool operator==(const ListIteratorBase< E, isConst, isReverse > &it) const
Equality operator.
std::ptrdiff_t difference_type
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.
ListPure< E > * listOf()
Returns the list that this iterator belongs to.
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.
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)
ListPure(ListPure< E > &&L) noexcept
Constructs a doubly linked list containing the elements of L (move semantics).
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.
Declaration of memory manager for allocating small pieces of memory.
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.