Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SList.h
Go to the documentation of this file.
1
32#pragma once
33
35
36namespace ogdf {
37
38template<class E>
39class SListPure;
40template<class E, bool isConst>
41class SListIteratorBase;
42template<class E>
44template<class E>
46
48template<class E>
50 friend class SListPure<E>;
51 friend class SListIteratorBase<E, true>;
52 friend class SListIteratorBase<E, false>;
53
55 E m_x;
56#ifdef OGDF_DEBUG
58#endif
59
61 SListElement(SListPure<E>* list, const E& x, SListElement<E>* next) : m_next(next), m_x(x) {
62#ifdef OGDF_DEBUG
63 m_list = list;
64#endif
65 }
66
68 SListElement(SListPure<E>* list, const E& x) : SListElement(list, x, nullptr) { }
69
72
74 template<class... Args>
76 : SListElement(list, E(std::forward<Args>(args)...), next) { }
77
79};
80
82
91template<class E, bool isConst>
93 friend class SListIteratorBase<E, !isConst>;
94 friend class SListPure<E>;
95
97 using ListElem = typename std::conditional<isConst, const SListElement<E>, SListElement<E>>::type;
99 using Elem = typename std::conditional<isConst, const E, E>::type;
100
102
104 operator ListElem*() { return m_pX; }
105
106public:
109
112
116
118 // gcc9 complains since it cannot match the templated constructor above (-Werror=deprecated-copy).
120
122 bool valid() const { return m_pX != nullptr; }
123
124#ifdef OGDF_DEBUG
129 return m_pX->m_list;
130 }
131#endif
132
134 bool operator==(const SListIteratorBase<E, isConst>& it) const { return m_pX == it.m_pX; }
135
137 bool operator!=(const SListIteratorBase<E, isConst>& it) const { return m_pX != it.m_pX; }
138
140 SListIteratorBase<E, isConst> succ() const { return m_pX->m_next; }
141
143 Elem& operator*() const { return m_pX->m_x; }
144
147 m_pX = it.m_pX;
148 return *this;
149 }
150
153 m_pX = m_pX->m_next;
154 return *this;
155 }
156
160 m_pX = m_pX->m_next;
161 return it;
162 }
163
165};
166
168
178template<class E>
182
183public:
185 using value_type = E;
187 using reference = E&;
189 using const_reference = const E&;
194
197
199 SListPure(std::initializer_list<E> init) : m_head(nullptr), m_tail(nullptr) {
200 for (const E& x : init) {
201 pushBack(x);
202 }
203 }
204
207
209
213 L.m_head = L.m_tail = nullptr;
214 }
215
217 virtual ~SListPure() { clear(); }
218
224
226 bool empty() const { return m_head == nullptr; }
227
229
233 virtual int size() const {
234 int count = 0;
235 for (SListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next) {
236 ++count;
237 }
238 return count;
239 }
240
242
246 OGDF_ASSERT(m_head != nullptr);
247 return m_head->m_x;
248 }
249
251
255 OGDF_ASSERT(m_head != nullptr);
256 return m_head->m_x;
257 }
258
260
264 OGDF_ASSERT(m_tail != nullptr);
265 return m_tail->m_x;
266 }
267
269
273 OGDF_ASSERT(m_tail != nullptr);
274 return m_tail->m_x;
275 }
276
278
281 const_iterator get(int pos) const {
283 for (pX = m_head; pX != nullptr; pX = pX->m_next) {
284 if (pos-- == 0) {
285 break;
286 }
287 }
288 return pX;
289 }
290
292
297 for (pX = m_head; pX != nullptr; pX = pX->m_next) {
298 if (pos-- == 0) {
299 break;
300 }
301 }
302 return pX;
303 }
304
306
310 int pos(const_iterator it) const {
311 OGDF_ASSERT(it.listOf() == this);
312 int p = 0;
313 for (SListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next, ++p) {
314 if (pX == it) {
315 break;
316 }
317 }
318 return p;
319 }
320
322
327
329
332 iterator begin() { return m_head; }
333
335
338 const_iterator begin() const { return m_head; }
339
341
344 const_iterator cbegin() const { return m_head; }
345
347
351
353
357
359
363
365
369
371
375
377
381 OGDF_ASSERT(it.listOf() == this);
382 const SListElement<E>* pX = it;
383 return (pX->m_next) ? pX->m_next : m_head;
384 }
385
387
391 OGDF_ASSERT(it.listOf() == this);
392 SListElement<E>* pX = it;
393 return (pX->m_next) ? pX->m_next : m_head;
394 }
395
397
402
405 clear();
406 copy(L);
407 return *this;
408 }
409
411
415 clear();
416 m_head = L.m_head;
417 m_tail = L.m_tail;
418 L.m_head = L.m_tail = nullptr;
420 return *this;
421 }
422
424 bool operator==(const SListPure<E>& L) const {
425 SListElement<E>*pX = m_head, *pY = L.m_head;
426 while (pX != nullptr && pY != nullptr) {
427 if (pX->m_x != pY->m_x) {
428 return false;
429 }
430 pX = pX->m_next;
431 pY = pY->m_next;
432 }
433 return pX == nullptr && pY == nullptr;
434 }
435
437 bool operator!=(const SListPure<E>& L) const { return !operator==(L); }
438
440
445
447 iterator pushFront(const E& x) {
448 m_head = new SListElement<E>(this, x, m_head);
449 if (m_tail == nullptr) {
450 m_tail = m_head;
451 }
452 return m_head;
453 }
454
456
459 template<class... Args>
461 m_head = new SListElement<E>(this, m_head, std::forward<Args>(args)...);
462 if (m_tail == nullptr) {
463 m_tail = m_head;
464 }
465 return m_head;
466 }
467
469 iterator pushBack(const E& x) {
470 SListElement<E>* pNew = new SListElement<E>(this, x);
471 if (m_head == nullptr) {
472 m_head = m_tail = pNew;
473 } else {
474 m_tail = m_tail->m_next = pNew;
475 }
476 return m_tail;
477 }
478
480
483 template<class... Args>
485 SListElement<E>* pNew = new SListElement<E>(this, nullptr, std::forward<Args>(args)...);
486 if (m_head == nullptr) {
487 m_head = m_tail = pNew;
488 } else {
489 m_tail = m_tail->m_next = pNew;
490 }
491 return m_tail;
492 }
493
495
499 OGDF_ASSERT(itBefore.listOf() == this);
501 SListElement<E>* pNew = new SListElement<E>(this, x, pBefore->m_next);
502 if (pBefore == m_tail) {
503 m_tail = pNew;
504 }
505 return (pBefore->m_next = pNew);
506 }
507
509
514
516
519 void popFront() {
520 OGDF_ASSERT(m_head != nullptr);
522 if ((m_head = m_head->m_next) == nullptr) {
523 m_tail = nullptr;
524 }
525 delete pX;
526 }
527
529
533 E el = front();
534 popFront();
535 return el;
536 }
537
539
543 OGDF_ASSERT(itBefore.listOf() == this);
545 OGDF_ASSERT(pBefore != nullptr);
547 OGDF_ASSERT(pDel != nullptr);
548 if ((pBefore->m_next = pDel->m_next) == nullptr) {
549 m_tail = pBefore;
550 }
551 delete pDel;
552 }
553
555 void clear() {
556 if (m_head == nullptr) {
557 return;
558 }
559
560 if (!std::is_trivially_destructible<E>::value) {
561 for (SListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next) {
562 pX->m_x.~E();
563 }
564 }
565 OGDF_ALLOCATOR::deallocateList(sizeof(SListElement<E>), m_head, m_tail);
566
567 m_head = m_tail = nullptr;
568 }
569
571
576
579 OGDF_ASSERT(m_head != nullptr);
580 OGDF_ASSERT(this != &L2);
581
583 if ((m_head = m_head->m_next) == nullptr) {
584 m_tail = nullptr;
585 }
586 pX->m_next = L2.m_head;
587 L2.m_head = pX;
588 if (L2.m_tail == nullptr) {
589 L2.m_tail = L2.m_head;
590 }
591
592 L2.m_head->m_list = &L2;
593 }
594
597 OGDF_ASSERT(m_head != nullptr);
598 OGDF_ASSERT(this != &L2);
599
601 if ((m_head = m_head->m_next) == nullptr) {
602 m_tail = nullptr;
603 }
604 pX->m_next = nullptr;
605 if (L2.m_head == nullptr) {
606 L2.m_head = L2.m_tail = pX;
607 } else {
608 L2.m_tail = L2.m_tail->m_next = pX;
609 }
610
611 L2.m_tail->m_list = &L2;
612 }
613
615
619 OGDF_ASSERT(m_head != nullptr);
620 OGDF_ASSERT(this != &L2);
621 OGDF_ASSERT(itBefore.listOf() == &L2);
622
625 if ((m_head = m_head->m_next) == nullptr) {
626 m_tail = nullptr;
627 }
628 pX->m_next = pBefore->m_next;
629 pBefore->m_next = pX;
630 if (pBefore == L2.m_tail) {
631 L2.m_tail = pX;
632 }
633
634 pX->m_list = &L2;
635 }
636
639 if (m_head) {
640 m_tail->m_next = L2.m_head;
641 } else {
642 m_head = L2.m_head;
643 }
644 if (L2.m_tail != nullptr) {
645 m_tail = L2.m_tail;
646 }
647
648 reassignListRefs(L2.m_head);
649
650 L2.m_head = L2.m_tail = nullptr;
651 }
652
654 void reverse() {
655 SListElement<E>*p, *pNext, *pPred = nullptr;
656 for (p = m_head; p; p = pNext) {
657 pNext = p->m_next;
658 p->m_next = pPred;
659 pPred = p;
660 }
661 std::swap(m_head, m_tail);
662 }
663
665
670
673 SListConstIterator<E> search(const E& e) const {
675 for (i = begin(); i.valid(); ++i) {
676 if (*i == e) {
677 return i;
678 }
679 }
680 return i;
681 }
682
687 for (i = begin(); i.valid(); ++i) {
688 if (*i == e) {
689 return i;
690 }
691 }
692 return i;
693 }
694
698 template<class COMPARER>
699 SListConstIterator<E> search(const E& e, const COMPARER& comp) const {
701 for (i = begin(); i.valid(); ++i) {
702 if (comp.equal(*i, e)) {
703 return i;
704 }
705 }
706 return i;
707 }
708
712 template<class COMPARER>
713 SListIterator<E> search(const E& e, const COMPARER& comp) {
715 for (i = begin(); i.valid(); ++i) {
716 if (comp.equal(*i, e)) {
717 return i;
718 }
719 }
720 return i;
721 }
722
725
727 template<class COMPARER>
728 void quicksort(const COMPARER& comp) {
730 }
731
733
740 void bucketSort(int l, int h, BucketFunc<E>& f);
741
744
746
751
754 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
755 bool isFastTest = true) const {
757 }
758
761 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
762 bool isFastTest = true) {
764 }
765
768 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
769 bool isFastTest = true) const {
771 OGDF_ASSERT(result.valid());
772 return *result;
773 }
774
777 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
778 bool isFastTest = true) {
780 OGDF_ASSERT(result.valid());
781 return *result;
782 }
783
785 void permute() {
786 std::minstd_rand rng(randomSeed());
787 permute(size(), rng);
788 }
789
791 template<class RNG>
792 void permute(RNG& rng) {
793 permute(size(), rng);
794 }
795
797
798protected:
799 void copy(const SListPure<E>& L) {
800 for (SListElement<E>* pX = L.m_head; pX != nullptr; pX = pX->m_next) {
801 pushBack(pX->m_x);
802 }
803 }
804
806 template<class RNG>
807 void permute(const int n, RNG& rng);
808
810 inline void reassignListRefs(SListElement<E>* start = nullptr) {
811#ifdef OGDF_DEBUG
812 for (auto e = start == nullptr ? m_head : start; e != nullptr; e = e->m_next) {
813 e->m_list = this;
814 }
815#endif
816 }
817
819};
820
822
832template<class E>
833class SList : private SListPure<E> {
835
836public:
842
844 SList() : m_count(0) { }
845
847 SList(std::initializer_list<E> init) : SListPure<E>(init), m_count((int)init.size()) { }
848
851
853
856 SList(SList<E>&& L) : SListPure<E>(std::move(L)), m_count(L.m_count) { L.m_count = 0; }
857
863
865
868 int size() const { return m_count; }
869
871 const SListPure<E>& getSListPure() const { return *this; }
872
874
879
883 m_count = L.m_count;
884 return *this;
885 }
886
888
892 m_count = L.m_count;
893 SListPure<E>::operator=(std::move(L));
894 L.m_count = 0;
895 return *this;
896 }
897
899 bool operator==(const SList<E>& L) const {
900 return (m_count == L.m_count) && SListPure<E>::operator==(L);
901 }
902
904 bool operator!=(const SList<E>& L) const { return !operator==(L); }
905
907
912
915 ++m_count;
916 return SListPure<E>::pushFront(x);
917 }
918
920 template<class... Args>
922 ++m_count;
923 return SListPure<E>::emplaceFront(std::forward<Args>(args)...);
924 }
925
928 ++m_count;
929 return SListPure<E>::pushBack(x);
930 }
931
933 template<class... Args>
935 ++m_count;
936 return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
937 }
938
944
946
951
953 void popFront() {
954 --m_count;
956 }
957
960 E el = front();
961 popFront();
962 return el;
963 }
964
970
972 void clear() {
973 m_count = 0;
975 }
976
978
983
987 --m_count;
988 ++L2.m_count;
989 }
990
994 --m_count;
995 ++L2.m_count;
996 }
997
1004
1008 m_count += L2.m_count;
1009 L2.m_count = 0;
1010 }
1011
1012 using SListPure<E>::empty;
1013 using SListPure<E>::front;
1014 using SListPure<E>::back;
1015 using SListPure<E>::get;
1016 using SListPure<E>::pos;
1017 using SListPure<E>::begin;
1018 using SListPure<E>::cbegin;
1019 using SListPure<E>::end;
1020 using SListPure<E>::cend;
1021 using SListPure<E>::backIterator;
1022 using SListPure<E>::cyclicSucc;
1023 using SListPure<E>::reverse;
1024 using SListPure<E>::search;
1025 using SListPure<E>::quicksort;
1026 using SListPure<E>::bucketSort;
1028 using SListPure<E>::chooseElement;
1029 using SListPure<E>::permute;
1030
1032};
1033
1034template<class E>
1036 // if less than two elements, nothing to do
1037 if (m_head == m_tail) {
1038 return;
1039 }
1040
1041 int l, h;
1042 l = h = f.getBucket(m_head->m_x);
1043
1045 for (pX = m_head->m_next; pX; pX = pX->m_next) {
1046 int i = f.getBucket(pX->m_x);
1047 if (i < l) {
1048 l = i;
1049 }
1050 if (i > h) {
1051 h = i;
1052 }
1053 }
1054
1055 bucketSort(l, h, f);
1056}
1057
1058template<class E>
1060 // if less than two elements, nothing to do
1061 if (m_head == m_tail) {
1062 return;
1063 }
1064
1065 Array<SListElement<E>*> head(l, h, nullptr), tail(l, h);
1066
1068 for (pX = m_head; pX; pX = pX->m_next) {
1069 int i = f.getBucket(pX->m_x);
1070 if (head[i]) {
1071 tail[i] = (tail[i]->m_next = pX);
1072 } else {
1073 head[i] = tail[i] = pX;
1074 }
1075 }
1076
1077 SListElement<E>* pY = nullptr;
1078 for (int i = l; i <= h; i++) {
1079 pX = head[i];
1080 if (pX) {
1081 if (pY) {
1082 pY->m_next = pX;
1083 } else {
1084 m_head = pX;
1085 }
1086 pY = tail[i];
1087 }
1088 }
1089
1090 m_tail = pY;
1091 pY->m_next = nullptr;
1092}
1093
1094template<class E>
1095template<class RNG>
1096void SListPure<E>::permute(const int n, RNG& rng) {
1097 if (n == 0) {
1098 return;
1099 }
1100
1101 Array<SListElement<E>*> A(n + 1);
1102 A[n] = nullptr;
1103
1104 int i = 0;
1106 for (pX = m_head; pX; pX = pX->m_next) {
1107 A[i++] = pX;
1108 }
1109
1110 A.permute(0, n - 1, rng);
1111
1112 for (i = 0; i < n; i++) {
1113 A[i]->m_next = A[i + 1];
1114 }
1115
1116 m_head = A[0];
1117 m_tail = A[n - 1];
1118}
1119
1121template<class E>
1122void print(std::ostream& os, const SListPure<E>& L, char delim = ' ') {
1123 SListConstIterator<E> pX = L.begin();
1124 if (pX.valid()) {
1125 os << *pX;
1126 for (++pX; pX.valid(); ++pX) {
1127 os << delim << *pX;
1128 }
1129 }
1130}
1131
1133template<class E>
1134void print(std::ostream& os, const SList<E>& L, char delim = ' ') {
1135 print(os, L.getSListPure(), delim);
1136}
1137
1139template<class E>
1140std::ostream& operator<<(std::ostream& os, const SListPure<E>& L) {
1141 print(os, L);
1142 return os;
1143}
1144
1146template<class E>
1147std::ostream& operator<<(std::ostream& os, const SList<E>& L) {
1148 return operator<<(os, L.getSListPure());
1149}
1150
1153template<class E>
1154void bucketSort(Array<E>& a, int min, int max, BucketFunc<E>& f) {
1155 if (a.low() >= a.high()) {
1156 return;
1157 }
1158
1159 Array<SListPure<E>> bucket(min, max);
1160
1161 int i;
1162 for (i = a.low(); i <= a.high(); ++i) {
1163 bucket[f.getBucket(a[i])].pushBack(a[i]);
1164 }
1165
1166 i = a.low();
1167 for (int j = min; j <= max; ++j) {
1168 SListConstIterator<E> it = bucket[j].begin();
1169 for (; it.valid(); ++it) {
1170 a[i++] = *it;
1171 }
1172 }
1173}
1174
1175}
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
iterator begin()
Returns an iterator to the first element.
Definition Array.h:324
INDEX high() const
Returns the maximal array index.
Definition Array.h:294
INDEX low() const
Returns the minimal array index.
Definition Array.h:291
Abstract base class for bucket functions.
Definition basic.h:241
Structure for elements of singly linked lists.
Definition SList.h:49
SListElement(SListPure< E > *list, SListElement< E > *next, Args &&... args)
Constructs an SListElement with given arguments args for constructor of element type.
Definition SList.h:75
E m_x
Stores the content.
Definition SList.h:55
SListElement(SListPure< E > *list, const E &x)
Constructs an SListElement.
Definition SList.h:68
SListElement()
Constructs an SListElement.
Definition SList.h:71
SListElement< E > * m_next
Pointer to successor element.
Definition SList.h:54
SListElement(SListPure< E > *list, const E &x, SListElement< E > *next)
Constructs an SListElement.
Definition SList.h:61
Singly linked lists (maintaining the length of the list).
Definition SList.h:833
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition SList.h:934
void moveFrontToSucc(SList< E > &L2, SListIterator< E > itBefore)
Moves the first element of this list to list L2 inserted after itBefore.
Definition SList.h:999
bool operator!=(const SList< E > &L) const
Inequality operator.
Definition SList.h:904
void clear()
Removes all elements from the list.
Definition SList.h:972
void moveFrontToFront(SList< E > &L2)
Moves the first element of this list to the begin of list L2.
Definition SList.h:985
int size() const
Returns the number of elements in the list.
Definition SList.h:868
SListIterator< E > insertAfter(const E &x, SListIterator< E > itBefore)
Inserts element x after itBefore.
Definition SList.h:940
SList(std::initializer_list< E > init)
Constructs a singly linked list containing the elements in init.
Definition SList.h:847
void conc(SList< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition SList.h:1006
void popFront()
Removes the first element from the list.
Definition SList.h:953
bool operator==(const SList< E > &L) const
Equality operator.
Definition SList.h:899
SList(SList< E > &&L)
Constructs a singly linked list containing the elements of L (move semantics).
Definition SList.h:856
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition SList.h:881
void moveFrontToBack(SList< E > &L2)
Moves the first element of this list to the end of list L2.
Definition SList.h:992
SList< E > & operator=(SList< E > &&L)
Assignment operator (move semantics).
Definition SList.h:891
SList(const SList< E > &L)
Constructs a singly linked list that is a copy of L.
Definition SList.h:850
void delSucc(SListIterator< E > itBefore)
Removes the succesor of itBefore.
Definition SList.h:966
E popFrontRet()
Removes the first element from the list and returns it.
Definition SList.h:959
SListIterator< E > pushFront(const E &x)
Adds element x at the beginning of the list.
Definition SList.h:914
const SListPure< E > & getSListPure() const
Conversion to const SListPure.
Definition SList.h:871
int m_count
The length of the list.
Definition SList.h:834
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition SList.h:921
SList()
Constructs an empty singly linked list.
Definition SList.h:844
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:927
Encapsulates a pointer to an ogdf::SList element.
Definition SList.h:92
SListIteratorBase()
Constructs an invalid iterator.
Definition SList.h:111
typename std::conditional< isConst, const SListElement< E >, SListElement< E > >::type ListElem
The underlying list element, depending on isConst.
Definition SList.h:97
SListIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
Definition SList.h:158
SListIteratorBase< E, isConst > & operator=(const SListIterator< E > &it)
Assignment operator.
Definition SList.h:146
bool operator==(const SListIteratorBase< E, isConst > &it) const
Equality operator.
Definition SList.h:134
SListIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
Definition SList.h:152
SListIteratorBase(const SListIterator< E > &it)
Copy constructor.
Definition SList.h:119
bool valid() const
Returns true iff the iterator points to an element.
Definition SList.h:122
Elem & operator*() const
Returns a reference to the element content.
Definition SList.h:143
typename std::conditional< isConst, const E, E >::type Elem
The underlying type, depending on isConst.
Definition SList.h:99
ListElem * m_pX
Pointer to slist element.
Definition SList.h:101
SListIteratorBase(const SListIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
Definition SList.h:115
SListIteratorBase< E, isConst > succ() const
Returns successor iterator.
Definition SList.h:140
SListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
Definition SList.h:108
bool operator!=(const SListIteratorBase< E, isConst > &it) const
Inequality operator.
Definition SList.h:137
Singly linked lists.
Definition SList.h:179
void bucketSort(BucketFunc< E > &f)
Sorts the list using bucket sort.
Definition SList.h:1035
bool operator==(const SListPure< E > &L) const
Equality operator.
Definition SList.h:424
const_iterator backIterator() const
Returns a const iterator to the last element of the list.
Definition SList.h:374
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
Definition SList.h:760
iterator backIterator()
Returns an iterator to the last element of the list.
Definition SList.h:368
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations.
Definition SList.h:189
SListPure(const SListPure< E > &L)
Constructs a singly linked list that is a copy of L.
Definition SList.h:206
void reassignListRefs(SListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
Definition SList.h:810
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
Definition SList.h:728
void clear()
Removes all elements from the list.
Definition SList.h:555
SListPure()
Constructs an empty singly linked list.
Definition SList.h:196
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,...
Definition SList.h:673
SListIterator< E > iterator
Provides a forward iterator that can read or modify any element in a list.
Definition SList.h:193
SListPure< E > & operator=(SListPure< E > &&L)
Assignment operator (move semantics).
Definition SList.h:414
const_iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns an iterator to a random element.
Definition SList.h:753
SListConstIterator< E > const_iterator
Provides a forward iterator that can read a const element in a list.
Definition SList.h:191
SListElement< E > * m_tail
Pointer to last element.
Definition SList.h:181
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition SList.h:460
reference front()
Returns a reference to the first element.
Definition SList.h:254
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...
Definition SList.h:713
void moveFrontToSucc(SListPure< E > &L2, iterator itBefore)
Moves the first element of this list to list L2 inserted after itBefore.
Definition SList.h:618
iterator end()
Returns an iterator to one-past-last element of the list.
Definition SList.h:350
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
Definition SList.h:792
E & reference
Provides a reference to an element stored in a list.
Definition SList.h:187
void reverse()
Reverses the order of the list elements.
Definition SList.h:654
iterator insertAfter(const E &x, iterator itBefore)
Inserts element x after itBefore.
Definition SList.h:498
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
Definition SList.h:1059
const_iterator cyclicSucc(const_iterator it) const
Returns an iterator to the cyclic successor of it.
Definition SList.h:380
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition SList.h:344
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
Definition SList.h:356
SListElement< E > * m_head
Pointer to first element.
Definition SList.h:180
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
Definition SList.h:390
int pos(const_iterator it) const
Returns the position (starting with 0) of it in the list.
Definition SList.h:310
void quicksort()
Sorts the list using Quicksort.
Definition SList.h:724
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...
Definition SList.h:699
SListPure(SListPure< E > &&L)
Constructs a singly linked list containing the elements of L (move semantics).
Definition SList.h:212
const_iterator get(int pos) const
Returns an iterator pointing to the element at position pos.
Definition SList.h:281
reference back()
Returns a reference to the last element.
Definition SList.h:272
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition SList.h:362
SListIterator< E > search(const E &e)
Scans the list for the specified element and returns an iterator to the first occurrence in the list,...
Definition SList.h:685
bool empty() const
Returns true iff the list is empty.
Definition SList.h:226
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition SList.h:484
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
Definition SList.h:776
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition SList.h:404
const_reference front() const
Returns a reference to the first element.
Definition SList.h:245
E popFrontRet()
Removes the first element from the list and returns it.
Definition SList.h:532
virtual int size() const
Returns the number of elements in the list.
Definition SList.h:233
void permute()
Randomly permutes the elements in the list.
Definition SList.h:785
void moveFrontToBack(SListPure< E > &L2)
Moves the first element of this list to the end of list L2.
Definition SList.h:596
virtual ~SListPure()
Destructor.
Definition SList.h:217
E value_type
Represents the data type stored in a list element.
Definition SList.h:185
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition SList.h:447
const_reference back() const
Returns a reference to the last element.
Definition SList.h:263
void copy(const SListPure< E > &L)
Definition SList.h:799
bool operator!=(const SListPure< E > &L) const
Inequality operator.
Definition SList.h:437
iterator begin()
Returns an iterator to the first element of the list.
Definition SList.h:332
SListPure(std::initializer_list< E > init)
Constructs a singly linked list containing the elements in init.
Definition SList.h:199
iterator get(int pos)
Returns an iterator pointing to the element at position pos.
Definition SList.h:295
void moveFrontToFront(SListPure< E > &L2)
Moves the first element of this list to the begin of list L2.
Definition SList.h:578
const_iterator begin() const
Returns a const iterator to the first element of the list.
Definition SList.h:338
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:469
void delSucc(iterator itBefore)
Removes the succesor of itBefore.
Definition SList.h:542
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
Definition SList.h:767
void permute(const int n, RNG &rng)
Permutes elements in list randomly; n is the length of the list.
Definition SList.h:1096
void popFront()
Removes the first element from the list.
Definition SList.h:519
void conc(SListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition SList.h:638
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
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.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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.
Definition Array.h:978
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 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,...
Definition SList.h:1154
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.
Definition Array.h:967
Definition GML.h:110