 |
Open Graph Drawing Framework |
v. 2022.02 (Dogwood)
|
|
|
Go to the documentation of this file.
40 template<
class E>
class List;
75 template<
class ... Args>
77 :
ListElement(list, E(
std::forward<Args>(args)...), next, prev) { }
92 template<
class E,
bool isConst,
bool isReverse>
class ListIteratorBase {
134 bool operator==(
const ListIteratorBase<E, isConst, isReverse> &it)
const {
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;
202 template<
class E>
class ListPure {
228 for (
const E &x :
init)
243 L.m_head = L.m_tail =
nullptr;
314 if (
pos-- == 0)
break;
325 if (
pos-- == 0)
break;
518 L.m_head = L.m_tail =
nullptr;
526 while(pX !=
nullptr && pY !=
nullptr) {
527 if(pX->
m_x != pY->m_x)
532 return pX ==
nullptr && pY ==
nullptr;
561 template<
class ... Args>
585 template<
class ... Args>
609 if (pYnext) pYnext->
m_prev = pX;
614 if (pYprev) pYprev->
m_next = pX;
629 if (pYprev) pYprev->
m_next = pX;
643 if (pYnext) pYnext->
m_prev = pX;
709 if (pPrev) pPrev->
m_next = pNext;
711 if (pNext) pNext->m_prev = pPrev;
725 del(pX);
return true;
732 if (
m_head ==
nullptr)
return;
734 if (!std::is_trivially_destructible<E>::value) {
760 std::swap(pX->
m_next,pY->m_next);
761 std::swap(pX->
m_prev,pY->m_prev);
763 std::swap(pX->m_list,pY->m_list);
767 pX->
m_next = pY; pY->m_prev = pX;
770 pX->
m_prev = pY; pY->m_next = pX;
776 if(pY->m_prev) pY->
m_prev->m_next = pY;
782 if(pY->m_next) pY->
m_next->m_prev = pY;
798 if (pPrev) pPrev->m_next = pNext;
799 if (pNext) pNext->m_prev = pPrev;
819 if (pPrev) pPrev->m_next = pNext;
821 if (pNext) pNext->m_prev = pPrev;
839 if(pX == pY || pPrev == pY)
return;
842 if (pPrev) pPrev->m_next = pNext;
844 if (pNext) pNext->m_prev = pPrev;
848 (pX->
m_prev = pY)->m_next = pX;
849 if (pYnext) pYnext->
m_prev = pX;
864 if(pX == pY || pNext == pY)
return;
867 if (pPrev) pPrev->m_next = pNext;
869 if (pNext) pNext->m_prev = pPrev;
873 (pX->
m_next = pY)->m_prev = pX;
874 if (pYprev) pYprev->
m_next = pX;
887 if (pPrev) pPrev->m_next = pNext;
889 if (pNext) pNext->m_prev = pPrev;
893 if ((pX->
m_next = L2.m_head) !=
nullptr)
894 L2.m_head = L2.m_head->m_prev = pX;
896 L2.m_head = L2.m_tail = pX;
912 if (pPrev) pPrev->m_next = pNext;
914 if (pNext) pNext->m_prev = pPrev;
918 if ((pX->
m_prev = L2.m_tail) !=
nullptr)
919 L2.m_tail = L2.m_tail->m_next = pX;
921 L2.m_head = L2.m_tail = pX;
939 if (pPrev) pPrev->m_next = pNext;
941 if (pNext) pNext->m_prev = pPrev;
946 (pX->
m_prev = pY)->m_next = pX;
947 if (pYnext) pYnext->
m_prev = pX;
966 if (pPrev) pPrev->m_next = pNext;
968 if (pNext) pNext->m_prev = pPrev;
973 (pX->
m_next = pY)->m_prev = pX;
974 if (pYprev) pYprev->
m_next = pX;
986 m_tail->m_next = L2.m_head;
990 L2.m_head->m_prev =
m_tail;
996 L2.m_head = L2.m_tail =
nullptr;
1003 m_head->m_prev = L2.m_tail;
1007 L2.m_tail->m_next =
m_head;
1013 L2.m_head = L2.m_tail =
nullptr;
1018 std::swap(
m_head, other.m_head);
1019 std::swap(
m_tail, other.m_tail);
1022 other.reassignListRefs();
1037 if (&L1 !=
this) L1.clear();
1038 if (&L2 !=
this) L2.clear();
1045 L1.m_tail = L2.m_head->m_prev;
1049 L2.m_head = L1.m_tail->m_next;
1051 L2.m_head->m_prev = L1.m_tail->m_next =
nullptr;
1054 L1.m_head = L1.m_tail =
nullptr;
1059 if (
this != &L1 &&
this != &L2) {
1063 L1.reassignListRefs();
1064 L2.reassignListRefs();
1074 (L2.m_head = pX->
m_next)->m_prev =
nullptr;
1080 L2.reassignListRefs();
1089 L2.m_head = pX; L2.m_tail =
m_tail;
1093 m_tail->m_next =
nullptr;
1096 L2.reassignListRefs();
1122 if (*i == e)
return i;
1130 if (*i == e)
return i;
1135 template<
class COMPARER>
1139 if (comp.equal(*i, e))
return i;
1144 template<
class COMPARER>
1148 if (comp.equal(*i, e))
return i;
1158 template<
class COMPARER>
1189 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1190 bool isFastTest =
true)
const {
1196 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1197 bool isFastTest =
true) {
1210 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1211 bool isFastTest =
true)
const {
1219 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
1220 bool isFastTest =
true) {
1242 for(
ListElement<E> *pX = L.m_head; pX !=
nullptr; pX = pX->m_next)
1249 void permute(
const int n, RNG &rng);
1254 for(
auto e = start ==
nullptr ?
m_head : start; e !=
nullptr; e = e->m_next) {
1274 class List :
private ListPure<E> {
1367 template<
class ... Args>
1380 template<
class ... Args>
1505 std::swap(
m_count, other.m_count);
1511 int countL =
m_count, countL1 = 0;
1512 for(
ListElement<E> *pX = L1.m_head; pX !=
nullptr; pX = pX->m_next)
1515 L1.m_count = countL1;
1516 L2.m_count = countL - countL1;
1517 if (this->m_head ==
nullptr)
m_count = 0;
1554 if (m_head == m_tail)
return;
1559 for (pX = m_head; pX; pX = pX->
m_next) {
1562 tail[i] = ((pX->
m_prev = tail[i])->m_next = pX);
1564 head[i] = tail[i] = pX;
1568 for (
int i = l; i <= h; i++) {
1572 (pY->
m_next = pX)->m_prev = pY;
1574 (m_head = pX)->
m_prev =
nullptr;
1588 if (n == 0) {
return; }
1591 A[0] =
A[n+1] =
nullptr;
1595 for (pX = m_head; pX; pX = pX->
m_next)
1600 for (i = 1; i <= n; i++) {
1617 for(++pX; pX.valid(); ++pX)
1626 print(os, L.getListPure(), delim);
1641 return os << L.getListPure();
1644 template<
class E,
class Master>
const_iterator begin() const
Returns a const iterator to the first element of the list.
ListElement(ListPure< E > *list, const E &x, ListElement< E > *next, ListElement< E > *prev)
Constructs a ListElement.
void reassignListRefs(ListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
E & reference
Provides a reference to an element stored in a list.
The namespace for all OGDF objects.
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
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 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 moveToPrec(iterator it, ListPure< E > &L2, iterator itAfter)
Moves it to list L2 and inserts it before itAfter.
const_iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns an iterator to a random element.
void moveToBack(iterator it, List< E > &L2)
Moves it to the end of the list.
ListElement< E > * m_head
Pointer to first element.
ListConstReverseIterator< E > const_reverse_iterator
Provides a bidirectional reverse iterator that can read a const element in a list.
void copy(const ListPure< E > &L)
void clear()
Removes all elements from the list.
ListIteratorBase(const ListIteratorBase< E, isArgConst, isArgReverse > &it)
Constructs an iterator that is a copy of it.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
void conc(List< E > &L2)
Appends L2 to this list and makes L2 empty.
void swap(List< E > &other)
Exchanges the contents of this list and other in constant time.
void splitAfter(iterator it, ListPure< E > &L2)
Splits the list after it.
ListIteratorBase< E, isConst, isReverse > & operator++()
Increment operator (prefix).
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
ListElement(ListPure< E > *list, const E &x)
Constructs a ListElement.
void popFront()
Removes the first element from the list.
void moveToSucc(iterator it, ListPure< E > &L2, iterator itBefore)
Moves it to list L2 and inserts it after itBefore.
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
reference back()
Returns a reference to the last element.
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.
virtual int size() const
Returns the number of elements in the list.
List(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
const_reference back() const
Returns a const reference to the last element.
E popFrontRet()
Removes the first element from the list and returns it.
bool operator!=(const ListIteratorBase< E, isConst, isReverse > &it) const
Inequality operator.
bool operator==(const ListPure< E > &L) const
Equality operator.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
iterator begin()
Returns an iterator to the first element of the list.
E popBackRet()
Removes the last element from the list and returns it.
bool valid() const
Returns true iff the iterator points to an element.
bool operator==(const List< E > &L) const
Equality operator.
const_reverse_iterator crbegin() const
Returns a const iterator to the last element of the list.
void popFront()
Removes the first element from the list.
Abstract base class for bucket functions.
ListIterator< E > iterator
Provides a bidirectional iterator that can read or modify any element in a list.
const_iterator cyclicSucc(const_iterator it) const
Returns a const iterator to the cyclic successor of it.
List< E > & operator=(const List< E > &L)
Assignment operator.
void exchange(iterator it1, iterator it2)
Exchanges the positions of it1 and it2 in the list.
const_iterator get(int pos) const
Returns a const iterator pointing to the element at position pos.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
typename List< ogdf::ClusterElement >::const_reverse_iterator reverse_iterator
Provides a bidirectional reverse iterator to an object in the container.
ListIterator< E > search(const E &e)
Scans the list for the specified element and returns an iterator to the first occurrence in the list,...
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
ListElement< E > * m_next
Pointer to successor element.
void conc(ListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
ListPure(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
void concFront(List< E > &L2)
Prepends L2 to this list and makes L2 empty.
iterator end()
Returns an iterator to one-past-last element of the list.
ListPure< E > & operator=(const ListPure< E > &L)
Assignment operator.
int m_count
The length of the list.
int size() const
Returns the number of elements in the container.
void moveToBack(iterator it)
Moves it to the end of the list.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
void moveToSucc(iterator it, iterator itBefore)
Moves it after itBefore.
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
ListElement(ListPure< E > *list, ListElement< E > *next, ListElement< E > *prev, Args &&... args)
Constructs a ListElement with given arguments args for constructor of element type.
typename List< ogdf::ClusterElement >::const_iterator iterator
Provides a bidirectional iterator to an object in the container.
ListElem * m_pX
pointer to list element
ListPure(const ListPure< E > &L)
Constructs a doubly linked list that is a copy of L.
List< E > & operator=(List< E > &&L)
Assignment operator (move semantics).
ListIteratorBase< E, isConst, isReverse > operator--(int)
Decrement operator (postfix).
E popFrontRet()
Removes the first element from the list and returns it.
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Implementation of algorithms as templates working with different list types.
void concFront(ListPure< E > &L2)
Prepends L2 to this list and makes L2 empty.
Elem & operator*() const
Returns a reference to the element content.
iterator cyclicPred(iterator it)
Returns an iterator to the cyclic predecessor of it.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
void moveToFront(iterator it)
Moves it to the begin of the 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...
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
const T & move(const T &v)
The parameterized class Array implements dynamic arrays of type E.
void swap(ListPure< E > &other)
Exchanges the contents of this list and other in constant time.
virtual ~ListPure()
Destructor.
iterator begin() const
Returns an iterator to the first element in the container.
void moveToSucc(iterator it, List< E > &L2, iterator itBefore)
Moves it after itBefore.
void moveToPrec(iterator it, List< E > &L2, iterator itAfter)
Moves it before itAfter.
ListIteratorBase< E, isConst, isReverse > operator++(int)
Increment operator (postfix).
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
void moveToBack(iterator it, ListPure< E > &L2)
Moves it to the end of L2.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
reverse_iterator rend()
Returns an iterator to one-before-first element of the list.
ListIteratorBase< E, isConst, isReverse > & operator--()
Decrement operator (prefix).
Abstract Base class for graph observers.
Doubly linked lists (maintaining the length of the list).
void reverse()
Reverses the order of the list elements.
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...
void popBack()
Removes the last element from the list.
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
ListConstIterator< E > const_iterator
Provides a bidirectional iterator that can read a const element in a list.
E popBackRet()
Removes the last element from the list and returns it.
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
reverse_iterator cyclicPred(reverse_iterator it)
bool operator!=(const ListPure< E > &L) const
Inequality operator.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
void moveToPrec(iterator it, iterator itAfter)
Moves it before itAfter.
const_reverse_iterator rend() const
Returns a const iterator to one-before-first element of the list.
List()
Constructs an empty doubly linked list.
ListPure< E > & operator=(ListPure< E > &&L)
Assignment operator (move semantics).
const_reverse_iterator rbegin() const
Returns a const iterator to the last element of the list.
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
Structure for elements of doubly linked lists.
Implementation of the Reverse class for the reverse iteration of containers.
const_reverse_iterator cyclicSucc(const_reverse_iterator it) const
ListPure()
Constructs an empty doubly linked list.
bool operator==(const ListIteratorBase< E, isConst, isReverse > &it) const
Equality operator.
void quicksort()
Sorts the list using Quicksort.
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
ListIteratorBase< E, isConst, isReverse > & operator=(const ListIteratorBase< E, isConst, isReverse > &it)
Assignment operator.
ListPure(ListPure< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
const ListPure< E > & getListPure() const
Conversion to const ListPure.
void del(iterator it)
Removes it from the list.
const_reverse_iterator cyclicPred(const_reverse_iterator it) const
void popBack()
Removes the last element from the list.
typename std::conditional< isConst, const ListElement< E >, ListElement< E > >::type ListElem
The underlying list element, depending on isConst.
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.
const_reverse_iterator crend() const
Returns a const iterator to one-before-first element of the list.
ListIteratorBase()
Constructs an invalid iterator.
void moveToFront(iterator it, ListPure< E > &L2)
Moves it to the begin of L2.
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
reference front()
Returns a reference to the first element.
const_reference front() const
Returns a const reference to the first element.
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
int size() const
Returns the number of elements in the list.
iterator get(int pos)
Returns an iterator pointing to the element at position pos.
Encapsulates a pointer to a list element.
List(List< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
reverse_iterator cyclicSucc(reverse_iterator it)
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
ListElement< E > * m_tail
Pointer to last element.
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
void quicksortTemplate(LIST &L)
ListIteratorBase(const ListIteratorBase< E, isConst, isReverse > &it)
Copy constructor.
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,...
void splitBefore(iterator it, ListPure< E > &L2)
Splits the list before it.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
void del(iterator it)
Removes it from the list.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
bool operator!=(const List< E > &L) const
Inequality operator.
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations.
List(const List< E > &L)
Constructs a doubly linked list that is a copy of L.
typename std::conditional< isConst, const ogdf::EdgeElement, ogdf::EdgeElement >::type Elem
The underlying type, depending on isConst.
virtual int getBucket(const E &x)=0
Returns the bucket of x.
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
bool empty() const
Returns true iff the list is empty.
iterator pushBack(const E &x)
Adds element x at the end of the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
void clear()
Removes all elements from the list.
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
void moveToFront(iterator it, List< E > &L2)
Moves it to the begin of the list.
ListReverseIterator< E > reverse_iterator
Provides a bidirectional reverse iterator that can read or modify any element in a list.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
void permute()
Randomly permutes the elements in the list.
E value_type
Represents the data type stored in a list element.
ListElement< E > * m_prev
Pointer to predecessor element.