Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
39 namespace ogdf {
40 
41 template<class E>
42 class List;
43 template<class E>
44 class ListPure;
45 template<class E, bool isConst, bool isReverse>
47 template<class E>
49 template<class E>
51 template<class E>
53 template<class E>
55 
57 template<class E>
58 class ListElement {
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>
86  ListElement(ListPure<E>* list, ListElement<E>* next, ListElement<E>* prev, Args&&... args)
87  : ListElement(list, E(std::forward<Args>(args)...), next, prev) { }
88 
90 };
91 
93 
102 template<class E, bool isConst, bool isReverse>
103 class ListIteratorBase {
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;
112 
115 
116 public:
117  using difference_type = std::ptrdiff_t;
118  using value_type = Elem;
119  using iterator_category = std::bidirectional_iterator_tag;
120  using pointer = value_type*;
122 
124  operator ListElem*() { return m_pX; }
125 
128 
131 
135  : ListIteratorBase(it.m_pX) { }
136 
138  // gcc9 complains since it cannot match the templated constructor above (-Werror=deprecated-copy).
140  : ListIteratorBase(it.m_pX) { }
141 
143  bool valid() const { return m_pX != nullptr; }
144 
145 #ifdef OGDF_DEBUG
146  ListPure<E>* listOf() {
149  OGDF_ASSERT(valid());
150  return m_pX->m_list;
151  }
152 #endif
153  bool operator==(const ListIteratorBase<E, isConst, isReverse>& it) const {
155  return m_pX == it.m_pX;
156  }
157 
160  return m_pX != it.m_pX;
161  }
162 
165  return isReverse ? m_pX->m_prev : m_pX->m_next;
166  }
167 
170  return isReverse ? m_pX->m_next : m_pX->m_prev;
171  }
172 
174  Elem& operator*() const { return m_pX->m_x; }
175 
179  m_pX = it.m_pX;
180  return *this;
181  }
182 
185  m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
186  return *this;
187  }
188 
192  m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
193  return it;
194  }
195 
198  m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
199  return *this;
200  }
201 
205  m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
206  return it;
207  }
208 
210 };
211 
213 
222 template<class E>
223 class ListPure {
224 protected:
227 
228 public:
230  using value_type = E;
232  using reference = E&;
234  using const_reference = const E&;
243 
245  ListPure() : m_head(nullptr), m_tail(nullptr) { }
246 
248  ListPure(std::initializer_list<E> init) : m_head(nullptr), m_tail(nullptr) {
249  for (const E& x : init) {
250  pushBack(x);
251  }
252  }
253 
255  ListPure(const ListPure<E>& L) : m_head(nullptr), m_tail(nullptr) { copy(L); }
256 
258 
261  ListPure(ListPure<E>&& L) noexcept : m_head(L.m_head), m_tail(L.m_tail) {
262  L.m_head = L.m_tail = nullptr;
264  }
265 
267  virtual ~ListPure() { clear(); }
268 
273 
276  bool empty() const { return m_head == nullptr; }
277 
279 
283  virtual int size() const {
284  int count = 0;
285  for (ListElement<E>* pX = m_head; pX; pX = pX->m_next) {
286  ++count;
287  }
288  return count;
289  }
290 
292 
296  OGDF_ASSERT(m_head != nullptr);
297  return m_head->m_x;
298  }
299 
301 
305  OGDF_ASSERT(m_head != nullptr);
306  return m_head->m_x;
307  }
308 
310 
314  OGDF_ASSERT(m_tail != nullptr);
315  return m_tail->m_x;
316  }
317 
319 
323  OGDF_ASSERT(m_tail != nullptr);
324  return m_tail->m_x;
325  }
326 
328 
331  const_iterator get(int pos) const {
332  ListElement<E>* pX;
333  for (pX = m_head; pX != nullptr; pX = pX->m_next) {
334  if (pos-- == 0) {
335  break;
336  }
337  }
338  return pX;
339  }
340 
342 
345  iterator get(int pos) {
346  ListElement<E>* pX;
347  for (pX = m_head; pX != nullptr; pX = pX->m_next) {
348  if (pos-- == 0) {
349  break;
350  }
351  }
352  return pX;
353  }
354 
356 
359  int pos(const_iterator it) const {
360  OGDF_ASSERT(it.listOf() == this);
361  int p = 0;
362  for (ListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next, ++p) {
363  if (pX == (const ListElement<E>*)it) {
364  break;
365  }
366  }
367  return p;
368  }
369 
371 
375 
378 
381  iterator begin() { return m_head; }
382 
384 
387  const_iterator begin() const { return m_head; }
388 
390 
393  const_iterator cbegin() const { return m_head; }
394 
396 
399  iterator end() { return iterator(); }
400 
402 
405  const_iterator end() const { return const_iterator(); }
406 
408 
411  const_iterator cend() const { return const_iterator(); }
412 
414 
418 
420 
424 
426 
430 
432 
436 
438 
442 
444 
448 
450 
454  OGDF_ASSERT(!it.valid() || it.listOf() == this);
455  const ListElement<E>* pX = it;
456  return (pX && pX->m_next) ? pX->m_next : m_head;
457  }
458 
460 
464  OGDF_ASSERT(!it.valid() || it.listOf() == this);
465  ListElement<E>* pX = it;
466  return (pX && pX->m_next) ? pX->m_next : m_head;
467  }
468 
473  OGDF_ASSERT(!it.valid() || it.listOf() == this);
474  const ListElement<E>* pX = it;
475  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
476  }
477 
482  OGDF_ASSERT(!it.valid() || it.listOf() == this);
483  ListElement<E>* pX = it;
484  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
485  }
486 
488 
492  OGDF_ASSERT(!it.valid() || it.listOf() == this);
493  const ListElement<E>* pX = it;
494  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
495  }
496 
498 
502  OGDF_ASSERT(!it.valid() || it.listOf() == this);
503  ListElement<E>* pX = it;
504  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
505  }
506 
511  OGDF_ASSERT(!it.valid() || it.listOf() == this);
512  const ListElement<E>* pX = it;
513  return (pX && pX->m_next) ? pX->m_next : m_head;
514  }
515 
520  OGDF_ASSERT(!it.valid() || it.listOf() == this);
521  ListElement<E>* pX = it;
522  return (pX && pX->m_next) ? pX->m_next : m_head;
523  }
524 
526 
530 
534  clear();
535  copy(L);
536  return *this;
537  }
538 
540 
544  clear();
545  m_head = L.m_head;
546  m_tail = L.m_tail;
547  L.m_head = L.m_tail = nullptr;
549  return *this;
550  }
551 
553  bool operator==(const ListPure<E>& L) const {
554  ListElement<E>*pX = m_head, *pY = L.m_head;
555  while (pX != nullptr && pY != nullptr) {
556  if (pX->m_x != pY->m_x) {
557  return false;
558  }
559  pX = pX->m_next;
560  pY = pY->m_next;
561  }
562  return pX == nullptr && pY == nullptr;
563  }
564 
566  bool operator!=(const ListPure<E>& L) const { return !operator==(L); }
567 
569 
573 
576  iterator pushFront(const E& x) {
577  ListElement<E>* pX = new ListElement<E>(this, x, m_head, nullptr);
578  if (m_head) {
579  m_head = m_head->m_prev = pX;
580  } else {
581  m_head = m_tail = pX;
582  }
583  return m_head;
584  }
585 
587 
590  template<class... Args>
591  iterator emplaceFront(Args&&... args) {
592  ListElement<E>* pX = new ListElement<E>(this, m_head, nullptr, std::forward<Args>(args)...);
593  if (m_head) {
594  m_head = m_head->m_prev = pX;
595  } else {
596  m_head = m_tail = pX;
597  }
598  return m_head;
599  }
600 
602  iterator pushBack(const E& x) {
603  ListElement<E>* pX = new ListElement<E>(this, x, nullptr, m_tail);
604  if (m_head) {
605  m_tail = m_tail->m_next = pX;
606  } else {
607  m_tail = m_head = pX;
608  }
609  return m_tail;
610  }
611 
613 
616  template<class... Args>
617  iterator emplaceBack(Args&&... args) {
618  ListElement<E>* pX = new ListElement<E>(this, nullptr, m_tail, std::forward<Args>(args)...);
619  if (m_head) {
620  m_tail = m_tail->m_next = pX;
621  } else {
622  m_tail = m_head = pX;
623  }
624  return m_tail;
625  }
626 
628 
636  OGDF_ASSERT(it.listOf() == this);
637  ListElement<E>*pY = it, *pX;
638  if (dir == Direction::after) {
639  ListElement<E>* pYnext = pY->m_next;
640  pY->m_next = pX = new ListElement<E>(this, x, pYnext, pY);
641  if (pYnext) {
642  pYnext->m_prev = pX;
643  } else {
644  m_tail = pX;
645  }
646  } else {
647  ListElement<E>* pYprev = pY->m_prev;
648  pY->m_prev = pX = new ListElement<E>(this, x, pY, pYprev);
649  if (pYprev) {
650  pYprev->m_next = pX;
651  } else {
652  m_head = pX;
653  }
654  }
655  return pX;
656  }
657 
659 
662  iterator insertBefore(const E& x, iterator it) {
663  OGDF_ASSERT(it.listOf() == this);
664  ListElement<E>*pY = it, *pX;
665  ListElement<E>* pYprev = pY->m_prev;
666  pY->m_prev = pX = new ListElement<E>(this, x, pY, pYprev);
667  if (pYprev) {
668  pYprev->m_next = pX;
669  } else {
670  m_head = pX;
671  }
672  return pX;
673  }
674 
676 
679  iterator insertAfter(const E& x, iterator it) {
680  OGDF_ASSERT(it.listOf() == this);
681  ListElement<E>*pY = it, *pX;
682  ListElement<E>* pYnext = pY->m_next;
683  pY->m_next = pX = new ListElement<E>(this, x, pYnext, pY);
684  if (pYnext) {
685  pYnext->m_prev = pX;
686  } else {
687  m_tail = pX;
688  }
689  return pX;
690  }
691 
693 
697 
700 
703  void popFront() {
704  OGDF_ASSERT(m_head != nullptr);
705  ListElement<E>* pX = m_head;
706  m_head = m_head->m_next;
707  delete pX;
708  if (m_head) {
709  m_head->m_prev = nullptr;
710  } else {
711  m_tail = nullptr;
712  }
713  }
714 
716 
720  E el = front();
721  popFront();
722  return el;
723  }
724 
726 
729  void popBack() {
730  OGDF_ASSERT(m_tail != nullptr);
731  ListElement<E>* pX = m_tail;
732  m_tail = m_tail->m_prev;
733  delete pX;
734  if (m_tail) {
735  m_tail->m_next = nullptr;
736  } else {
737  m_head = nullptr;
738  }
739  }
740 
742 
746  E el = back();
747  popBack();
748  return el;
749  }
750 
752 
755  void del(iterator it) {
756  OGDF_ASSERT(it.listOf() == this);
757  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
758  delete pX;
759  if (pPrev) {
760  pPrev->m_next = pNext;
761  } else {
762  m_head = pNext;
763  }
764  if (pNext) {
765  pNext->m_prev = pPrev;
766  } else {
767  m_tail = pPrev;
768  }
769  }
770 
772 
778  bool removeFirst(const E& x) {
779  for (ListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next) {
780  if (pX->m_x == x) {
781  del(pX);
782  return true;
783  }
784  }
785  return false;
786  }
787 
789  void clear() {
790  if (m_head == nullptr) {
791  return;
792  }
793 
794  if (!std::is_trivially_destructible<E>::value) {
795  for (ListElement<E>* pX = m_head; pX != nullptr; pX = pX->m_next) {
796  pX->m_x.~E();
797  }
798  }
799  OGDF_ALLOCATOR::deallocateList(sizeof(ListElement<E>), m_head, m_tail);
800 
801  m_head = m_tail = nullptr;
802  }
803 
805 
809 
812 
815  void exchange(iterator it1, iterator it2) {
816  OGDF_ASSERT(it1.valid());
817  OGDF_ASSERT(it2.valid());
818  OGDF_ASSERT(it1 != it2);
819  ListElement<E>*pX = it1, *pY = it2;
820 
821  std::swap(pX->m_next, pY->m_next);
822  std::swap(pX->m_prev, pY->m_prev);
823 #ifdef OGDF_DEBUG
824  std::swap(pX->m_list, pY->m_list);
825 #endif
826 
827  if (pX->m_next == pX) {
828  pX->m_next = pY;
829  pY->m_prev = pX;
830  }
831  if (pX->m_prev == pX) {
832  pX->m_prev = pY;
833  pY->m_next = pX;
834  }
835 
836  if (pX->m_prev) {
837  pX->m_prev->m_next = pX;
838  } else {
839  m_head = pX;
840  }
841 
842  if (pY->m_prev) {
843  pY->m_prev->m_next = pY;
844  } else {
845  m_head = pY;
846  }
847 
848  if (pX->m_next) {
849  pX->m_next->m_prev = pX;
850  } else {
851  m_tail = pX;
852  }
853 
854  if (pY->m_next) {
855  pY->m_next->m_prev = pY;
856  } else {
857  m_tail = pY;
858  }
859  }
860 
862 
866  OGDF_ASSERT(it.listOf() == this);
867  // remove it
868  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
869  //already at front
870  if (!pPrev) {
871  return;
872  }
873 
874  //update old position
875  if (pPrev) {
876  pPrev->m_next = pNext;
877  }
878  if (pNext) {
879  pNext->m_prev = pPrev;
880  } else {
881  m_tail = pPrev;
882  }
883  // insert it at front
884  pX->m_prev = nullptr;
885  pX->m_next = m_head;
886  m_head = m_head->m_prev = pX;
887  }
888 
890 
893  void moveToBack(iterator it) {
894  OGDF_ASSERT(it.listOf() == this);
895  // remove it
896  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
897  //already at back
898  if (!pNext) {
899  return;
900  }
901 
902  //update old position
903  if (pPrev) {
904  pPrev->m_next = pNext;
905  } else {
906  m_head = pNext;
907  }
908  if (pNext) {
909  pNext->m_prev = pPrev;
910  }
911  // insert it at back
912  pX->m_prev = m_tail;
913  pX->m_next = nullptr;
914  m_tail = m_tail->m_next = pX;
915  }
916 
918 
921  void moveToSucc(iterator it, iterator itBefore) {
922  OGDF_ASSERT(it.listOf() == this);
923  OGDF_ASSERT(itBefore.listOf() == this);
924  // move it
925  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
926  //the same of already in place
927  ListElement<E>* pY = itBefore;
928  if (pX == pY || pPrev == pY) {
929  return;
930  }
931 
932  // update old position
933  if (pPrev) {
934  pPrev->m_next = pNext;
935  } else {
936  m_head = pNext;
937  }
938  if (pNext) {
939  pNext->m_prev = pPrev;
940  } else {
941  m_tail = pPrev;
942  }
943  // move it after itBefore
944  ListElement<E>* pYnext = pX->m_next = pY->m_next;
945  (pX->m_prev = pY)->m_next = pX;
946  if (pYnext) {
947  pYnext->m_prev = pX;
948  } else {
949  m_tail = pX;
950  }
951  }
952 
954 
957  void moveToPrec(iterator it, iterator itAfter) {
958  OGDF_ASSERT(it.listOf() == this);
959  OGDF_ASSERT(itAfter.listOf() == this);
960  // move it
961  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
962  //the same of already in place
963  ListElement<E>* pY = itAfter;
964  if (pX == pY || pNext == pY) {
965  return;
966  }
967 
968  // update old position
969  if (pPrev) {
970  pPrev->m_next = pNext;
971  } else {
972  m_head = pNext;
973  }
974  if (pNext) {
975  pNext->m_prev = pPrev;
976  } else {
977  m_tail = pPrev;
978  }
979  // move it before itAfter
980  ListElement<E>* pYprev = pX->m_prev = pY->m_prev;
981  (pX->m_next = pY)->m_prev = pX;
982  if (pYprev) {
983  pYprev->m_next = pX;
984  } else {
985  m_head = pX;
986  }
987  }
988 
990 
994  OGDF_ASSERT(it.listOf() == this);
995  OGDF_ASSERT(this != &L2);
996  // remove it
997  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
998  if (pPrev) {
999  pPrev->m_next = pNext;
1000  } else {
1001  m_head = pNext;
1002  }
1003  if (pNext) {
1004  pNext->m_prev = pPrev;
1005  } else {
1006  m_tail = pPrev;
1007  }
1008  // insert it at front of L2
1009  pX->m_prev = nullptr;
1010  if ((pX->m_next = L2.m_head) != nullptr) {
1011  L2.m_head = L2.m_head->m_prev = pX;
1012  } else {
1013  L2.m_head = L2.m_tail = pX;
1014  }
1015 
1016 #ifdef OGDF_DEBUG
1017  pX->m_list = &L2;
1018 #endif
1019  }
1020 
1022 
1026  OGDF_ASSERT(it.listOf() == this);
1027  OGDF_ASSERT(this != &L2);
1028  // remove it
1029  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
1030  if (pPrev) {
1031  pPrev->m_next = pNext;
1032  } else {
1033  m_head = pNext;
1034  }
1035  if (pNext) {
1036  pNext->m_prev = pPrev;
1037  } else {
1038  m_tail = pPrev;
1039  }
1040  // insert it at back of L2
1041  pX->m_next = nullptr;
1042  if ((pX->m_prev = L2.m_tail) != nullptr) {
1043  L2.m_tail = L2.m_tail->m_next = pX;
1044  } else {
1045  L2.m_head = L2.m_tail = pX;
1046  }
1047 
1048 #ifdef OGDF_DEBUG
1049  pX->m_list = this;
1050 #endif
1051  }
1052 
1054 
1058  void moveToSucc(iterator it, ListPure<E>& L2, iterator itBefore) {
1059  OGDF_ASSERT(it.listOf() == this);
1060  OGDF_ASSERT(itBefore.listOf() == &L2);
1061  OGDF_ASSERT(this != &L2);
1062  // remove it
1063  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
1064  if (pPrev) {
1065  pPrev->m_next = pNext;
1066  } else {
1067  m_head = pNext;
1068  }
1069  if (pNext) {
1070  pNext->m_prev = pPrev;
1071  } else {
1072  m_tail = pPrev;
1073  }
1074  // insert it in list L2 after itBefore
1075  ListElement<E>* pY = itBefore;
1076  ListElement<E>* pYnext = pX->m_next = pY->m_next;
1077  (pX->m_prev = pY)->m_next = pX;
1078  if (pYnext) {
1079  pYnext->m_prev = pX;
1080  } else {
1081  L2.m_tail = pX;
1082  }
1083 
1084 #ifdef OGDF_DEBUG
1085  pX->m_list = &L2;
1086 #endif
1087  }
1088 
1090 
1094  void moveToPrec(iterator it, ListPure<E>& L2, iterator itAfter) {
1095  OGDF_ASSERT(it.listOf() == this);
1096  OGDF_ASSERT(itAfter.listOf() == &L2);
1097  OGDF_ASSERT(this != &L2);
1098  // remove it
1099  ListElement<E>*pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
1100  if (pPrev) {
1101  pPrev->m_next = pNext;
1102  } else {
1103  m_head = pNext;
1104  }
1105  if (pNext) {
1106  pNext->m_prev = pPrev;
1107  } else {
1108  m_tail = pPrev;
1109  }
1110  // insert it in list L2 after itBefore
1111  ListElement<E>* pY = itAfter;
1112  ListElement<E>* pYprev = pX->m_prev = pY->m_prev;
1113  (pX->m_next = pY)->m_prev = pX;
1114  if (pYprev) {
1115  pYprev->m_next = pX;
1116  } else {
1117  L2.m_head = pX;
1118  }
1119 
1120 #ifdef OGDF_DEBUG
1121  pX->m_list = &L2;
1122 #endif
1123  }
1124 
1126  void conc(ListPure<E>& L2) {
1127  OGDF_ASSERT(this != &L2);
1128  if (m_head) {
1129  m_tail->m_next = L2.m_head;
1130  } else {
1131  m_head = L2.m_head;
1132  }
1133  if (L2.m_head) {
1134  L2.m_head->m_prev = m_tail;
1135  m_tail = L2.m_tail;
1136  }
1137 
1138  reassignListRefs(L2.m_head);
1139 
1140  L2.m_head = L2.m_tail = nullptr;
1141  }
1142 
1145  OGDF_ASSERT(this != &L2);
1146  if (m_head) {
1147  m_head->m_prev = L2.m_tail;
1148  } else {
1149  m_tail = L2.m_tail;
1150  }
1151  if (L2.m_head) {
1152  L2.m_tail->m_next = m_head;
1153  m_head = L2.m_head;
1154  }
1155 
1156  reassignListRefs(L2.m_head);
1157 
1158  L2.m_head = L2.m_tail = nullptr;
1159  }
1160 
1162  void swap(ListPure<E>& other) {
1163  std::swap(m_head, other.m_head);
1164  std::swap(m_tail, other.m_tail);
1165 
1166  reassignListRefs();
1167  other.reassignListRefs();
1168  }
1169 
1171 
1181  OGDF_ASSERT(!it.valid() || it.listOf() == this);
1182  if (&L1 != this) {
1183  L1.clear();
1184  }
1185  if (&L2 != this) {
1186  L2.clear();
1187  }
1188 
1189  if (it.valid()) {
1190  L1.m_head = m_head;
1191  L2.m_tail = m_tail;
1192  if (dir == Direction::before) {
1193  L2.m_head = it;
1194  L1.m_tail = L2.m_head->m_prev;
1195  } else {
1196  L1.m_tail = it;
1197  L2.m_head = L1.m_tail->m_next;
1198  }
1199  L2.m_head->m_prev = L1.m_tail->m_next = nullptr;
1200 
1201  } else {
1202  L1.m_head = L1.m_tail = nullptr;
1203  L2.m_head = m_head;
1204  L2.m_tail = m_tail;
1205  }
1206 
1207  if (this != &L1 && this != &L2) {
1208  m_head = m_tail = nullptr;
1209  }
1210 
1211  L1.reassignListRefs();
1212  L2.reassignListRefs();
1213  }
1214 
1217  OGDF_ASSERT(it.listOf() == this);
1218  OGDF_ASSERT(this != &L2);
1219  L2.clear();
1220  ListElement<E>* pX = it;
1221  if (pX != m_tail) {
1222  (L2.m_head = pX->m_next)->m_prev = nullptr;
1223  pX->m_next = nullptr;
1224  L2.m_tail = m_tail;
1225  m_tail = pX;
1226  }
1227 
1228  L2.reassignListRefs();
1229  }
1230 
1233  OGDF_ASSERT(it.listOf() == this);
1234  OGDF_ASSERT(this != &L2);
1235  L2.clear();
1236  ListElement<E>* pX = it;
1237  L2.m_head = pX;
1238  L2.m_tail = m_tail;
1239  if ((m_tail = pX->m_prev) == nullptr) {
1240  m_head = nullptr;
1241  } else {
1242  m_tail->m_next = nullptr;
1243  }
1244  pX->m_prev = nullptr;
1245 
1246  L2.reassignListRefs();
1247  }
1248 
1250  void reverse() {
1251  ListElement<E>* pX = m_head;
1252  m_head = m_tail;
1253  m_tail = pX;
1254  while (pX) {
1255  ListElement<E>* pY = pX->m_next;
1256  pX->m_next = pX->m_prev;
1257  pX = pX->m_prev = pY;
1258  }
1259  }
1260 
1262 
1266 
1270  ListConstIterator<E> search(const E& e) const {
1272  for (i = begin(); i.valid(); ++i) {
1273  if (*i == e) {
1274  return i;
1275  }
1276  }
1277  return i;
1278  }
1279 
1282  ListIterator<E> search(const E& e) {
1283  ListIterator<E> i;
1284  for (i = begin(); i.valid(); ++i) {
1285  if (*i == e) {
1286  return i;
1287  }
1288  }
1289  return i;
1290  }
1291 
1295  template<class COMPARER>
1296  ListConstIterator<E> search(const E& e, const COMPARER& comp) const {
1298  for (i = begin(); i.valid(); ++i) {
1299  if (comp.equal(*i, e)) {
1300  return i;
1301  }
1302  }
1303  return i;
1304  }
1305 
1309  template<class COMPARER>
1310  ListIterator<E> search(const E& e, const COMPARER& comp) {
1311  ListIterator<E> i;
1312  for (i = begin(); i.valid(); ++i) {
1313  if (comp.equal(*i, e)) {
1314  return i;
1315  }
1316  }
1317  return i;
1318  }
1319 
1322 
1324  template<class COMPARER>
1325  void quicksort(const COMPARER& comp) {
1326  ogdf::quicksortTemplate(*this, comp);
1327  }
1328 
1330 
1337  void bucketSort(int l, int h, BucketFunc<E>& f);
1338 
1340 
1344 
1355  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1356  bool isFastTest = true) const {
1357  return chooseIteratorFrom(*this, includeElement, isFastTest);
1358  }
1359 
1362  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1363  bool isFastTest = true) {
1364  return chooseIteratorFrom(*this, includeElement, isFastTest);
1365  }
1366 
1376  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1377  bool isFastTest = true) const {
1378  const_iterator result = chooseIterator(includeElement, isFastTest);
1379  OGDF_ASSERT(result.valid());
1380  return *result;
1381  }
1382 
1385  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1386  bool isFastTest = true) {
1387  iterator result = chooseIterator(includeElement, isFastTest);
1388  OGDF_ASSERT(result.valid());
1389  return *result;
1390  }
1391 
1393  void permute() {
1394  std::minstd_rand rng(randomSeed());
1395  permute(size(), rng);
1396  }
1397 
1399  template<class RNG>
1400  void permute(RNG& rng) {
1401  permute(size(), rng);
1402  }
1403 
1405 
1406 protected:
1407  void copy(const ListPure<E>& L) {
1408  for (ListElement<E>* pX = L.m_head; pX != nullptr; pX = pX->m_next) {
1409  pushBack(pX->m_x);
1410  }
1411  }
1412 
1413  template<class RNG>
1414 
1416  void permute(const int n, RNG& rng);
1417 
1419  inline void reassignListRefs(ListElement<E>* start = nullptr) {
1420 #ifdef OGDF_DEBUG
1421  for (auto e = start == nullptr ? m_head : start; e != nullptr; e = e->m_next) {
1422  e->m_list = this;
1423  }
1424 #endif
1425  }
1426 
1428 };
1429 
1431 
1440 template<class E>
1441 class List : private ListPure<E> {
1442  int m_count;
1443 
1444 public:
1445  using typename ListPure<E>::value_type;
1446  using typename ListPure<E>::reference;
1447  using typename ListPure<E>::const_reference;
1448  using typename ListPure<E>::const_iterator;
1449  using typename ListPure<E>::iterator;
1450  using typename ListPure<E>::const_reverse_iterator;
1451  using typename ListPure<E>::reverse_iterator;
1452 
1454  List() : m_count(0) { }
1455 
1457  List(std::initializer_list<E> init) : ListPure<E>(init), m_count((int)init.size()) { }
1458 
1460  List(const List<E>& L) : ListPure<E>(L), m_count(L.m_count) { }
1461 
1463 
1466  List(List<E>&& L) noexcept : ListPure<E>(std::move(L)), m_count(L.m_count) { L.m_count = 0; }
1467 
1472 
1475 
1478  int size() const { return m_count; }
1479 
1481  const ListPure<E>& getListPure() const { return *this; }
1482 
1484 
1488 
1493  m_count = L.m_count;
1494  return *this;
1495  }
1496 
1498 
1502  m_count = L.m_count;
1504  L.m_count = 0;
1505  return *this;
1506  }
1507 
1509  bool operator==(const List<E>& L) const {
1510  return (m_count == L.m_count) && ListPure<E>::operator==(L);
1511  }
1512 
1514  bool operator!=(const List<E>& L) const { return !operator==(L); }
1515 
1517 
1521 
1524  iterator pushFront(const E& x) {
1525  ++m_count;
1526  return ListPure<E>::pushFront(x);
1527  }
1528 
1530  template<class... Args>
1531  iterator emplaceFront(Args&&... args) {
1532  ++m_count;
1533  return ListPure<E>::emplaceFront(std::forward<Args>(args)...);
1534  }
1535 
1537  iterator pushBack(const E& x) {
1538  ++m_count;
1539  return ListPure<E>::pushBack(x);
1540  }
1541 
1543  template<class... Args>
1544  iterator emplaceBack(Args&&... args) {
1545  ++m_count;
1546  return ListPure<E>::emplaceBack(std::forward<Args>(args)...);
1547  }
1548 
1550  iterator insert(const E& x, iterator it, Direction dir = Direction::after) {
1551  ++m_count;
1552  return ListPure<E>::insert(x, it, dir);
1553  }
1554 
1556  iterator insertBefore(const E& x, iterator it) {
1557  ++m_count;
1558  return ListPure<E>::insertBefore(x, it);
1559  }
1560 
1562  iterator insertAfter(const E& x, iterator it) {
1563  ++m_count;
1564  return ListPure<E>::insertAfter(x, it);
1565  }
1566 
1568 
1572 
1575  void popFront() {
1576  --m_count;
1578  }
1579 
1582  E el = front();
1583  popFront();
1584  return el;
1585  }
1586 
1588  void popBack() {
1589  --m_count;
1591  }
1592 
1595  E el = back();
1596  popBack();
1597  return el;
1598  }
1599 
1601  void del(iterator it) {
1602  --m_count;
1603  ListPure<E>::del(it);
1604  }
1605 
1607  bool removeFirst(const E& x) {
1608  bool hasRemoved = ListPure<E>::removeFirst(x);
1609  if (hasRemoved) {
1610  --m_count;
1611  }
1612  return hasRemoved;
1613  }
1614 
1616  void clear() {
1617  m_count = 0;
1619  }
1620 
1622 
1626 
1629  void moveToFront(iterator it, List<E>& L2) {
1630  ListPure<E>::moveToFront(it, L2);
1631  --m_count;
1632  ++L2.m_count;
1633  }
1634 
1636  void moveToBack(iterator it, List<E>& L2) {
1637  ListPure<E>::moveToBack(it, L2);
1638  --m_count;
1639  ++L2.m_count;
1640  }
1641 
1643  void moveToSucc(iterator it, List<E>& L2, iterator itBefore) {
1644  ListPure<E>::moveToSucc(it, L2, itBefore);
1645  --m_count;
1646  ++L2.m_count;
1647  }
1648 
1650  void moveToPrec(iterator it, List<E>& L2, iterator itAfter) {
1651  ListPure<E>::moveToPrec(it, L2, itAfter);
1652  --m_count;
1653  ++L2.m_count;
1654  }
1655 
1657  void conc(List<E>& L2) {
1658  ListPure<E>::conc(L2);
1659  m_count += L2.m_count;
1660  L2.m_count = 0;
1661  }
1662 
1664  void concFront(List<E>& L2) {
1666  m_count += L2.m_count;
1667  L2.m_count = 0;
1668  }
1669 
1671  void swap(List<E>& other) {
1672  ListPure<E>::swap(other);
1673  std::swap(m_count, other.m_count);
1674  }
1675 
1677  void split(iterator it, List<E>& L1, List<E>& L2, Direction dir = Direction::before) {
1678  ListPure<E>::split(it, L1, L2, dir);
1679  int countL = m_count, countL1 = 0;
1680  for (ListElement<E>* pX = L1.m_head; pX != nullptr; pX = pX->m_next) {
1681  ++countL1;
1682  }
1683 
1684  L1.m_count = countL1;
1685  L2.m_count = countL - countL1;
1686  if (this->m_head == nullptr) {
1687  m_count = 0;
1688  }
1689  }
1690 
1691  using ListPure<E>::empty;
1692  using ListPure<E>::front;
1693  using ListPure<E>::back;
1694  using ListPure<E>::get;
1695  using ListPure<E>::pos;
1696  using ListPure<E>::begin;
1697  using ListPure<E>::cbegin;
1698  using ListPure<E>::end;
1699  using ListPure<E>::cend;
1700  using ListPure<E>::rbegin;
1701  using ListPure<E>::crbegin;
1702  using ListPure<E>::rend;
1703  using ListPure<E>::crend;
1706  using ListPure<E>::exchange;
1711  using ListPure<E>::reverse;
1712  using ListPure<E>::search;
1713  using ListPure<E>::quicksort;
1717  using ListPure<E>::permute;
1718 
1720 };
1721 
1722 template<class E>
1723 void ListPure<E>::bucketSort(int l, int h, BucketFunc<E>& f) {
1724  if (m_head == m_tail) {
1725  return;
1726  }
1727 
1728  Array<ListElement<E>*> head(l, h, nullptr), tail(l, h);
1729 
1730  ListElement<E>* pX;
1731  for (pX = m_head; pX; pX = pX->m_next) {
1732  int i = f.getBucket(pX->m_x);
1733  if (head[i]) {
1734  tail[i] = ((pX->m_prev = tail[i])->m_next = pX);
1735  } else {
1736  head[i] = tail[i] = pX;
1737  }
1738  }
1739 
1740  ListElement<E>* pY = nullptr;
1741  for (int i = l; i <= h; i++) {
1742  pX = head[i];
1743  if (pX) {
1744  if (pY) {
1745  (pY->m_next = pX)->m_prev = pY;
1746  } else {
1747  (m_head = pX)->m_prev = nullptr;
1748  }
1749  pY = tail[i];
1750  }
1751  }
1752 
1753  m_tail = pY;
1754  pY->m_next = nullptr;
1755 }
1756 
1757 template<class E>
1758 template<class RNG>
1759 void ListPure<E>::permute(const int n, RNG& rng) {
1760  //if n==0 do nothing
1761  if (n == 0) {
1762  return;
1763  }
1764 
1765  Array<ListElement<E>*> A(n + 2);
1766  A[0] = A[n + 1] = nullptr;
1767 
1768  int i = 1;
1769  ListElement<E>* pX;
1770  for (pX = m_head; pX; pX = pX->m_next) {
1771  A[i++] = pX;
1772  }
1773 
1774  A.permute(1, n, rng);
1775 
1776  for (i = 1; i <= n; i++) {
1777  pX = A[i];
1778  pX->m_next = A[i + 1];
1779  pX->m_prev = A[i - 1];
1780  }
1781 
1782  m_head = A[1];
1783  m_tail = A[n];
1784 }
1785 
1787 template<class E>
1788 void print(std::ostream& os, const ListPure<E>& L, char delim = ' ') {
1789  typename ListPure<E>::const_iterator pX = L.begin();
1790  if (pX.valid()) {
1791  os << *pX;
1792  for (++pX; pX.valid(); ++pX) {
1793  os << delim << *pX;
1794  }
1795  }
1796 }
1797 
1799 template<class E>
1800 void print(std::ostream& os, const List<E>& L, char delim = ' ') {
1801  print(os, L.getListPure(), delim);
1802 }
1803 
1805 template<class E>
1806 std::ostream& operator<<(std::ostream& os, const ListPure<E>& L) {
1807  print(os, L);
1808  return os;
1809 }
1810 
1812 template<class E>
1813 std::ostream& operator<<(std::ostream& os, const List<E>& L) {
1814  return os << L.getListPure();
1815 }
1816 
1817 template<class E, class Master>
1818 class ListContainer : public List<E> {
1819  friend Master;
1820 
1821 public:
1826 
1828  iterator begin() const { return List<E>::cbegin(); }
1829 
1831  iterator end() const { return List<E>::cend(); }
1832 
1835 
1837  reverse_iterator rend() const { return List<E>::crend(); }
1838 
1840  int size() const { return List<E>::size(); }
1841 };
1842 
1843 }
ogdf::ListPure::begin
const_iterator begin() const
Returns a const iterator to the first element of the list.
Definition: List.h:387
ogdf::ListElement::ListElement
ListElement(ListPure< E > *list, const E &x, ListElement< E > *next, ListElement< E > *prev)
Constructs a ListElement.
Definition: List.h:74
ogdf::ListPure::reassignListRefs
void reassignListRefs(ListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
Definition: List.h:1419
ogdf::ListPure< TObserver * >::reference
TObserver * & reference
Provides a reference to an element stored in a list.
Definition: List.h:232
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::ListIteratorBase::pred
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
Definition: List.h:169
ogdf::ListPure::permute
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
Definition: List.h:1400
ogdf::chooseIteratorFrom
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.
Definition: list_templates.h:219
ogdf::ListPure::split
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:1180
ogdf::ListElement::m_x
E m_x
Stores the content.
Definition: List.h:68
ogdf::ListPure::moveToPrec
void moveToPrec(iterator it, ListPure< E > &L2, iterator itAfter)
Moves it to list L2 and inserts it before itAfter.
Definition: List.h:1094
ogdf::Direction
Direction
Definition: basic.h:148
ogdf::ListPure::chooseIterator
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:1354
ogdf::List::moveToBack
void moveToBack(iterator it, List< E > &L2)
Moves it to the end of the list.
Definition: List.h:1636
ogdf::ListPure::m_head
ListElement< E > * m_head
Pointer to first element.
Definition: List.h:225
ogdf::ListPure::const_reverse_iterator
ListConstReverseIterator< E > const_reverse_iterator
Provides a bidirectional reverse iterator that can read a const element in a list.
Definition: List.h:240
ogdf::ListIteratorBase< ogdf::Graph::HiddenEdgeSet * >::value_type
Elem value_type
Definition: List.h:118
ogdf::ListPure::copy
void copy(const ListPure< E > &L)
Definition: List.h:1407
ogdf::ListPure::clear
void clear()
Removes all elements from the list.
Definition: List.h:789
ogdf::ListIteratorBase::ListIteratorBase
ListIteratorBase(const ListIteratorBase< E, isArgConst, isArgReverse > &it)
Constructs an iterator that is a copy of it.
Definition: List.h:134
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::List::conc
void conc(List< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition: List.h:1657
ogdf::List::swap
void swap(List< E > &other)
Exchanges the contents of this list and other in constant time.
Definition: List.h:1671
ogdf::ListPure::splitAfter
void splitAfter(iterator it, ListPure< E > &L2)
Splits the list after it.
Definition: List.h:1216
ogdf::ListIteratorBase::operator++
ListIteratorBase< E, isConst, isReverse > & operator++()
Increment operator (prefix).
Definition: List.h:184
ogdf::ListPure::bucketSort
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
Definition: List.h:1723
ogdf::ListElement::m_list
ListPure< E > * m_list
List object that the element belongs to.
Definition: List.h:70
ogdf::ListElement::ListElement
ListElement(ListPure< E > *list, const E &x)
Constructs a ListElement.
Definition: List.h:82
ogdf::List::popFront
void popFront()
Removes the first element from the list.
Definition: List.h:1575
ogdf::ListContainer::Master
friend Master
Definition: List.h:1819
ogdf::ListPure::moveToSucc
void moveToSucc(iterator it, ListPure< E > &L2, iterator itBefore)
Moves it to list L2 and inserts it after itBefore.
Definition: List.h:1058
ogdf::ListPure::cyclicSucc
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
Definition: List.h:463
ogdf::ListPure::back
reference back()
Returns a reference to the last element.
Definition: List.h:322
ogdf::List::split
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:1677
ogdf::ListPure::size
virtual int size() const
Returns the number of elements in the list.
Definition: List.h:283
ogdf::List::List
List(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
Definition: List.h:1457
ogdf::ListPure::emplaceFront
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition: List.h:591
ogdf::ListPure::back
const_reference back() const
Returns a const reference to the last element.
Definition: List.h:313
ogdf::List::popFrontRet
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:1581
ogdf::whaType::A
@ A
ogdf::ListIteratorBase::operator!=
bool operator!=(const ListIteratorBase< E, isConst, isReverse > &it) const
Inequality operator.
Definition: List.h:159
ogdf::ListPure::operator==
bool operator==(const ListPure< E > &L) const
Equality operator.
Definition: List.h:553
ogdf::ListPure::insertAfter
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:679
ogdf::ListPure::begin
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:381
ogdf::ListPure::popBackRet
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:745
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:143
ogdf::List::operator==
bool operator==(const List< E > &L) const
Equality operator.
Definition: List.h:1509
ogdf::ListPure::crbegin
const_reverse_iterator crbegin() const
Returns a const iterator to the last element of the list.
Definition: List.h:429
ogdf::ListPure::popFront
void popFront()
Removes the first element from the list.
Definition: List.h:703
ogdf::BucketFunc
Abstract base class for bucket functions.
Definition: basic.h:255
ogdf::Direction::before
@ before
ogdf::ListPure::iterator
ListIterator< E > iterator
Provides a bidirectional iterator that can read or modify any element in a list.
Definition: List.h:238
ogdf::ListPure::cyclicSucc
const_iterator cyclicSucc(const_iterator it) const
Returns a const iterator to the cyclic successor of it.
Definition: List.h:453
ogdf::List::operator=
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition: List.h:1491
ogdf::ListPure::exchange
void exchange(iterator it1, iterator it2)
Exchanges the positions of it1 and it2 in the list.
Definition: List.h:815
ogdf::ListPure::get
const_iterator get(int pos) const
Returns a const iterator pointing to the element at position pos.
Definition: List.h:331
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:84
ogdf::List::insertAfter
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:1562
ogdf::ListContainer< ogdf::ClusterElement, ogdf::ClusterElement >::reverse_iterator
typename List< ogdf::ClusterElement >::const_reverse_iterator reverse_iterator
Provides a bidirectional reverse iterator to an object in the container.
Definition: List.h:1825
ogdf::ListPure::search
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:1282
ogdf::ListContainer::rbegin
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
Definition: List.h:1834
ogdf::ListElement::m_next
ListElement< E > * m_next
Pointer to successor element.
Definition: List.h:66
ogdf::ListPure::conc
void conc(ListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition: List.h:1126
ogdf::ListPure::ListPure
ListPure(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
Definition: List.h:248
ogdf::List::concFront
void concFront(List< E > &L2)
Prepends L2 to this list and makes L2 empty.
Definition: List.h:1664
ogdf::ListPure::ListPure
ListPure(ListPure< E > &&L) noexcept
Constructs a doubly linked list containing the elements of L (move semantics).
Definition: List.h:261
ogdf::ListPure::end
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: List.h:399
ogdf::ListPure::operator=
ListPure< E > & operator=(const ListPure< E > &L)
Assignment operator.
Definition: List.h:533
ogdf::List::m_count
int m_count
The length of the list.
Definition: List.h:1442
ogdf::ListContainer::size
int size() const
Returns the number of elements in the container.
Definition: List.h:1840
ogdf::ListPure::moveToBack
void moveToBack(iterator it)
Moves it to the end of the list.
Definition: List.h:893
ogdf::List::insert
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Definition: List.h:1550
ogdf::ListPure::moveToSucc
void moveToSucc(iterator it, iterator itBefore)
Moves it after itBefore.
Definition: List.h:921
ogdf::ListIteratorBase::ListIteratorBase
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
Definition: List.h:127
ogdf::ListPure::end
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
Definition: List.h:405
ogdf::ListIteratorBase::succ
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:164
ogdf::ListElement::ListElement
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
ogdf::ListContainer< ogdf::ClusterElement, ogdf::ClusterElement >::iterator
typename List< ogdf::ClusterElement >::const_iterator iterator
Provides a bidirectional iterator to an object in the container.
Definition: List.h:1823
ogdf::ListIteratorBase::m_pX
ListElem * m_pX
pointer to list element
Definition: List.h:114
ogdf::ListPure::ListPure
ListPure(const ListPure< E > &L)
Constructs a doubly linked list that is a copy of L.
Definition: List.h:255
ogdf::List::operator=
List< E > & operator=(List< E > &&L)
Assignment operator (move semantics).
Definition: List.h:1501
ogdf::ListIteratorBase::operator--
ListIteratorBase< E, isConst, isReverse > operator--(int)
Decrement operator (postfix).
Definition: List.h:203
ogdf::ListPure::popFrontRet
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:719
ogdf::Direction::after
@ after
ogdf::ListPure::cyclicPred
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Definition: List.h:491
list_templates.h
Implementation of algorithms as templates working with different list types.
ogdf::ListPure::concFront
void concFront(ListPure< E > &L2)
Prepends L2 to this list and makes L2 empty.
Definition: List.h:1144
ogdf::ListIteratorBase::operator*
Elem & operator*() const
Returns a reference to the element content.
Definition: List.h:174
ogdf::ListPure::cyclicPred
iterator cyclicPred(iterator it)
Returns an iterator to the cyclic predecessor of it.
Definition: List.h:501
ogdf::List::pushFront
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1524
ogdf::ListIteratorBase< ogdf::Graph::HiddenEdgeSet * >::pointer
value_type * pointer
Definition: List.h:120
ogdf::ListPure::moveToFront
void moveToFront(iterator it)
Moves it to the begin of the list.
Definition: List.h:865
ogdf::ListPure::search
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:1296
backward::Color::type
type
Definition: backward.hpp:1716
ogdf::ListPure::chooseIterator
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:1361
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:214
ogdf::ListPure::swap
void swap(ListPure< E > &other)
Exchanges the contents of this list and other in constant time.
Definition: List.h:1162
ogdf::ListPure::~ListPure
virtual ~ListPure()
Destructor.
Definition: List.h:267
ogdf::ListContainer::begin
iterator begin() const
Returns an iterator to the first element in the container.
Definition: List.h:1828
ogdf::List::moveToSucc
void moveToSucc(iterator it, List< E > &L2, iterator itBefore)
Moves it after itBefore.
Definition: List.h:1643
ogdf::List::moveToPrec
void moveToPrec(iterator it, List< E > &L2, iterator itAfter)
Moves it before itAfter.
Definition: List.h:1650
ogdf::ListIteratorBase::operator++
ListIteratorBase< E, isConst, isReverse > operator++(int)
Increment operator (postfix).
Definition: List.h:190
ogdf::ListPure::chooseElement
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
Definition: List.h:1375
ogdf::ListPure::emplaceBack
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: List.h:617
ogdf::ListPure::moveToBack
void moveToBack(iterator it, ListPure< E > &L2)
Moves it to the end of L2.
Definition: List.h:1025
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:978
ogdf::ListPure::rbegin
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
Definition: List.h:417
ogdf::ListPure::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: List.h:393
ogdf::ListPure::rend
reverse_iterator rend()
Returns an iterator to one-before-first element of the list.
Definition: List.h:435
ogdf::ListIteratorBase::operator--
ListIteratorBase< E, isConst, isReverse > & operator--()
Decrement operator (prefix).
Definition: List.h:197
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::ListPure::reverse
void reverse()
Reverses the order of the list elements.
Definition: List.h:1250
ogdf::ListPure::search
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:1310
ogdf::ListIteratorBase< ogdf::Graph::HiddenEdgeSet * >::reference
value_type & reference
Definition: List.h:121
ogdf::ListPure::popBack
void popBack()
Removes the last element from the list.
Definition: List.h:729
ogdf::ListPure::cend
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: List.h:411
ogdf::ListPure::const_iterator
ListConstIterator< E > const_iterator
Provides a bidirectional iterator that can read a const element in a list.
Definition: List.h:236
ogdf::List::popBackRet
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1594
ogdf::ListPure::insertBefore
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition: List.h:662
ogdf::ListPure::cyclicPred
reverse_iterator cyclicPred(reverse_iterator it)
Definition: List.h:519
ogdf::ListPure::operator!=
bool operator!=(const ListPure< E > &L) const
Inequality operator.
Definition: List.h:566
ogdf::ListPure::removeFirst
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition: List.h:778
ogdf::ListPure::moveToPrec
void moveToPrec(iterator it, iterator itAfter)
Moves it before itAfter.
Definition: List.h:957
ogdf::ListPure::rend
const_reverse_iterator rend() const
Returns a const iterator to one-before-first element of the list.
Definition: List.h:441
ogdf::List::List
List()
Constructs an empty doubly linked list.
Definition: List.h:1454
ogdf::ListPure::operator=
ListPure< E > & operator=(ListPure< E > &&L)
Assignment operator (move semantics).
Definition: List.h:543
ogdf::ListPure::rbegin
const_reverse_iterator rbegin() const
Returns a const iterator to the last element of the list.
Definition: List.h:423
ogdf::ListContainer
Definition: List.h:1818
ogdf::ListPure
Doubly linked lists.
Definition: List.h:44
ogdf::randomSeed
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
ogdf::ListElement
Structure for elements of doubly linked lists.
Definition: List.h:58
Reverse.h
Implementation of the Reverse class for the reverse iteration of containers.
ogdf::ListPure::cyclicSucc
const_reverse_iterator cyclicSucc(const_reverse_iterator it) const
Definition: List.h:472
ogdf::ListPure::ListPure
ListPure()
Constructs an empty doubly linked list.
Definition: List.h:245
ogdf::ListIteratorBase< ogdf::Graph::HiddenEdgeSet * >::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: List.h:119
ogdf::ListIteratorBase::operator==
bool operator==(const ListIteratorBase< E, isConst, isReverse > &it) const
Equality operator.
Definition: List.h:154
ogdf::ListPure::quicksort
void quicksort()
Sorts the list using Quicksort.
Definition: List.h:1321
ogdf::ListPure::pos
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
Definition: List.h:359
ogdf::graphics::init
void init()
Definition: graphics.h:446
ogdf::ListIteratorBase::operator=
ListIteratorBase< E, isConst, isReverse > & operator=(const ListIteratorBase< E, isConst, isReverse > &it)
Assignment operator.
Definition: List.h:177
ogdf::List::getListPure
const ListPure< E > & getListPure() const
Conversion to const ListPure.
Definition: List.h:1481
ogdf::List::del
void del(iterator it)
Removes it from the list.
Definition: List.h:1601
ogdf::ListPure::cyclicPred
const_reverse_iterator cyclicPred(const_reverse_iterator it) const
Definition: List.h:510
std
Definition: GML.h:110
ogdf::List::popBack
void popBack()
Removes the last element from the list.
Definition: List.h:1588
ogdf::ListIteratorBase::ListElem
typename std::conditional< isConst, const ListElement< E >, ListElement< E > >::type ListElem
The underlying list element, depending on isConst.
Definition: List.h:109
ogdf::ListContainer::end
iterator end() const
Returns an iterator to the one-past-last element in the container.
Definition: List.h:1831
ogdf::ListContainer::rend
reverse_iterator rend() const
Returns a reverse iterator to the one-before-first element in the container.
Definition: List.h:1837
ogdf::ListPure::crend
const_reverse_iterator crend() const
Returns a const iterator to one-before-first element of the list.
Definition: List.h:447
ogdf::ListIteratorBase::ListIteratorBase
ListIteratorBase()
Constructs an invalid iterator.
Definition: List.h:130
ogdf::ListIteratorBase::listOf
ListPure< E > * listOf()
Returns the list that this iterator belongs to.
Definition: List.h:148
ogdf::ListPure::moveToFront
void moveToFront(iterator it, ListPure< E > &L2)
Moves it to the begin of L2.
Definition: List.h:993
ogdf::print
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
ogdf::ListPure::front
reference front()
Returns a reference to the first element.
Definition: List.h:304
ogdf::ListPure::front
const_reference front() const
Returns a const reference to the first element.
Definition: List.h:295
ogdf::ListPure::quicksort
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
Definition: List.h:1325
ogdf::List::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1478
ogdf::ListPure::get
iterator get(int pos)
Returns an iterator pointing to the element at position pos.
Definition: List.h:345
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:46
ogdf::List::List
List(List< E > &&L) noexcept
Constructs a doubly linked list containing the elements of L (move semantics).
Definition: List.h:1466
ogdf::ListPure::cyclicSucc
reverse_iterator cyclicSucc(reverse_iterator it)
Definition: List.h:481
ogdf::List::emplaceFront
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition: List.h:1531
ogdf::ListPure::m_tail
ListElement< E > * m_tail
Pointer to last element.
Definition: List.h:226
ogdf::ListPure::chooseElement
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
Definition: List.h:1384
ogdf::quicksortTemplate
void quicksortTemplate(LIST &L)
Definition: list_templates.h:77
ogdf::ListIteratorBase::ListIteratorBase
ListIteratorBase(const ListIteratorBase< E, isConst, isReverse > &it)
Copy constructor.
Definition: List.h:139
ogdf::ListPure::search
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:1270
ogdf::ListPure::splitBefore
void splitBefore(iterator it, ListPure< E > &L2)
Splits the list before it.
Definition: List.h:1232
ogdf::ListPure::pushFront
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:576
ogdf::ListPure::del
void del(iterator it)
Removes it from the list.
Definition: List.h:755
ogdf::List::removeFirst
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition: List.h:1607
ogdf::List::operator!=
bool operator!=(const List< E > &L) const
Inequality operator.
Definition: List.h:1514
ogdf::ListPure< TObserver * >::const_reference
const TObserver * & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations.
Definition: List.h:234
ogdf::List::List
List(const List< E > &L)
Constructs a doubly linked list that is a copy of L.
Definition: List.h:1460
ogdf::ListIteratorBase< ogdf::Graph::HiddenEdgeSet * >::Elem
typename std::conditional< isConst, const ogdf::Graph::HiddenEdgeSet *, ogdf::Graph::HiddenEdgeSet * >::type Elem
The underlying type, depending on isConst.
Definition: List.h:111
ogdf::BucketFunc::getBucket
virtual int getBucket(const E &x)=0
Returns the bucket of x.
ogdf::List::emplaceBack
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: List.h:1544
ogdf::ListPure::empty
bool empty() const
Returns true iff the list is empty.
Definition: List.h:276
ogdf::ListPure::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:602
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
ogdf::List::clear
void clear()
Removes all elements from the list.
Definition: List.h:1616
ogdf::List::insertBefore
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition: List.h:1556
ogdf::List::moveToFront
void moveToFront(iterator it, List< E > &L2)
Moves it to the begin of the list.
Definition: List.h:1629
ogdf::ListIteratorBase< ogdf::Graph::HiddenEdgeSet * >::difference_type
std::ptrdiff_t difference_type
Definition: List.h:117
ogdf::ListPure::reverse_iterator
ListReverseIterator< E > reverse_iterator
Provides a bidirectional reverse iterator that can read or modify any element in a list.
Definition: List.h:242
ogdf::ListPure::insert
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Definition: List.h:635
ogdf::ListPure::permute
void permute()
Randomly permutes the elements in the list.
Definition: List.h:1393
ogdf::ListPure< TObserver * >::value_type
TObserver * value_type
Represents the data type stored in a list element.
Definition: List.h:230
ogdf::ListElement::m_prev
ListElement< E > * m_prev
Pointer to predecessor element.
Definition: List.h:67