Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
List.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Reverse.h>
36
37#include <random>
38
39namespace ogdf {
40
41template<class E>
42class List;
43template<class E>
44class ListPure;
45template<class E, bool isConst, bool isReverse>
46class ListIteratorBase;
47template<class E>
49template<class E>
51template<class E>
53template<class E>
55
57template<class E>
59 friend class ListPure<E>;
60 friend class List<E>;
61 friend class ListIteratorBase<E, true, true>;
62 friend class ListIteratorBase<E, false, true>;
63 friend class ListIteratorBase<E, true, false>;
64 friend class ListIteratorBase<E, false, false>;
65
68 E m_x;
69#ifdef OGDF_DEBUG
71#endif
72
74 ListElement(ListPure<E>* list, const E& x, ListElement<E>* next, ListElement<E>* prev)
75 : m_next(next), m_prev(prev), m_x(x) {
76#ifdef OGDF_DEBUG
77 m_list = list;
78#endif
79 }
80
82 ListElement(ListPure<E>* list, const E& x) : ListElement(list, x, nullptr, nullptr) { }
83
85 template<class... Args>
87 : ListElement(list, E(std::forward<Args>(args)...), next, prev) { }
88
90};
91
93
102template<class E, bool isConst, bool isReverse>
104 friend class ListIteratorBase<E, !isConst, isReverse>;
105 friend class ListIteratorBase<E, isConst, !isReverse>;
106 friend class ListIteratorBase<E, !isConst, !isReverse>;
107 friend class ListPure<E>;
109 using ListElem = typename std::conditional<isConst, const ListElement<E>, ListElement<E>>::type;
111 using Elem = typename std::conditional<isConst, const E, E>::type;
112
115
117 operator ListElem*() { return m_pX; }
118
119public:
122
125
130
132 // gcc9 complains since it cannot match the templated constructor above (-Werror=deprecated-copy).
135
137 bool valid() const { return m_pX != nullptr; }
138
139#ifdef OGDF_DEBUG
144 return m_pX->m_list;
145 }
146#endif
149 return m_pX == it.m_pX;
150 }
151
154 return m_pX != it.m_pX;
155 }
156
159 return isReverse ? m_pX->m_prev : m_pX->m_next;
160 }
161
164 return isReverse ? m_pX->m_next : m_pX->m_prev;
165 }
166
168 Elem& operator*() const { return m_pX->m_x; }
169
176
179 m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
180 return *this;
181 }
182
186 m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
187 return it;
188 }
189
192 m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
193 return *this;
194 }
195
199 m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
200 return it;
201 }
202
204};
205
207
216template<class E>
217class ListPure {
218protected:
221
222public:
224 using value_type = E;
226 using reference = E&;
228 using const_reference = const E&;
237
240
242 ListPure(std::initializer_list<E> init) : m_head(nullptr), m_tail(nullptr) {
243 for (const E& x : init) {
244 pushBack(x);
245 }
246 }
247
250
252
257 L.m_head = L.m_tail = nullptr;
258 }
259
261 virtual ~ListPure() { clear(); }
262
268
270 bool empty() const { return m_head == nullptr; }
271
273
277 virtual int size() const {
278 int count = 0;
279 for (ListElement<E>* pX = m_head; pX; pX = pX->m_next) {
280 ++count;
281 }
282 return count;
283 }
284
286
290 OGDF_ASSERT(m_head != nullptr);
291 return m_head->m_x;
292 }
293
295
299 OGDF_ASSERT(m_head != nullptr);
300 return m_head->m_x;
301 }
302
304
308 OGDF_ASSERT(m_tail != nullptr);
309 return m_tail->m_x;
310 }
311
313
317 OGDF_ASSERT(m_tail != nullptr);
318 return m_tail->m_x;
319 }
320
322
325 const_iterator get(int pos) const {
327 for (pX = m_head; pX != nullptr; pX = pX->m_next) {
328 if (pos-- == 0) {
329 break;
330 }
331 }
332 return pX;
333 }
334
336
341 for (pX = m_head; pX != nullptr; pX = pX->m_next) {
342 if (pos-- == 0) {
343 break;
344 }
345 }
346 return pX;
347 }
348
350
353 int pos(const_iterator it) const {
354 OGDF_ASSERT(it.listOf() == this);
355 int p = 0;
356 for (ListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next, ++p) {
357 if (pX == (const ListElement<E>*)it) {
358 break;
359 }
360 }
361 return p;
362 }
363
365
370
372
375 iterator begin() { return m_head; }
376
378
381 const_iterator begin() const { return m_head; }
382
384
387 const_iterator cbegin() const { return m_head; }
388
390
393 iterator end() { return iterator(); }
394
396
399 const_iterator end() const { return const_iterator(); }
400
402
405 const_iterator cend() const { return const_iterator(); }
406
408
412
414
418
420
424
426
430
432
436
438
442
444
448 OGDF_ASSERT(!it.valid() || it.listOf() == this);
449 const ListElement<E>* pX = it;
450 return (pX && pX->m_next) ? pX->m_next : m_head;
451 }
452
454
458 OGDF_ASSERT(!it.valid() || it.listOf() == this);
459 ListElement<E>* pX = it;
460 return (pX && pX->m_next) ? pX->m_next : m_head;
461 }
462
467 OGDF_ASSERT(!it.valid() || it.listOf() == this);
468 const ListElement<E>* pX = it;
469 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
470 }
471
476 OGDF_ASSERT(!it.valid() || it.listOf() == this);
477 ListElement<E>* pX = it;
478 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
479 }
480
482
486 OGDF_ASSERT(!it.valid() || it.listOf() == this);
487 const ListElement<E>* pX = it;
488 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
489 }
490
492
496 OGDF_ASSERT(!it.valid() || it.listOf() == this);
497 ListElement<E>* pX = it;
498 return (pX && pX->m_prev) ? pX->m_prev : m_tail;
499 }
500
505 OGDF_ASSERT(!it.valid() || it.listOf() == this);
506 const ListElement<E>* pX = it;
507 return (pX && pX->m_next) ? pX->m_next : m_head;
508 }
509
514 OGDF_ASSERT(!it.valid() || it.listOf() == this);
515 ListElement<E>* pX = it;
516 return (pX && pX->m_next) ? pX->m_next : m_head;
517 }
518
520
525
528 clear();
529 copy(L);
530 return *this;
531 }
532
534
538 clear();
539 m_head = L.m_head;
540 m_tail = L.m_tail;
541 L.m_head = L.m_tail = nullptr;
543 return *this;
544 }
545
547 bool operator==(const ListPure<E>& L) const {
548 ListElement<E>*pX = m_head, *pY = L.m_head;
549 while (pX != nullptr && pY != nullptr) {
550 if (pX->m_x != pY->m_x) {
551 return false;
552 }
553 pX = pX->m_next;
554 pY = pY->m_next;
555 }
556 return pX == nullptr && pY == nullptr;
557 }
558
560 bool operator!=(const ListPure<E>& L) const { return !operator==(L); }
561
563
568
570 iterator pushFront(const E& x) {
571 ListElement<E>* pX = new ListElement<E>(this, x, m_head, nullptr);
572 if (m_head) {
573 m_head = m_head->m_prev = pX;
574 } else {
575 m_head = m_tail = pX;
576 }
577 return m_head;
578 }
579
581
584 template<class... Args>
586 ListElement<E>* pX = new ListElement<E>(this, m_head, nullptr, std::forward<Args>(args)...);
587 if (m_head) {
588 m_head = m_head->m_prev = pX;
589 } else {
590 m_head = m_tail = pX;
591 }
592 return m_head;
593 }
594
596 iterator pushBack(const E& x) {
597 ListElement<E>* pX = new ListElement<E>(this, x, nullptr, m_tail);
598 if (m_head) {
599 m_tail = m_tail->m_next = pX;
600 } else {
601 m_tail = m_head = pX;
602 }
603 return m_tail;
604 }
605
607
610 template<class... Args>
612 ListElement<E>* pX = new ListElement<E>(this, nullptr, m_tail, std::forward<Args>(args)...);
613 if (m_head) {
614 m_tail = m_tail->m_next = pX;
615 } else {
616 m_tail = m_head = pX;
617 }
618 return m_tail;
619 }
620
622
630 OGDF_ASSERT(it.listOf() == this);
631 ListElement<E>*pY = it, *pX;
632 if (dir == Direction::after) {
634 pY->m_next = pX = new ListElement<E>(this, x, pYnext, pY);
635 if (pYnext) {
636 pYnext->m_prev = pX;
637 } else {
638 m_tail = pX;
639 }
640 } else {
642 pY->m_prev = pX = new ListElement<E>(this, x, pY, pYprev);
643 if (pYprev) {
644 pYprev->m_next = pX;
645 } else {
646 m_head = pX;
647 }
648 }
649 return pX;
650 }
651
653
657 OGDF_ASSERT(it.listOf() == this);
658 ListElement<E>*pY = it, *pX;
660 pY->m_prev = pX = new ListElement<E>(this, x, pY, pYprev);
661 if (pYprev) {
662 pYprev->m_next = pX;
663 } else {
664 m_head = pX;
665 }
666 return pX;
667 }
668
670
673 iterator insertAfter(const E& x, iterator it) {
674 OGDF_ASSERT(it.listOf() == this);
675 ListElement<E>*pY = it, *pX;
677 pY->m_next = pX = new ListElement<E>(this, x, pYnext, pY);
678 if (pYnext) {
679 pYnext->m_prev = pX;
680 } else {
681 m_tail = pX;
682 }
683 return pX;
684 }
685
687
692
694
697 void popFront() {
698 OGDF_ASSERT(m_head != nullptr);
701 delete pX;
702 if (m_head) {
703 m_head->m_prev = nullptr;
704 } else {
705 m_tail = nullptr;
706 }
707 }
708
710
714 E el = front();
715 popFront();
716 return el;
717 }
718
720
723 void popBack() {
724 OGDF_ASSERT(m_tail != nullptr);
727 delete pX;
728 if (m_tail) {
729 m_tail->m_next = nullptr;
730 } else {
731 m_head = nullptr;
732 }
733 }
734
736
740 E el = back();
741 popBack();
742 return el;
743 }
744
746
749 void del(iterator it) {
750 OGDF_ASSERT(it.listOf() == this);
751 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
752 delete pX;
753 if (pPrev) {
754 pPrev->m_next = pNext;
755 } else {
756 m_head = pNext;
757 }
758 if (pNext) {
759 pNext->m_prev = pPrev;
760 } else {
761 m_tail = pPrev;
762 }
763 }
764
766
772 bool removeFirst(const E& x) {
773 for (ListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next) {
774 if (pX->m_x == x) {
775 del(pX);
776 return true;
777 }
778 }
779 return false;
780 }
781
783 void clear() {
784 if (m_head == nullptr) {
785 return;
786 }
787
788 if (!std::is_trivially_destructible<E>::value) {
789 for (ListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next) {
790 pX->m_x.~E();
791 }
792 }
793 OGDF_ALLOCATOR::deallocateList(sizeof(ListElement<E>), m_head, m_tail);
794
795 m_head = m_tail = nullptr;
796 }
797
799
804
806
810 OGDF_ASSERT(it1.valid());
811 OGDF_ASSERT(it2.valid());
812 OGDF_ASSERT(it1 != it2);
813 ListElement<E>*pX = it1, *pY = it2;
814
815 std::swap(pX->m_next, pY->m_next);
816 std::swap(pX->m_prev, pY->m_prev);
817#ifdef OGDF_DEBUG
818 std::swap(pX->m_list, pY->m_list);
819#endif
820
821 if (pX->m_next == pX) {
822 pX->m_next = pY;
823 pY->m_prev = pX;
824 }
825 if (pX->m_prev == pX) {
826 pX->m_prev = pY;
827 pY->m_next = pX;
828 }
829
830 if (pX->m_prev) {
831 pX->m_prev->m_next = pX;
832 } else {
833 m_head = pX;
834 }
835
836 if (pY->m_prev) {
837 pY->m_prev->m_next = pY;
838 } else {
839 m_head = pY;
840 }
841
842 if (pX->m_next) {
843 pX->m_next->m_prev = pX;
844 } else {
845 m_tail = pX;
846 }
847
848 if (pY->m_next) {
849 pY->m_next->m_prev = pY;
850 } else {
851 m_tail = pY;
852 }
853 }
854
856
860 OGDF_ASSERT(it.listOf() == this);
861 // remove it
862 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
863 //already at front
864 if (!pPrev) {
865 return;
866 }
867
868 //update old position
869 if (pPrev) {
870 pPrev->m_next = pNext;
871 }
872 if (pNext) {
873 pNext->m_prev = pPrev;
874 } else {
875 m_tail = pPrev;
876 }
877 // insert it at front
878 pX->m_prev = nullptr;
879 pX->m_next = m_head;
880 m_head = m_head->m_prev = pX;
881 }
882
884
888 OGDF_ASSERT(it.listOf() == this);
889 // remove it
890 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
891 //already at back
892 if (!pNext) {
893 return;
894 }
895
896 //update old position
897 if (pPrev) {
898 pPrev->m_next = pNext;
899 } else {
900 m_head = pNext;
901 }
902 if (pNext) {
903 pNext->m_prev = pPrev;
904 }
905 // insert it at back
906 pX->m_prev = m_tail;
907 pX->m_next = nullptr;
908 m_tail = m_tail->m_next = pX;
909 }
910
912
916 OGDF_ASSERT(it.listOf() == this);
917 OGDF_ASSERT(itBefore.listOf() == this);
918 // move it
919 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
920 //the same of already in place
922 if (pX == pY || pPrev == pY) {
923 return;
924 }
925
926 // update old position
927 if (pPrev) {
928 pPrev->m_next = pNext;
929 } else {
930 m_head = pNext;
931 }
932 if (pNext) {
933 pNext->m_prev = pPrev;
934 } else {
935 m_tail = pPrev;
936 }
937 // move it after itBefore
938 ListElement<E>* pYnext = pX->m_next = pY->m_next;
939 (pX->m_prev = pY)->m_next = pX;
940 if (pYnext) {
941 pYnext->m_prev = pX;
942 } else {
943 m_tail = pX;
944 }
945 }
946
948
952 OGDF_ASSERT(it.listOf() == this);
953 OGDF_ASSERT(itAfter.listOf() == this);
954 // move it
955 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
956 //the same of already in place
958 if (pX == pY || pNext == pY) {
959 return;
960 }
961
962 // update old position
963 if (pPrev) {
964 pPrev->m_next = pNext;
965 } else {
966 m_head = pNext;
967 }
968 if (pNext) {
969 pNext->m_prev = pPrev;
970 } else {
971 m_tail = pPrev;
972 }
973 // move it before itAfter
974 ListElement<E>* pYprev = pX->m_prev = pY->m_prev;
975 (pX->m_next = pY)->m_prev = pX;
976 if (pYprev) {
977 pYprev->m_next = pX;
978 } else {
979 m_head = pX;
980 }
981 }
982
984
988 OGDF_ASSERT(it.listOf() == this);
989 OGDF_ASSERT(this != &L2);
990 // remove it
991 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
992 if (pPrev) {
993 pPrev->m_next = pNext;
994 } else {
995 m_head = pNext;
996 }
997 if (pNext) {
998 pNext->m_prev = pPrev;
999 } else {
1000 m_tail = pPrev;
1001 }
1002 // insert it at front of L2
1003 pX->m_prev = nullptr;
1004 if ((pX->m_next = L2.m_head) != nullptr) {
1005 L2.m_head = L2.m_head->m_prev = pX;
1006 } else {
1007 L2.m_head = L2.m_tail = pX;
1008 }
1009
1010#ifdef OGDF_DEBUG
1011 pX->m_list = &L2;
1012#endif
1013 }
1014
1016
1020 OGDF_ASSERT(it.listOf() == this);
1021 OGDF_ASSERT(this != &L2);
1022 // remove it
1023 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
1024 if (pPrev) {
1025 pPrev->m_next = pNext;
1026 } else {
1027 m_head = pNext;
1028 }
1029 if (pNext) {
1030 pNext->m_prev = pPrev;
1031 } else {
1032 m_tail = pPrev;
1033 }
1034 // insert it at back of L2
1035 pX->m_next = nullptr;
1036 if ((pX->m_prev = L2.m_tail) != nullptr) {
1037 L2.m_tail = L2.m_tail->m_next = pX;
1038 } else {
1039 L2.m_head = L2.m_tail = pX;
1040 }
1041
1042#ifdef OGDF_DEBUG
1043 pX->m_list = this;
1044#endif
1045 }
1046
1048
1053 OGDF_ASSERT(it.listOf() == this);
1054 OGDF_ASSERT(itBefore.listOf() == &L2);
1055 OGDF_ASSERT(this != &L2);
1056 // remove it
1057 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
1058 if (pPrev) {
1059 pPrev->m_next = pNext;
1060 } else {
1061 m_head = pNext;
1062 }
1063 if (pNext) {
1064 pNext->m_prev = pPrev;
1065 } else {
1066 m_tail = pPrev;
1067 }
1068 // insert it in list L2 after itBefore
1070 ListElement<E>* pYnext = pX->m_next = pY->m_next;
1071 (pX->m_prev = pY)->m_next = pX;
1072 if (pYnext) {
1073 pYnext->m_prev = pX;
1074 } else {
1075 L2.m_tail = pX;
1076 }
1077
1078#ifdef OGDF_DEBUG
1079 pX->m_list = &L2;
1080#endif
1081 }
1082
1084
1089 OGDF_ASSERT(it.listOf() == this);
1090 OGDF_ASSERT(itAfter.listOf() == &L2);
1091 OGDF_ASSERT(this != &L2);
1092 // remove it
1093 ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
1094 if (pPrev) {
1095 pPrev->m_next = pNext;
1096 } else {
1097 m_head = pNext;
1098 }
1099 if (pNext) {
1100 pNext->m_prev = pPrev;
1101 } else {
1102 m_tail = pPrev;
1103 }
1104 // insert it in list L2 after itBefore
1106 ListElement<E>* pYprev = pX->m_prev = pY->m_prev;
1107 (pX->m_next = pY)->m_prev = pX;
1108 if (pYprev) {
1109 pYprev->m_next = pX;
1110 } else {
1111 L2.m_head = pX;
1112 }
1113
1114#ifdef OGDF_DEBUG
1115 pX->m_list = &L2;
1116#endif
1117 }
1118
1121 OGDF_ASSERT(this != &L2);
1122 if (m_head) {
1123 m_tail->m_next = L2.m_head;
1124 } else {
1125 m_head = L2.m_head;
1126 }
1127 if (L2.m_head) {
1128 L2.m_head->m_prev = m_tail;
1129 m_tail = L2.m_tail;
1130 }
1131
1132 reassignListRefs(L2.m_head);
1133
1134 L2.m_head = L2.m_tail = nullptr;
1135 }
1136
1139 OGDF_ASSERT(this != &L2);
1140 if (m_head) {
1141 m_head->m_prev = L2.m_tail;
1142 } else {
1143 m_tail = L2.m_tail;
1144 }
1145 if (L2.m_head) {
1146 L2.m_tail->m_next = m_head;
1147 m_head = L2.m_head;
1148 }
1149
1150 reassignListRefs(L2.m_head);
1151
1152 L2.m_head = L2.m_tail = nullptr;
1153 }
1154
1157 std::swap(m_head, other.m_head);
1158 std::swap(m_tail, other.m_tail);
1159
1161 other.reassignListRefs();
1162 }
1163
1165
1175 OGDF_ASSERT(!it.valid() || it.listOf() == this);
1176 if (&L1 != this) {
1177 L1.clear();
1178 }
1179 if (&L2 != this) {
1180 L2.clear();
1181 }
1182
1183 if (it.valid()) {
1184 L1.m_head = m_head;
1185 L2.m_tail = m_tail;
1186 if (dir == Direction::before) {
1187 L2.m_head = it;
1188 L1.m_tail = L2.m_head->m_prev;
1189 } else {
1190 L1.m_tail = it;
1191 L2.m_head = L1.m_tail->m_next;
1192 }
1193 L2.m_head->m_prev = L1.m_tail->m_next = nullptr;
1194
1195 } else {
1196 L1.m_head = L1.m_tail = nullptr;
1197 L2.m_head = m_head;
1198 L2.m_tail = m_tail;
1199 }
1200
1201 if (this != &L1 && this != &L2) {
1202 m_head = m_tail = nullptr;
1203 }
1204
1205 L1.reassignListRefs();
1206 L2.reassignListRefs();
1207 }
1208
1211 OGDF_ASSERT(it.listOf() == this);
1212 OGDF_ASSERT(this != &L2);
1213 L2.clear();
1214 ListElement<E>* pX = it;
1215 if (pX != m_tail) {
1216 (L2.m_head = pX->m_next)->m_prev = nullptr;
1217 pX->m_next = nullptr;
1218 L2.m_tail = m_tail;
1219 m_tail = pX;
1220 }
1221
1222 L2.reassignListRefs();
1223 }
1224
1227 OGDF_ASSERT(it.listOf() == this);
1228 OGDF_ASSERT(this != &L2);
1229 L2.clear();
1230 ListElement<E>* pX = it;
1231 L2.m_head = pX;
1232 L2.m_tail = m_tail;
1233 if ((m_tail = pX->m_prev) == nullptr) {
1234 m_head = nullptr;
1235 } else {
1236 m_tail->m_next = nullptr;
1237 }
1238 pX->m_prev = nullptr;
1239
1240 L2.reassignListRefs();
1241 }
1242
1244 void reverse() {
1246 m_head = m_tail;
1247 m_tail = pX;
1248 while (pX) {
1250 pX->m_next = pX->m_prev;
1251 pX = pX->m_prev = pY;
1252 }
1253 }
1254
1256
1261
1264 ListConstIterator<E> search(const E& e) const {
1266 for (i = begin(); i.valid(); ++i) {
1267 if (*i == e) {
1268 return i;
1269 }
1270 }
1271 return i;
1272 }
1273
1278 for (i = begin(); i.valid(); ++i) {
1279 if (*i == e) {
1280 return i;
1281 }
1282 }
1283 return i;
1284 }
1285
1289 template<class COMPARER>
1290 ListConstIterator<E> search(const E& e, const COMPARER& comp) const {
1292 for (i = begin(); i.valid(); ++i) {
1293 if (comp.equal(*i, e)) {
1294 return i;
1295 }
1296 }
1297 return i;
1298 }
1299
1303 template<class COMPARER>
1304 ListIterator<E> search(const E& e, const COMPARER& comp) {
1306 for (i = begin(); i.valid(); ++i) {
1307 if (comp.equal(*i, e)) {
1308 return i;
1309 }
1310 }
1311 return i;
1312 }
1313
1316
1318 template<class COMPARER>
1319 void quicksort(const COMPARER& comp) {
1321 }
1322
1324
1331 void bucketSort(int l, int h, BucketFunc<E>& f);
1332
1334
1339
1349 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1350 bool isFastTest = true) const {
1352 }
1353
1356 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1357 bool isFastTest = true) {
1359 }
1360
1370 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1371 bool isFastTest = true) const {
1373 OGDF_ASSERT(result.valid());
1374 return *result;
1375 }
1376
1379 std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1380 bool isFastTest = true) {
1382 OGDF_ASSERT(result.valid());
1383 return *result;
1384 }
1385
1387 void permute() {
1388 std::minstd_rand rng(randomSeed());
1389 permute(size(), rng);
1390 }
1391
1393 template<class RNG>
1394 void permute(RNG& rng) {
1395 permute(size(), rng);
1396 }
1397
1399
1400protected:
1401 void copy(const ListPure<E>& L) {
1402 for (ListElement<E>* pX = L.m_head; pX != nullptr; pX = pX->m_next) {
1403 pushBack(pX->m_x);
1404 }
1405 }
1406
1407 template<class RNG>
1408
1410 void permute(const int n, RNG& rng);
1411
1413 inline void reassignListRefs(ListElement<E>* start = nullptr) {
1414#ifdef OGDF_DEBUG
1415 for (auto e = start == nullptr ? m_head : start; e != nullptr; e = e->m_next) {
1416 e->m_list = this;
1417 }
1418#endif
1419 }
1420
1422};
1423
1425
1434template<class E>
1435class List : private ListPure<E> {
1437
1438public:
1446
1448 List() : m_count(0) { }
1449
1451 List(std::initializer_list<E> init) : ListPure<E>(init), m_count((int)init.size()) { }
1452
1454 List(const List<E>& L) : ListPure<E>(L), m_count(L.m_count) { }
1455
1457
1460 List(List<E>&& L) : ListPure<E>(std::move(L)), m_count(L.m_count) { L.m_count = 0; }
1461
1467
1469
1472 int size() const { return m_count; }
1473
1475 const ListPure<E>& getListPure() const { return *this; }
1476
1478
1483
1487 m_count = L.m_count;
1488 return *this;
1489 }
1490
1492
1496 m_count = L.m_count;
1497 ListPure<E>::operator=(std::move(L));
1498 L.m_count = 0;
1499 return *this;
1500 }
1501
1503 bool operator==(const List<E>& L) const {
1504 return (m_count == L.m_count) && ListPure<E>::operator==(L);
1505 }
1506
1508 bool operator!=(const List<E>& L) const { return !operator==(L); }
1509
1511
1516
1518 iterator pushFront(const E& x) {
1519 ++m_count;
1520 return ListPure<E>::pushFront(x);
1521 }
1522
1524 template<class... Args>
1526 ++m_count;
1527 return ListPure<E>::emplaceFront(std::forward<Args>(args)...);
1528 }
1529
1531 iterator pushBack(const E& x) {
1532 ++m_count;
1533 return ListPure<E>::pushBack(x);
1534 }
1535
1537 template<class... Args>
1539 ++m_count;
1540 return ListPure<E>::emplaceBack(std::forward<Args>(args)...);
1541 }
1542
1545 ++m_count;
1546 return ListPure<E>::insert(x, it, dir);
1547 }
1548
1551 ++m_count;
1552 return ListPure<E>::insertBefore(x, it);
1553 }
1554
1557 ++m_count;
1558 return ListPure<E>::insertAfter(x, it);
1559 }
1560
1562
1567
1569 void popFront() {
1570 --m_count;
1572 }
1573
1576 E el = front();
1577 popFront();
1578 return el;
1579 }
1580
1582 void popBack() {
1583 --m_count;
1585 }
1586
1589 E el = back();
1590 popBack();
1591 return el;
1592 }
1593
1595 void del(iterator it) {
1596 --m_count;
1597 ListPure<E>::del(it);
1598 }
1599
1601 bool removeFirst(const E& x) {
1603 if (hasRemoved) {
1604 --m_count;
1605 }
1606 return hasRemoved;
1607 }
1608
1610 void clear() {
1611 m_count = 0;
1613 }
1614
1616
1621
1625 --m_count;
1626 ++L2.m_count;
1627 }
1628
1632 --m_count;
1633 ++L2.m_count;
1634 }
1635
1639 --m_count;
1640 ++L2.m_count;
1641 }
1642
1646 --m_count;
1647 ++L2.m_count;
1648 }
1649
1651 void conc(List<E>& L2) {
1653 m_count += L2.m_count;
1654 L2.m_count = 0;
1655 }
1656
1660 m_count += L2.m_count;
1661 L2.m_count = 0;
1662 }
1663
1667 std::swap(m_count, other.m_count);
1668 }
1669
1672 ListPure<E>::split(it, L1, L2, dir);
1673 int countL = m_count, countL1 = 0;
1674 for (ListElement<E>* pX = L1.m_head; pX != nullptr; pX = pX->m_next) {
1675 ++countL1;
1676 }
1677
1678 L1.m_count = countL1;
1679 L2.m_count = countL - countL1;
1680 if (this->m_head == nullptr) {
1681 m_count = 0;
1682 }
1683 }
1684
1685 using ListPure<E>::empty;
1686 using ListPure<E>::front;
1687 using ListPure<E>::back;
1688 using ListPure<E>::get;
1689 using ListPure<E>::pos;
1690 using ListPure<E>::begin;
1691 using ListPure<E>::cbegin;
1692 using ListPure<E>::end;
1693 using ListPure<E>::cend;
1694 using ListPure<E>::rbegin;
1695 using ListPure<E>::crbegin;
1696 using ListPure<E>::rend;
1697 using ListPure<E>::crend;
1698 using ListPure<E>::cyclicSucc;
1699 using ListPure<E>::cyclicPred;
1700 using ListPure<E>::exchange;
1701 using ListPure<E>::moveToFront;
1702 using ListPure<E>::moveToBack;
1703 using ListPure<E>::moveToSucc;
1704 using ListPure<E>::moveToPrec;
1705 using ListPure<E>::reverse;
1706 using ListPure<E>::search;
1707 using ListPure<E>::quicksort;
1708 using ListPure<E>::bucketSort;
1709 using ListPure<E>::chooseIterator;
1710 using ListPure<E>::chooseElement;
1711 using ListPure<E>::permute;
1712
1714};
1715
1716template<class E>
1718 if (m_head == m_tail) {
1719 return;
1720 }
1721
1722 Array<ListElement<E>*> head(l, h, nullptr), tail(l, h);
1723
1725 for (pX = m_head; pX; pX = pX->m_next) {
1726 int i = f.getBucket(pX->m_x);
1727 if (head[i]) {
1728 tail[i] = ((pX->m_prev = tail[i])->m_next = pX);
1729 } else {
1730 head[i] = tail[i] = pX;
1731 }
1732 }
1733
1734 ListElement<E>* pY = nullptr;
1735 for (int i = l; i <= h; i++) {
1736 pX = head[i];
1737 if (pX) {
1738 if (pY) {
1739 (pY->m_next = pX)->m_prev = pY;
1740 } else {
1741 (m_head = pX)->m_prev = nullptr;
1742 }
1743 pY = tail[i];
1744 }
1745 }
1746
1747 m_tail = pY;
1748 pY->m_next = nullptr;
1749}
1750
1751template<class E>
1752template<class RNG>
1753void ListPure<E>::permute(const int n, RNG& rng) {
1754 //if n==0 do nothing
1755 if (n == 0) {
1756 return;
1757 }
1758
1759 Array<ListElement<E>*> A(n + 2);
1760 A[0] = A[n + 1] = nullptr;
1761
1762 int i = 1;
1764 for (pX = m_head; pX; pX = pX->m_next) {
1765 A[i++] = pX;
1766 }
1767
1768 A.permute(1, n, rng);
1769
1770 for (i = 1; i <= n; i++) {
1771 pX = A[i];
1772 pX->m_next = A[i + 1];
1773 pX->m_prev = A[i - 1];
1774 }
1775
1776 m_head = A[1];
1777 m_tail = A[n];
1778}
1779
1781template<class E>
1782void print(std::ostream& os, const ListPure<E>& L, char delim = ' ') {
1783 typename ListPure<E>::const_iterator pX = L.begin();
1784 if (pX.valid()) {
1785 os << *pX;
1786 for (++pX; pX.valid(); ++pX) {
1787 os << delim << *pX;
1788 }
1789 }
1790}
1791
1793template<class E>
1794void print(std::ostream& os, const List<E>& L, char delim = ' ') {
1795 print(os, L.getListPure(), delim);
1796}
1797
1799template<class E>
1800std::ostream& operator<<(std::ostream& os, const ListPure<E>& L) {
1801 print(os, L);
1802 return os;
1803}
1804
1806template<class E>
1807std::ostream& operator<<(std::ostream& os, const List<E>& L) {
1808 return os << L.getListPure();
1809}
1810
1811template<class E, class Master>
1812class ListContainer : public List<E> {
1813 friend Master;
1814
1815public:
1820
1822 iterator begin() const { return List<E>::cbegin(); }
1823
1825 iterator end() const { return List<E>::cend(); }
1826
1829
1832
1834 int size() const { return List<E>::size(); }
1835};
1836
1837}
Implementation of the Reverse class for the reverse iteration of containers.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Abstract base class for bucket functions.
Definition basic.h:241
iterator begin() const
Returns an iterator to the first element in the container.
Definition List.h:1822
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
Definition List.h:1828
typename List< E >::const_reverse_iterator reverse_iterator
Provides a bidirectional reverse iterator to an object in the container.
Definition List.h:1819
iterator end() const
Returns an iterator to the one-past-last element in the container.
Definition List.h:1825
reverse_iterator rend() const
Returns a reverse iterator to the one-before-first element in the container.
Definition List.h:1831
int size() const
Returns the number of elements in the container.
Definition List.h:1834
typename List< E >::const_iterator iterator
Provides a bidirectional iterator to an object in the container.
Definition List.h:1817
Structure for elements of doubly linked lists.
Definition List.h:58
ListElement(ListPure< E > *list, const E &x)
Constructs a ListElement.
Definition List.h:82
ListElement(ListPure< E > *list, const E &x, ListElement< E > *next, ListElement< E > *prev)
Constructs a ListElement.
Definition List.h:74
E m_x
Stores the content.
Definition List.h:68
ListElement< E > * m_next
Pointer to successor element.
Definition List.h:66
ListElement< E > * m_prev
Pointer to predecessor element.
Definition List.h:67
ListElement(ListPure< E > *list, ListElement< E > *next, ListElement< E > *prev, Args &&... args)
Constructs a ListElement with given arguments args for constructor of element type.
Definition List.h:86
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
void popFront()
Removes the first element from the list.
Definition List.h:1569
List(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
Definition List.h:1451
List(const List< E > &L)
Constructs a doubly linked list that is a copy of L.
Definition List.h:1454
int size() const
Returns the number of elements in the list.
Definition List.h:1472
const ListPure< E > & getListPure() const
Conversion to const ListPure.
Definition List.h:1475
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition List.h:1538
List()
Constructs an empty doubly linked list.
Definition List.h:1448
void clear()
Removes all elements from the list.
Definition List.h:1610
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1531
void moveToFront(iterator it, List< E > &L2)
Moves it to the begin of the list.
Definition List.h:1623
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition List.h:1601
void del(iterator it)
Removes it from the list.
Definition List.h:1595
void moveToPrec(iterator it, List< E > &L2, iterator itAfter)
Moves it before itAfter.
Definition List.h:1644
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition List.h:1550
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.
Definition List.h:1671
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition List.h:1485
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition List.h:1525
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Definition List.h:1544
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition List.h:1518
int m_count
The length of the list.
Definition List.h:1436
List(List< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
Definition List.h:1460
E popBackRet()
Removes the last element from the list and returns it.
Definition List.h:1588
void swap(List< E > &other)
Exchanges the contents of this list and other in constant time.
Definition List.h:1665
bool operator==(const List< E > &L) const
Equality operator.
Definition List.h:1503
void moveToBack(iterator it, List< E > &L2)
Moves it to the end of the list.
Definition List.h:1630
List< E > & operator=(List< E > &&L)
Assignment operator (move semantics).
Definition List.h:1495
bool operator!=(const List< E > &L) const
Inequality operator.
Definition List.h:1508
void moveToSucc(iterator it, List< E > &L2, iterator itBefore)
Moves it after itBefore.
Definition List.h:1637
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition List.h:1556
void popBack()
Removes the last element from the list.
Definition List.h:1582
E popFrontRet()
Removes the first element from the list and returns it.
Definition List.h:1575
void concFront(List< E > &L2)
Prepends L2 to this list and makes L2 empty.
Definition List.h:1658
void conc(List< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition List.h:1651
Encapsulates a pointer to a list element.
Definition List.h:103
ListIteratorBase(const ListIteratorBase< E, isConst, isReverse > &it)
Copy constructor.
Definition List.h:133
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
Definition List.h:121
bool operator==(const ListIteratorBase< E, isConst, isReverse > &it) const
Equality operator.
Definition List.h:148
bool operator!=(const ListIteratorBase< E, isConst, isReverse > &it) const
Inequality operator.
Definition List.h:153
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:137
ListIteratorBase< E, isConst, isReverse > operator--(int)
Decrement operator (postfix).
Definition List.h:197
ListIteratorBase()
Constructs an invalid iterator.
Definition List.h:124
ListIteratorBase< E, isConst, isReverse > operator++(int)
Increment operator (postfix).
Definition List.h:184
ListIteratorBase< E, isConst, isReverse > & operator++()
Increment operator (prefix).
Definition List.h:178
typename std::conditional< isConst, const E, E >::type Elem
The underlying type, depending on isConst.
Definition List.h:111
ListElem * m_pX
pointer to list element
Definition List.h:114
ListIteratorBase< E, isConst, isReverse > & operator=(const ListIteratorBase< E, isConst, isReverse > &it)
Assignment operator.
Definition List.h:171
ListIteratorBase< E, isConst, isReverse > & operator--()
Decrement operator (prefix).
Definition List.h:191
typename std::conditional< isConst, const ListElement< E >, ListElement< E > >::type ListElem
The underlying list element, depending on isConst.
Definition List.h:109
ListIteratorBase(const ListIteratorBase< E, isArgConst, isArgReverse > &it)
Constructs an iterator that is a copy of it.
Definition List.h:128
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition List.h:158
Elem & operator*() const
Returns a reference to the element content.
Definition List.h:168
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
Definition List.h:163
Doubly linked lists.
Definition List.h:217
iterator begin()
Returns an iterator to the first element of the list.
Definition List.h:375
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Definition List.h:485
E & reference
Provides a reference to an element stored in a list.
Definition List.h:226
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:596
void moveToFront(iterator it, ListPure< E > &L2)
Moves it to the begin of L2.
Definition List.h:987
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 List.h:1348
ListIterator< E > search(const E &e)
Scans the list for the specified element and returns an iterator to the first occurrence in the list,...
Definition List.h:1276
void splitAfter(iterator it, ListPure< E > &L2)
Splits the list after it.
Definition List.h:1210
ListIterator< E > iterator
Provides a bidirectional iterator that can read or modify any element in a list.
Definition List.h:232
virtual ~ListPure()
Destructor.
Definition List.h:261
const_iterator begin() const
Returns a const iterator to the first element of the list.
Definition List.h:381
void concFront(ListPure< E > &L2)
Prepends L2 to this list and makes L2 empty.
Definition List.h:1138
void reverse()
Reverses the order of the list elements.
Definition List.h:1244
const_iterator cyclicSucc(const_iterator it) const
Returns a const iterator to the cyclic successor of it.
Definition List.h:447
const_reverse_iterator rend() const
Returns a const iterator to one-before-first element of the list.
Definition List.h:435
ListConstIterator< E > const_iterator
Provides a bidirectional iterator that can read a const element in a list.
Definition List.h:230
void moveToBack(iterator it)
Moves it to the end of the list.
Definition List.h:887
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...
Definition List.h:1304
ListPure(const ListPure< E > &L)
Constructs a doubly linked list that is a copy of L.
Definition List.h:249
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
Definition List.h:1319
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
Definition List.h:353
const_reverse_iterator cyclicPred(const_reverse_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Definition List.h:504
ListPure(ListPure< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
Definition List.h:255
const_reference front() const
Returns a const reference to the first element.
Definition List.h:289
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition List.h:772
const_reverse_iterator cyclicSucc(const_reverse_iterator it) const
Returns a const iterator to the cyclic successor of it.
Definition List.h:466
ListPure< E > & operator=(const ListPure< E > &L)
Assignment operator.
Definition List.h:527
const_iterator get(int pos) const
Returns a const iterator pointing to the element at position pos.
Definition List.h:325
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition List.h:387
reverse_iterator cyclicSucc(reverse_iterator it)
Returns a const iterator to the cyclic successor of it.
Definition List.h:475
const_reference back() const
Returns a const reference to the last element.
Definition List.h:307
E value_type
Represents the data type stored in a list element.
Definition List.h:224
reference back()
Returns a reference to the last element.
Definition List.h:316
void permute()
Randomly permutes the elements in the list.
Definition List.h:1387
void moveToBack(iterator it, ListPure< E > &L2)
Moves it to the end of L2.
Definition List.h:1019
void copy(const ListPure< E > &L)
Definition List.h:1401
iterator cyclicPred(iterator it)
Returns an iterator to the cyclic predecessor of it.
Definition List.h:495
iterator get(int pos)
Returns an iterator pointing to the element at position pos.
Definition List.h:339
E popFrontRet()
Removes the first element from the list and returns it.
Definition List.h:713
const_reverse_iterator crbegin() const
Returns a const iterator to the last element of the list.
Definition List.h:423
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
Definition List.h:1369
void exchange(iterator it1, iterator it2)
Exchanges the positions of it1 and it2 in the list.
Definition List.h:809
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
Definition List.h:1355
virtual int size() const
Returns the number of elements in the list.
Definition List.h:277
void clear()
Removes all elements from the list.
Definition List.h:783
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.
Definition List.h:1174
void del(iterator it)
Removes it from the list.
Definition List.h:749
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Definition List.h:629
void moveToPrec(iterator it, iterator itAfter)
Moves it before itAfter.
Definition List.h:951
ListPure< E > & operator=(ListPure< E > &&L)
Assignment operator (move semantics).
Definition List.h:537
ListConstReverseIterator< E > const_reverse_iterator
Provides a bidirectional reverse iterator that can read a const element in a list.
Definition List.h:234
bool operator==(const ListPure< E > &L) const
Equality operator.
Definition List.h:547
void popBack()
Removes the last element from the list.
Definition List.h:723
ListPure()
Constructs an empty doubly linked list.
Definition List.h:239
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
Definition List.h:1394
ListElement< E > * m_tail
Pointer to last element.
Definition List.h:220
ListPure(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
Definition List.h:242
const_reverse_iterator crend() const
Returns a const iterator to one-before-first element of the list.
Definition List.h:441
void reassignListRefs(ListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
Definition List.h:1413
void conc(ListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition List.h:1120
void splitBefore(iterator it, ListPure< E > &L2)
Splits the list before it.
Definition List.h:1226
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition List.h:405
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
Definition List.h:411
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
Definition List.h:1717
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...
Definition List.h:1290
bool operator!=(const ListPure< E > &L) const
Inequality operator.
Definition List.h:560
void moveToFront(iterator it)
Moves it to the begin of the list.
Definition List.h:859
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition List.h:585
void permute(const int n, RNG &rng)
permutes elements in list randomly; n is the length of the list
Definition List.h:1753
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition List.h:611
const_reverse_iterator rbegin() const
Returns a const iterator to the last element of the list.
Definition List.h:417
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition List.h:673
E popBackRet()
Removes the last element from the list and returns it.
Definition List.h:739
void swap(ListPure< E > &other)
Exchanges the contents of this list and other in constant time.
Definition List.h:1156
ListReverseIterator< E > reverse_iterator
Provides a bidirectional reverse iterator that can read or modify any element in a list.
Definition List.h:236
reference front()
Returns a reference to the first element.
Definition List.h:298
bool empty() const
Returns true iff the list is empty.
Definition List.h:270
reverse_iterator cyclicPred(reverse_iterator it)
Returns a const iterator to the cyclic predecessor of it.
Definition List.h:513
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations.
Definition List.h:228
void moveToSucc(iterator it, iterator itBefore)
Moves it after itBefore.
Definition List.h:915
reverse_iterator rend()
Returns an iterator to one-before-first element of the list.
Definition List.h:429
void quicksort()
Sorts the list using Quicksort.
Definition List.h:1315
ListElement< E > * m_head
Pointer to first element.
Definition List.h:219
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
Definition List.h:457
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,...
Definition List.h:1264
iterator end()
Returns an iterator to one-past-last element of the list.
Definition List.h:393
void moveToSucc(iterator it, ListPure< E > &L2, iterator itBefore)
Moves it to list L2 and inserts it after itBefore.
Definition List.h:1052
void moveToPrec(iterator it, ListPure< E > &L2, iterator itAfter)
Moves it to list L2 and inserts it before itAfter.
Definition List.h:1088
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
Definition List.h:1378
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition List.h:570
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition List.h:656
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
Definition List.h:399
void popFront()
Removes the first element from the list.
Definition List.h:697
#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.
Direction
Definition basic.h:134
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