58 : m_next(next), m_x(x) {
68 template<
class ... Args>
97 operator ListElem *() {
return m_pX; }
115 bool valid()
const {
return m_pX !=
nullptr; }
128 return m_pX == it.
m_pX;
133 return m_pX != it.
m_pX;
195 SListPure(std::initializer_list<E>
init) : m_head(nullptr), m_tail(nullptr) {
196 for (
const E &x : init)
209 L.m_head = L.m_tail =
nullptr;
222 bool empty()
const {
return m_head ==
nullptr; }
278 for(pX = m_head; pX !=
nullptr; pX = pX->
m_next)
279 if (pos-- == 0)
break;
289 for(pX = m_head; pX !=
nullptr; pX = pX->
m_next)
290 if (pos-- == 0)
break;
369 return (pX->m_next) ? pX->m_next : m_head;
379 return (pX->m_next) ? pX->m_next : m_head;
403 L.m_head = L.m_tail =
nullptr;
411 while(pX !=
nullptr && pY !=
nullptr) {
412 if(pX->
m_x != pY->m_x)
417 return pX ==
nullptr && pY ==
nullptr;
435 if (m_tail ==
nullptr) m_tail = m_head;
443 template<
class ... Args>
445 m_head =
new SListElement<E>(
this, m_head, std::forward<Args>(args)...);
446 if (m_tail ==
nullptr) m_tail = m_head;
453 if (m_head ==
nullptr)
454 m_head = m_tail = pNew;
456 m_tail = m_tail->
m_next = pNew;
464 template<
class ... Args>
467 if (m_head ==
nullptr)
468 m_head = m_tail = pNew;
470 m_tail = m_tail->
m_next = pNew;
482 if (pBefore == m_tail) m_tail = pNew;
483 return (pBefore->m_next = pNew);
500 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
524 if ((pBefore->m_next = pDel->
m_next) ==
nullptr) m_tail = pBefore;
530 if (m_head ==
nullptr)
return;
532 if (!std::is_trivially_destructible<E>::value) {
538 m_head = m_tail =
nullptr;
554 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
568 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
589 if ((m_head = m_head->
m_next) ==
nullptr) m_tail =
nullptr;
590 pX->
m_next = pBefore->m_next;
591 pBefore->m_next = pX;
605 reassignListRefs(L2.
m_head);
613 for(p = m_head; p; p = pNext) {
618 std::swap(m_head,m_tail);
631 for (i = begin(); i.
valid(); ++i)
632 if (*i == e)
return i;
639 for (i = begin(); i.
valid(); ++i)
640 if (*i == e)
return i;
645 template<
class COMPARER>
648 for (i = begin(); i.
valid(); ++i)
649 if (comp.equal(*i, e))
return i;
654 template<
class COMPARER>
657 for (i = begin(); i.
valid(); ++i)
658 if (comp.equal(*i, e))
return i;
668 template<
class COMPARER>
695 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
696 bool isFastTest =
true)
const {
702 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
703 bool isFastTest =
true) {
709 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
710 bool isFastTest =
true)
const {
711 const_iterator result = chooseIterator(includeElement, isFastTest);
718 std::function<
bool(
const E&)> includeElement = [](
const E&) {
return true; },
719 bool isFastTest =
true) {
720 iterator result = chooseIterator(includeElement, isFastTest);
728 permute(size(), rng);
734 permute(size(), rng);
747 void permute(
const int n, RNG &rng);
752 for(
auto e = start ==
nullptr ? m_head : start; e !=
nullptr; e = e->
m_next) {
811 int size()
const {
return m_count; }
865 template<
class ... Args>
878 template<
class ... Args>
980 if (m_head == m_tail)
return;
1000 if (m_head == m_tail)
return;
1005 for (pX = m_head; pX; pX = pX->
m_next) {
1008 tail[i] = (tail[i]->m_next = pX);
1010 head[i] = tail[i] = pX;
1014 for (
int i = l; i <= h; i++) {
1042 for (pX = m_head; pX; pX = pX->
m_next)
1047 for (i = 0; i < n; i++) {
1048 A[i]->m_next = A[i+1];
1062 for(++pX; pX.valid(); ++pX)
1076 std::ostream &operator<<(std::ostream &os, const SListPure<E> &L)
1084 std::ostream &operator<<(std::ostream &os, const SList<E> &L)
1094 if (a.
low() >= a.
high())
return;
1099 for(i = a.
low(); i <= a.
high(); ++i)
1100 bucket[f.
getBucket(a[i])].pushBack(a[i]);
1103 for(
int j = min; j <= max; ++j) {
1105 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.
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)
Returns a random element.
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.
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.
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.
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.
SListIteratorBase(const SListIterator< E > &it)
Copy constructor.
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)
iterator backIterator()
Returns an iterator to the last element of the list.
#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
Returns a random element.
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
SListElement< E > * m_tail
Pointer to last element.
void clear()
Removes all elements from the list.
const_iterator backIterator() const
Returns a const iterator to the last element of the list.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning 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.
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.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
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.