40 template<
class E>
class List;
67 : m_next(next), m_prev(prev), m_x(x) {
75 template<
class ... Args>
77 :
ListElement(list, E(
std::forward<Args>(args)...), next, prev) { }
106 operator ListElem *() {
return m_pX; }
124 bool valid()
const {
return m_pX !=
nullptr; }
136 return m_pX == it.
m_pX;
141 return m_pX != it.
m_pX;
146 return isReverse ? m_pX->m_prev : m_pX->m_next;
151 return isReverse ? m_pX->m_next : m_pX->m_prev;
165 m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
172 m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
178 m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
185 m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
227 ListPure(std::initializer_list<E>
init) : m_head(nullptr), m_tail(nullptr) {
228 for (
const E &x : init)
242 L.m_head = L.m_tail =
nullptr;
256 bool empty()
const {
return m_head ==
nullptr; }
312 for(pX = m_head; pX !=
nullptr; pX = pX->
m_next)
313 if (pos-- == 0)
break;
323 for(pX = m_head; pX !=
nullptr; pX = pX->
m_next)
324 if (pos-- == 0)
break;
427 return (pX && pX->m_next) ? pX->m_next : m_head;
437 return (pX && pX->m_next) ? pX->m_next : m_head;
446 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
455 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
465 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
475 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
484 return (pX && pX->m_next) ? pX->m_next : m_head;
493 return (pX && pX->m_next) ? pX->m_next : m_head;
517 L.m_head = L.m_tail =
nullptr;
525 while(pX !=
nullptr && pY !=
nullptr) {
526 if(pX->
m_x != pY->m_x)
531 return pX ==
nullptr && pY ==
nullptr;
550 m_head = m_head->
m_prev = pX;
552 m_head = m_tail = pX;
560 template<
class ... Args>
564 m_head = m_head->
m_prev = pX;
566 m_head = m_tail = pX;
574 m_tail = m_tail->
m_next = pX;
576 m_tail = m_head = pX;
584 template<
class ... Args>
588 m_tail = m_tail->
m_next = pX;
590 m_tail = m_head = pX;
608 if (pYnext) pYnext->
m_prev = pX;
613 if (pYprev) pYprev->
m_next = pX;
628 if (pYprev) pYprev->
m_next = pX;
642 if (pYnext) pYnext->
m_prev = pX;
663 if (m_head) m_head->
m_prev =
nullptr;
664 else m_tail =
nullptr;
686 if (m_tail) m_tail->
m_next =
nullptr;
687 else m_head =
nullptr;
706 ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
708 if (pPrev) pPrev->m_next = pNext;
710 if (pNext) pNext->
m_prev = pPrev;
724 del(pX);
return true;
731 if (m_head ==
nullptr)
return;
733 if (!std::is_trivially_destructible<E>::value) {
737 OGDF_ALLOCATOR::deallocateList(
sizeof(
ListElement<E>),m_head,m_tail);
739 m_head = m_tail =
nullptr;
759 std::swap(pX->
m_next,pY->m_next);
760 std::swap(pX->
m_prev,pY->m_prev);
762 std::swap(pX->m_list,pY->m_list);
766 pX->
m_next = pY; pY->m_prev = pX;
769 pX->
m_prev = pY; pY->m_next = pX;
775 if(pY->m_prev) pY->
m_prev->m_next = pY;
781 if(pY->m_next) pY->
m_next->m_prev = pY;
792 ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
797 if (pPrev) pPrev->m_next = pNext;
798 if (pNext) pNext->m_prev = pPrev;
803 m_head = m_head->
m_prev = pX;
813 ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
818 if (pPrev) pPrev->m_next = pNext;
820 if (pNext) pNext->
m_prev = pPrev;
824 m_tail = m_tail->
m_next = pX;
835 ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
838 if(pX == pY || pPrev == pY)
return;
841 if (pPrev) pPrev->m_next = pNext;
843 if (pNext) pNext->
m_prev = pPrev;
847 (pX->m_prev = pY)->
m_next = pX;
848 if (pYnext) pYnext->
m_prev = pX;
860 ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
863 if(pX == pY || pNext == pY)
return;
866 if (pPrev) pPrev->m_next = pNext;
868 if (pNext) pNext->
m_prev = pPrev;
872 (pX->m_next = pY)->
m_prev = pX;
873 if (pYprev) pYprev->
m_next = pX;
886 if (pPrev) pPrev->m_next = pNext;
888 if (pNext) pNext->
m_prev = pPrev;
911 if (pPrev) pPrev->m_next = pNext;
913 if (pNext) pNext->
m_prev = pPrev;
938 if (pPrev) pPrev->m_next = pNext;
940 if (pNext) pNext->
m_prev = pPrev;
946 if (pYnext) pYnext->
m_prev = pX;
965 if (pPrev) pPrev->m_next = pNext;
967 if (pNext) pNext->
m_prev = pPrev;
973 if (pYprev) pYprev->
m_next = pX;
989 L2.
m_head->m_prev = m_tail;
993 reassignListRefs(L2.
m_head);
1006 L2.
m_tail->m_next = m_head;
1010 reassignListRefs(L2.
m_head);
1017 std::swap(m_head, other.
m_head);
1018 std::swap(m_tail, other.
m_tail);
1036 if (&L1 !=
this) L1.
clear();
1037 if (&L2 !=
this) L2.
clear();
1058 if (
this != &L1 &&
this != &L2) {
1059 m_head = m_tail =
nullptr;
1089 if ((m_tail = pX->
m_prev) ==
nullptr)
1092 m_tail->
m_next =
nullptr;
1120 for (i = begin(); i.
valid(); ++i)
1121 if (*i == e)
return i;
1128 for (i = begin(); i.
valid(); ++i)
1129 if (*i == e)
return i;
1134 template<
class COMPARER>
1137 for (i = begin(); i.
valid(); ++i)
1138 if (comp.equal(*i, e))
return i;
1143 template<
class COMPARER>
1146 for (i = begin(); i.
valid(); ++i)
1147 if (comp.equal(*i, e))
return i;
1157 template<
class COMPARER>
1188 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1189 bool isFastTest =
true)
const {
1195 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1196 bool isFastTest =
true) {
1209 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1210 bool isFastTest =
true)
const {
1211 const_iterator result = chooseIterator(includeElement, isFastTest);
1218 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1219 bool isFastTest =
true) {
1220 iterator result = chooseIterator(includeElement, isFastTest);
1228 permute(size(), rng);
1234 permute(size(), rng);
1248 void permute(
const int n, RNG &rng);
1253 for(
auto e = start ==
nullptr ? m_head : start; e !=
nullptr; e = e->
m_next) {
1312 int size()
const {
return m_count; }
1366 template<
class ... Args>
1379 template<
class ... Args>
1504 std::swap(m_count, other.
m_count);
1510 int countL = m_count, countL1 = 0;
1515 L2.
m_count = countL - countL1;
1516 if (this->m_head ==
nullptr) m_count = 0;
1553 if (m_head == m_tail)
return;
1558 for (pX = m_head; pX; pX = pX->
m_next) {
1563 head[i] = tail[i] = pX;
1567 for (
int i = l; i <= h; i++) {
1573 (m_head = pX)->
m_prev =
nullptr;
1587 if (n == 0) {
return; }
1590 A[0] = A[n+1] =
nullptr;
1594 for (pX = m_head; pX; pX = pX->
m_next)
1599 for (i = 1; i <= n; i++) {
1616 for(++pX; pX.valid(); ++pX)
1630 std::ostream &operator<<(std::ostream &os, const ListPure<E> &L)
1638 std::ostream &operator<<(std::ostream &os, const List<E> &L)
1640 return os << L.getListPure();
1643 template<
class E,
class Master>
void concFront(ListPure< E > &L2)
Prepends L2 to this list and makes L2 empty.
void clear()
Removes all elements from the list.
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
reverse_iterator rend() const
Returns a reverse iterator to the one-before-first element in the container.
E & reference
Provides a reference to an element stored in a list.
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...
ListElement< E > * m_tail
Pointer to last element.
void moveToBack(iterator it)
Moves it to the end of the list.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
ListIteratorBase< E, isConst, isReverse > operator++(int)
Increment operator (postfix).
ListPure(ListPure< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
The parameterized class Array implements dynamic arrays of type E.
ListElement< E > * m_prev
Pointer to predecessor element.
typename std::conditional< isConst, const ogdf::ClusterGraphObserver *, ogdf::ClusterGraphObserver * >::type Elem
The underlying type, depending on isConst.
bool operator==(const ListPure< E > &L) const
Equality operator.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
void quicksortTemplate(LIST &L)
ListIteratorBase< E, isConst, isReverse > operator--(int)
Decrement operator (postfix).
iterator pushBack(const E &x)
Adds element x at the end of the list.
void moveToPrec(iterator it, List< E > &L2, iterator itAfter)
Moves it before itAfter.
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
Elem & operator*() const
Returns a reference to the element content.
void conc(List< E > &L2)
Appends L2 to this list and makes L2 empty.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
void splitAfter(iterator it, ListPure< E > &L2)
Splits the list after it.
iterator pushBack(const E &x)
Adds element x at the end of the list.
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
void popFront()
Removes the first element from the list.
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations...
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.
iterator begin()
Returns an iterator to the first element of the list.
iterator begin() const
Returns an iterator to the first element in the container.
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.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
ListIteratorBase< E, isConst, isReverse > & operator=(const ListIteratorBase< E, isConst, isReverse > &it)
Assignment operator.
List< E > & operator=(List< E > &&L)
Assignment operator (move semantics).
const_iterator cyclicSucc(const_iterator it) const
Returns a const iterator to the cyclic successor of it.
E popBackRet()
Removes the last element from the list and returns it.
void moveToFront(iterator it)
Moves it to the begin of the list.
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
void moveToSucc(iterator it, List< E > &L2, iterator itBefore)
Moves it after itBefore.
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 conc(ListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
void moveToSucc(iterator it, ListPure< E > &L2, iterator itBefore)
Moves it to list L2 and inserts it after itBefore.
bool operator!=(const ListIteratorBase< E, isConst, isReverse > &it) const
Inequality operator.
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
const_reverse_iterator crbegin() const
Returns a const iterator to the last element of the list.
virtual int size() const
Returns the number of elements in the list.
ListIteratorBase< E, isConst, isReverse > & operator--()
Decrement operator (prefix).
ListIterator< E > search(const E &e)
Scans the list for the specified element and returns an iterator to the first occurrence in the list...
ListElement(ListPure< E > *list, const E &x)
Constructs a ListElement.
bool operator==(const List< E > &L) const
Equality operator.
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
iterator cyclicPred(iterator it)
Returns an iterator to the cyclic predecessor of it.
void del(iterator it)
Removes it from the list.
void popBack()
Removes the last element from the list.
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
List(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
bool valid() const
Returns true iff the iterator points to an element.
void del(iterator it)
Removes it from the list.
ListPure(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
ListIteratorBase(const ListIteratorBase< E, isConst, isReverse > &it)
Copy constructor.
void moveToBack(iterator it, List< E > &L2)
Moves it to the end of the list.
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
reference front()
Returns a reference to the first element.
Implementation of the Reverse class for the reverse iteration of containers.
ListElement< E > * m_next
Pointer to successor element.
const_reverse_iterator rend() const
Returns a const iterator to one-before-first element of the list.
void reverse()
Reverses the order of the list elements.
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
void quicksort()
Sorts the list using Quicksort.
const ListPure< E > & getListPure() const
Conversion to const ListPure.
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
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...
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
bool operator!=(const ListPure< E > &L) const
Inequality operator.
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
reference back()
Returns a reference to the last element.
static void copy(const T &from, T &to)
const_reference front() const
Returns a const reference to the first element.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
iterator end() const
Returns an iterator to the one-past-last element in the container.
void swap(List< E > &other)
Exchanges the contents of this list and other in constant time.
void moveToPrec(iterator it, iterator itAfter)
Moves it before itAfter.
List(List< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
void swap(ListPure< E > &other)
Exchanges the contents of this list and other in constant time.
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
ListElement(ListPure< E > *list, const E &x, ListElement< E > *next, ListElement< E > *prev)
Constructs a ListElement.
E popBackRet()
Removes the last element from the list and returns it.
Doubly linked lists (maintaining the length of the list).
ListPure(const ListPure< E > &L)
Constructs a doubly linked list that is a copy of L.
Structure for elements of doubly linked lists.
iterator end()
Returns an iterator to one-past-last element of the list.
void clear()
Removes all elements from the list.
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
E popFrontRet()
Removes the first element from the list and returns it.
void moveToBack(iterator it, ListPure< E > &L2)
Moves it to the end of L2.
void exchange(iterator it1, iterator it2)
Exchanges the positions of it1 and it2 in the list.
E popFrontRet()
Removes the first element from the list and returns it.
const_iterator begin() const
Returns a const iterator to the first element of the list.
Encapsulates a pointer to a list element.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
const_reverse_iterator crend() const
Returns a const iterator to one-before-first element of the list.
const T & move(const T &v)
void reassignListRefs(ListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
Implementation of algorithms as templates working with different list types.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Abstract base class for bucket functions.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
void bucketSort(Array< E > &a, int min, int max, BucketFunc< E > &f)
Bucket-sort array a using bucket assignment f; the values of f must be in the interval [min...
void moveToFront(iterator it, List< E > &L2)
Moves it to the begin of the list.
const_reverse_iterator cyclicSucc(const_reverse_iterator it) const
Returns a const iterator to the cyclic successor of it.
ListElem * m_pX
pointer to list element
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
void moveToFront(iterator it, ListPure< E > &L2)
Moves it to the begin of L2.
void moveToSucc(iterator it, iterator itBefore)
Moves it after itBefore.
reverse_iterator rend()
Returns an iterator to one-before-first element of the list.
int size() const
Returns the number of elements in the list.
reverse_iterator cyclicPred(reverse_iterator it)
Returns a const iterator to the cyclic predecessor of it.
void splitBefore(iterator it, ListPure< E > &L2)
Splits the list before it.
E value_type
Represents the data type stored in a list element.
int m_count
The length of the list.
List(const List< E > &L)
Constructs a doubly linked list that is a copy of L.
void popFront()
Removes the first element from the list.
virtual int getBucket(const E &x)=0
Returns the bucket of x.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
virtual ~ListPure()
Destructor.
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
const_iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns an iterator to a random element.
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
void popBack()
Removes the last element from the list.
const_reverse_iterator rbegin() const
Returns a const iterator to the last element of the list.
void concFront(List< E > &L2)
Prepends L2 to this list and makes L2 empty.
List()
Constructs an empty doubly linked list.
The namespace for all OGDF objects.
ListIteratorBase()
Constructs an invalid iterator.
ListPure()
Constructs an empty doubly linked list.
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
void copy(const ListPure< E > &L)
List< E > & operator=(const List< E > &L)
Assignment operator.
bool operator!=(const List< E > &L) const
Inequality operator.
ListElement(ListPure< E > *list, ListElement< E > *next, ListElement< E > *prev, Args &&... args)
Constructs a ListElement with given arguments args for constructor of element type.
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...
ListPure< E > & operator=(ListPure< E > &&L)
Assignment operator (move semantics).
const_reverse_iterator cyclicPred(const_reverse_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
reverse_iterator cyclicSucc(reverse_iterator it)
Returns a const iterator to the cyclic successor of it.
ListElement< E > * m_head
Pointer to first element.
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
bool empty() const
Returns true iff the list is empty.
int size() const
Returns the number of elements in the container.
ListIteratorBase(const ListIteratorBase< E, isArgConst, isArgReverse > &it)
Constructs an iterator that is a copy of it.
void moveToPrec(iterator it, ListPure< E > &L2, iterator itAfter)
Moves it to list L2 and inserts it before itAfter.
void permute()
Randomly permutes the elements in the list.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
ListIteratorBase< E, isConst, isReverse > & operator++()
Increment operator (prefix).
ListPure< E > & operator=(const ListPure< E > &L)
Assignment operator.
const_reference back() const
Returns a const reference to the last element.