60 : m_next(next), m_x(x) {
70 template<
class ... Args>
72 :
SListElement(list, E(std::forward<Args>(args)...), next) { }
99 operator ListElem *() {
return m_pX; }
113 bool valid()
const {
return m_pX !=
nullptr; }
126 return m_pX == it.
m_pX;
131 return m_pX != it.
m_pX;
193 SListPure(std::initializer_list<E> init) : m_head(nullptr), m_tail(nullptr) {
194 for (
const E &x : init)
207 L.m_head = L.m_tail =
nullptr;
220 bool empty()
const {
return m_head ==
nullptr; }
276 for(pX = m_head; pX !=
nullptr; pX = pX->
m_next)
277 if (pos-- == 0)
break;
287 for(pX = m_head; pX !=
nullptr; pX = pX->
m_next)
288 if (pos-- == 0)
break;
373 return (pX->m_next) ? pX->m_next : m_head;
383 return (pX->m_next) ? pX->m_next : m_head;
407 L.m_head = L.m_tail =
nullptr;
415 while(pX !=
nullptr && pY !=
nullptr) {
416 if(pX->
m_x != pY->m_x)
421 return (pX ==
nullptr && pY ==
nullptr);
439 if (m_tail ==
nullptr) m_tail = m_head;
447 template<
class ... Args>
449 m_head =
new SListElement<E>(
this, m_head, std::forward<Args>(args)...);
450 if (m_tail ==
nullptr) m_tail = m_head;
457 if (m_head ==
nullptr)
458 m_head = m_tail = pNew;
460 m_tail = m_tail->
m_next = pNew;
468 template<
class ... Args>
471 if (m_head ==
nullptr)
472 m_head = m_tail = pNew;
474 m_tail = m_tail->
m_next = pNew;
486 if (pBefore == m_tail) m_tail = pNew;
487 return (pBefore->m_next = pNew);
504 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
528 if ((pBefore->m_next = pDel->
m_next) ==
nullptr) m_tail = pBefore;
534 if (m_head ==
nullptr)
return;
536 if (!std::is_trivially_destructible<E>::value) {
542 m_head = m_tail =
nullptr;
558 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
572 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
593 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
594 pX->
m_next = pBefore->m_next;
595 pBefore->m_next = pX;
609 reassignListRefs(L2.
m_head);
617 for(p = m_head; p; p = pNext) {
635 for (i = begin(); i.
valid(); ++i)
636 if (*i == e)
return i;
643 for (i = begin(); i.
valid(); ++i)
644 if (*i == e)
return i;
649 template<
class COMPARER>
652 for (i = begin(); i.
valid(); ++i)
653 if (comp.equal(*i, e))
return i;
658 template<
class COMPARER>
661 for (i = begin(); i.
valid(); ++i)
662 if (comp.equal(*i, e))
return i;
672 template<
class COMPARER>
699 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
700 bool isFastTest =
true)
const {
706 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
707 bool isFastTest =
true) {
713 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
714 bool isFastTest =
true)
const {
715 const_iterator result = chooseIterator(includeElement, isFastTest);
722 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
723 bool isFastTest =
true) {
724 iterator result = chooseIterator(includeElement, isFastTest);
732 permute(size(), rng);
738 permute(size(), rng);
751 void permute(
const int n, RNG &rng);
756 for(
auto e = start ==
nullptr ? m_head : start; e !=
nullptr; e = e->
m_next) {
792 SList(std::initializer_list<E> init) :
SListPure<E>(init), m_count((int) init.size()) { }
815 int size()
const {
return m_count; }
869 template<
class ... Args>
882 template<
class ... Args>
985 if (m_head == m_tail)
return;
1005 if (m_head == m_tail)
return;
1010 for (pX = m_head; pX; pX = pX->
m_next) {
1013 tail[i] = (tail[i]->m_next = pX);
1015 head[i] = tail[i] = pX;
1019 for (
int i = l; i <= h; i++) {
1043 for (pX = m_head; pX; pX = pX->
m_next)
1048 for (i = 0; i < n; i++) {
1049 A[i]->m_next = A[i+1];
1063 for(++pX; pX.valid(); ++pX)
1077 ostream &operator<<(ostream &os, const SListPure<E> &L)
1085 ostream &operator<<(ostream &os, const SList<E> &L)
1095 if (a.
low() >= a.
high())
return;
1100 for(i = a.
low(); i <= a.
high(); ++i)
1101 bucket[f.
getBucket(a[i])].pushBack(a[i]);
1104 for(
int j = min; j <= max; ++j) {
1106 for(; it.
valid(); ++it)
SList< E > & operator=(SList< E > &&L)
Assignment operator (move semantics).
bool operator==(const SListIteratorBase< E, isConst > &it) const
Equality operator.
SListElement(SListPure< E > *list, SListElement< E > *next, Args &&... args)
Constructs an SListElement with given arguments args for constructor of element type.
SList(std::initializer_list< E > init)
Constructs a singly linked list containing the elements in init.
bool operator!=(const SListIteratorBase< E, isConst > &it) const
Inequality operator.
SListElement< E > * m_head
Pointer to first element.
E value_type
Represents the data type stored in a list element.
SListIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
SListPure< E > & operator=(SListPure< E > &&L)
Assignment operator (move semantics).
SListIterator< E > search(const E &e)
Scans the list for the specified element and returns an iterator to the first occurrence in the list...
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
The parameterized class Array implements dynamic arrays of type E.
void delSucc(iterator itBefore)
Removes the succesor of itBefore.
bool valid() const
Returns true iff the iterator points to an element.
Contains the class UmlDiagramGraph which represents one particular diagram of the complete UML Model...
void moveFrontToSucc(SListPure< E > &L2, iterator itBefore)
Moves the first element of this list to list L2 inserted after itBefore.
void quicksortTemplate(LIST &L)
const_reference back() const
Returns a reference to the last element.
bool empty() const
Returns true iff the list is empty.
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
virtual ~SListPure()
Destructor.
int size() const
Returns the number of elements in the list.
INDEX high() const
Returns the maximal array index.
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
List::chooseElement.
SListElement(SListPure< E > *list, const E &x)
Constructs an SListElement.
const_iterator cyclicSucc(const_iterator it) const
Returns an iterator to the cyclic successor of it.
const_iterator begin() const
Returns a const iterator to the first element of the list.
const_iterator crbegin() const
Returns a const iterator to the last element of the list.
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.
virtual int size() const
Returns the number of elements in the list.
Encapsulates a pointer to an ogdf::SList element.
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
bool operator==(const SList< E > &L) const
Equality operator.
const_iterator rbegin() const
Returns a const iterator to the last element of the list.
SListIteratorBase< E, isConst > succ() const
Returns successor iterator.
void reverse()
Reverses the order of the list elements.
SListIteratorBase< E, isConst > & operator=(const SListIterator< E > &it)
Assignment operator.
SListIterator< E > insertAfter(const E &x, SListIterator< E > itBefore)
Inserts element x after itBefore.
SListPure()
Constructs an empty singly linked list.
SListElement()
Constructs an SListElement.
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
SListIterator< 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 emplaceBack(Args &&... args)
Adds a new element at the end of the list.
ListElem * m_pX
Pointer to slist element.
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Singly linked lists (maintaining the length of the list).
void moveFrontToFront(SList< E > &L2)
Moves the first element of this list to the begin of list L2.
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
SListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
bool operator==(const SListPure< E > &L) const
Equality operator.
E popFrontRet()
Removes the first element from the list and returns it.
SListElement< E > * m_next
Pointer to successor element.
SListPure(std::initializer_list< E > init)
Constructs a singly linked list containing the elements in init.
Elem & operator*() const
Returns a reference to the element content.
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
void reassignListRefs(SListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
iterator begin()
Returns an iterator to the first element of the list.
const SListPure< E > & getSListPure() const
Conversion to const SListPure.
SList< E > & operator=(const SList< E > &L)
Assignment operator.
iterator pushBack(const E &x)
Adds element x at the end of the list.
bool operator!=(const SListPure< E > &L) const
Inequality operator.
void delSucc(SListIterator< E > itBefore)
Removes the succesor of itBefore.
SList(SList< E > &&L)
Constructs a singly linked list containing the elements of L (move semantics).
static void copy(const T &from, T &to)
SListPure(const SListPure< E > &L)
Constructs a singly linked list that is a copy of L.
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 conc(SListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
int pos(const_iterator it) const
Returns the position (starting with 0) of it in the list.
void popFront()
Removes the first element from the list.
bool operator!=(const SList< E > &L) const
Inequality operator.
void quicksort()
Sorts the list using Quicksort.
E & reference
Provides a reference to an element stored in a list.
SListConstIterator< 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...
void moveFrontToBack(SList< E > &L2)
Moves the first element of this list to the end of list L2.
typename std::conditional< isConst, const ogdf::ExternE, ogdf::ExternE >::type Elem
The underlying type, depending on isConst.
void conc(SList< E > &L2)
Appends L2 to this list and makes L2 empty.
const_reference front() const
Returns a reference to the first element.
iterator insertAfter(const E &x, iterator itBefore)
Inserts element x after itBefore.
void copy(const SListPure< E > &L)
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
const T & move(const T &v)
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
SListConstIterator< E > search(const E &e) const
Scans the list for the specified element and returns an iterator to the first occurrence in the list...
Implementation of algorithms as templates working with different list types.
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations...
SListIterator< E > pushFront(const E &x)
Adds element x at the beginning of the list.
reference front()
Returns a reference to the first element.
iterator begin()
Returns an iterator to the first element.
E popFrontRet()
Removes the first element from the list and returns it.
Abstract base class for bucket functions.
void moveFrontToBack(SListPure< E > &L2)
Moves the first element of this list to the end of list L2.
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...
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
int m_count
The length of the list.
SListElement(SListPure< E > *list, const E &x, SListElement< E > *next)
Constructs an SListElement.
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
SList(const SList< E > &L)
Constructs a singly linked list that is a copy of L.
SList()
Constructs an empty singly linked list.
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
reference back()
Returns a reference to the last element.
virtual int getBucket(const E &x)=0
Returns the bucket of x.
void clear()
Removes all elements from the list.
The namespace for all OGDF objects.
Structure for elements of singly linked lists.
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
List::chooseElement.
SListElement< E > * m_tail
Pointer to last element.
void clear()
Removes all elements from the list.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
iterator rbegin()
Returns an iterator to the last element of the list.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
void moveFrontToFront(SListPure< E > &L2)
Moves the first element of this list to the begin of list L2.
SListIteratorBase(const SListIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
void print(ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
INDEX low() const
Returns the minimal array index.
void moveFrontToSucc(SList< E > &L2, SListIterator< E > itBefore)
Moves the first element of this list to list L2 inserted after itBefore.
SListIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
SListPure(SListPure< E > &&L)
Constructs a singly linked list containing the elements of L (move semantics).
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
void popFront()
Removes the first element from the list.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
iterator end()
Returns an iterator to one-past-last element of the list.
SListIteratorBase()
Constructs an invalid iterator.
void permute()
Randomly permutes the elements in the list.