Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

List.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 #include <ogdf/basic/Reverse.h>
36 #include <random>
37 
38 namespace ogdf {
39 
40 template<class E> class List;
41 template<class E> class ListPure;
42 template<class E, bool isConst, bool isReverse> class ListIteratorBase;
47 
49 template<class E>
50 class ListElement {
51  friend class ListPure<E>;
52  friend class List<E>;
53  friend class ListIteratorBase<E, true, true>;
54  friend class ListIteratorBase<E, false, true>;
55  friend class ListIteratorBase<E, true, false>;
56  friend class ListIteratorBase<E, false, false>;
57 
60  E m_x;
61 #ifdef OGDF_DEBUG
62  ListPure<E> *m_list;
63 #endif
64 
66  ListElement(ListPure<E> *list, const E &x, ListElement<E> *next, ListElement<E> *prev)
67  : m_next(next), m_prev(prev), m_x(x) {
68 #ifdef OGDF_DEBUG
69  m_list = list;
70 #endif
71  }
73  ListElement(ListPure<E> *list, const E &x) : ListElement(list, x, nullptr, nullptr) { }
75  template<class ... Args>
76  ListElement(ListPure<E> *list, ListElement<E> *next, ListElement<E> *prev, Args && ... args)
77  : ListElement(list, E(std::forward<Args>(args)...), next, prev) { }
78 
80 };
81 
83 
92 template<class E, bool isConst, bool isReverse> class ListIteratorBase {
93  friend class ListIteratorBase<E, !isConst, isReverse>;
94  friend class ListIteratorBase<E, isConst, !isReverse>;
95  friend class ListIteratorBase<E, !isConst, !isReverse>;
96  friend class ListPure<E>;
98  using ListElem = typename std::conditional<isConst, const ListElement<E>, ListElement<E>>::type;
101 
103  ListElem *m_pX;
104 
106  operator ListElem *() { return m_pX; }
107 
108 public:
110  ListIteratorBase(ListElem *pX) : m_pX(pX) { }
111 
114 
118 
120  // gcc9 complains since it cannot match the templated constructor above (-Werror=deprecated-copy).
122 
124  bool valid() const { return m_pX != nullptr; }
125 
126 #ifdef OGDF_DEBUG
127  ListPure<E> *listOf() {
130  OGDF_ASSERT(valid());
131  return m_pX->m_list;
132  }
133 #endif
136  return m_pX == it.m_pX;
137  }
138 
141  return m_pX != it.m_pX;
142  }
143 
146  return isReverse ? m_pX->m_prev : m_pX->m_next;
147  }
148 
151  return isReverse ? m_pX->m_next : m_pX->m_prev;
152  }
153 
155  Elem &operator*() const { return m_pX->m_x; }
156 
159  m_pX = it.m_pX;
160  return *this;
161  }
162 
165  m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
166  return *this;
167  }
168 
172  m_pX = isReverse ? m_pX->m_prev : m_pX->m_next;
173  return it;
174  }
175 
178  m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
179  return *this;
180  }
181 
185  m_pX = isReverse ? m_pX->m_next : m_pX->m_prev;
186  return it;
187  }
188 
190 };
191 
193 
202 template<class E> class ListPure {
203 protected:
206 
207 public:
209  using value_type = E;
211  using reference = E&;
213  using const_reference = const E&;
222 
224  ListPure() : m_head(nullptr), m_tail(nullptr) { }
225 
227  ListPure(std::initializer_list<E> init) : m_head(nullptr), m_tail(nullptr) {
228  for (const E &x : init)
229  pushBack(x);
230  }
231 
233  ListPure(const ListPure<E> &L) : m_head(nullptr), m_tail(nullptr) {
234  copy(L);
235  }
236 
238 
241  ListPure(ListPure<E> &&L) : m_head(L.m_head), m_tail(L.m_tail) {
242  L.m_head = L.m_tail = nullptr;
243  }
244 
246  virtual ~ListPure() { clear(); }
247 
248 
254 
256  bool empty() const { return m_head == nullptr; }
257 
259 
263  virtual int size() const {
264  int count = 0;
265  for (ListElement<E> *pX = m_head; pX; pX = pX->m_next)
266  ++count;
267  return count;
268  }
269 
271 
275  OGDF_ASSERT(m_head != nullptr);
276  return m_head->m_x;
277  }
278 
280 
284  OGDF_ASSERT(m_head != nullptr);
285  return m_head->m_x;
286  }
287 
289 
293  OGDF_ASSERT(m_tail != nullptr);
294  return m_tail->m_x;
295  }
296 
298 
302  OGDF_ASSERT(m_tail != nullptr);
303  return m_tail->m_x;
304  }
305 
307 
310  const_iterator get(int pos) const {
311  ListElement<E> *pX;
312  for(pX = m_head; pX != nullptr; pX = pX->m_next)
313  if (pos-- == 0) break;
314  return pX;
315  }
316 
318 
321  iterator get(int pos) {
322  ListElement<E> *pX;
323  for(pX = m_head; pX != nullptr; pX = pX->m_next)
324  if (pos-- == 0) break;
325  return pX;
326  }
327 
329 
332  int pos(const_iterator it) const {
333  OGDF_ASSERT(it.listOf() == this);
334  int p = 0;
335  for(ListElement<E> *pX = m_head; pX != nullptr; pX = pX->m_next, ++p)
336  if (pX == it) break;
337  return p;
338  }
339 
340 
342 
347 
349 
352  iterator begin() { return m_head; }
353 
355 
358  const_iterator begin() const { return m_head; }
359 
361 
364  const_iterator cbegin() const { return m_head; }
365 
367 
370  iterator end() { return iterator(); }
371 
373 
376  const_iterator end() const { return const_iterator(); }
377 
379 
382  const_iterator cend() const { return const_iterator(); }
383 
385 
388  reverse_iterator rbegin() { return m_tail; }
389 
391 
394  const_reverse_iterator rbegin() const { return m_tail; }
395 
397 
400  const_reverse_iterator crbegin() const { return m_tail; }
401 
403 
407 
409 
413 
415 
419 
421 
425  OGDF_ASSERT(!it.valid() || it.listOf() == this);
426  const ListElement<E> *pX = it;
427  return (pX && pX->m_next) ? pX->m_next : m_head;
428  }
429 
431 
435  OGDF_ASSERT(!it.valid() || it.listOf() == this);
436  ListElement<E> *pX = it;
437  return (pX && pX->m_next) ? pX->m_next : m_head;
438  }
439 
444  OGDF_ASSERT(!it.valid() || it.listOf() == this);
445  const ListElement<E> *pX = it;
446  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
447  }
448 
453  OGDF_ASSERT(!it.valid() || it.listOf() == this);
454  ListElement<E> *pX = it;
455  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
456  }
457 
459 
463  OGDF_ASSERT(!it.valid() || it.listOf() == this);
464  const ListElement<E> *pX = it;
465  return (pX && pX->m_prev) ? pX->m_prev : m_tail;
466  }
467 
469 
473  OGDF_ASSERT(!it.valid() || it.listOf() == this);
474  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  const ListElement<E> *pX = it;
484  return (pX && pX->m_next) ? pX->m_next : m_head;
485  }
486 
491  OGDF_ASSERT(!it.valid() || it.listOf() == this);
492  ListElement<E> *pX = it;
493  return (pX && pX->m_next) ? pX->m_next : m_head;
494  }
495 
497 
502 
505  clear(); copy(L);
506  return *this;
507  }
508 
510 
514  clear();
515  m_head = L.m_head;
516  m_tail = L.m_tail;
517  L.m_head = L.m_tail = nullptr;
518  reassignListRefs();
519  return *this;
520  }
521 
523  bool operator==(const ListPure<E> &L) const {
524  ListElement<E> *pX = m_head, *pY = L.m_head;
525  while(pX != nullptr && pY != nullptr) {
526  if(pX->m_x != pY->m_x)
527  return false;
528  pX = pX->m_next;
529  pY = pY->m_next;
530  }
531  return pX == nullptr && pY == nullptr;
532  }
533 
535  bool operator!=(const ListPure<E> &L) const {
536  return !operator==(L);
537  }
538 
540 
545 
547  iterator pushFront(const E &x) {
548  ListElement<E> *pX = new ListElement<E>(this, x, m_head, nullptr);
549  if (m_head)
550  m_head = m_head->m_prev = pX;
551  else
552  m_head = m_tail = pX;
553  return m_head;
554  }
555 
557 
560  template<class ... Args>
561  iterator emplaceFront(Args && ... args) {
562  ListElement<E> *pX = new ListElement<E>(this, m_head, nullptr, std::forward<Args>(args)...);
563  if (m_head)
564  m_head = m_head->m_prev = pX;
565  else
566  m_head = m_tail = pX;
567  return m_head;
568  }
569 
571  iterator pushBack(const E &x) {
572  ListElement<E> *pX = new ListElement<E>(this, x, nullptr, m_tail);
573  if (m_head)
574  m_tail = m_tail->m_next = pX;
575  else
576  m_tail = m_head = pX;
577  return m_tail;
578  }
579 
581 
584  template<class ... Args>
585  iterator emplaceBack(Args && ... args) {
586  ListElement<E> *pX = new ListElement<E>(this, nullptr, m_tail, std::forward<Args>(args)...);
587  if (m_head)
588  m_tail = m_tail->m_next = pX;
589  else
590  m_tail = m_head = pX;
591  return m_tail;
592  }
593 
595 
603  OGDF_ASSERT(it.listOf() == this);
604  ListElement<E> *pY = it, *pX;
605  if (dir == Direction::after) {
606  ListElement<E> *pYnext = pY->m_next;
607  pY->m_next = pX = new ListElement<E>(this, x, pYnext, pY);
608  if (pYnext) pYnext->m_prev = pX;
609  else m_tail = pX;
610  } else {
611  ListElement<E> *pYprev = pY->m_prev;
612  pY->m_prev = pX = new ListElement<E>(this, x, pY, pYprev);
613  if (pYprev) pYprev->m_next = pX;
614  else m_head = pX;
615  }
616  return pX;
617  }
618 
620 
623  iterator insertBefore(const E &x, iterator it) {
624  OGDF_ASSERT(it.listOf() == this);
625  ListElement<E> *pY = it, *pX;
626  ListElement<E> *pYprev = pY->m_prev;
627  pY->m_prev = pX = new ListElement<E>(this, x, pY, pYprev);
628  if (pYprev) pYprev->m_next = pX;
629  else m_head = pX;
630  return pX;
631  }
632 
634 
637  iterator insertAfter(const E &x, iterator it) {
638  OGDF_ASSERT(it.listOf() == this);
639  ListElement<E> *pY = it, *pX;
640  ListElement<E> *pYnext = pY->m_next;
641  pY->m_next = pX = new ListElement<E>(this, x, pYnext, pY);
642  if (pYnext) pYnext->m_prev = pX;
643  else m_tail = pX;
644  return pX;
645  }
646 
648 
653 
655 
658  void popFront() {
659  OGDF_ASSERT(m_head != nullptr);
660  ListElement<E> *pX = m_head;
661  m_head = m_head->m_next;
662  delete pX;
663  if (m_head) m_head->m_prev = nullptr;
664  else m_tail = nullptr;
665  }
666 
668 
672  E el = front();
673  popFront();
674  return el;
675  }
676 
678 
681  void popBack() {
682  OGDF_ASSERT(m_tail != nullptr);
683  ListElement<E> *pX = m_tail;
684  m_tail = m_tail->m_prev;
685  delete pX;
686  if (m_tail) m_tail->m_next = nullptr;
687  else m_head = nullptr;
688  }
689 
691 
695  E el = back();
696  popBack();
697  return el;
698  }
699 
701 
704  void del(iterator it) {
705  OGDF_ASSERT(it.listOf() == this);
706  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
707  delete pX;
708  if (pPrev) pPrev->m_next = pNext;
709  else m_head = pNext;
710  if (pNext) pNext->m_prev = pPrev;
711  else m_tail = pPrev;
712  }
713 
715 
721  bool removeFirst(const E &x) {
722  for(ListElement<E> *pX = m_head; pX != nullptr; pX = pX->m_next)
723  if(pX->m_x == x) {
724  del(pX); return true;
725  }
726  return false;
727  }
728 
730  void clear() {
731  if (m_head == nullptr) return;
732 
733  if (!std::is_trivially_destructible<E>::value) {
734  for(ListElement<E> *pX = m_head; pX != nullptr; pX = pX->m_next)
735  pX->m_x.~E();
736  }
737  OGDF_ALLOCATOR::deallocateList(sizeof(ListElement<E>),m_head,m_tail);
738 
739  m_head = m_tail = nullptr;
740  }
741 
743 
748 
750 
753  void exchange(iterator it1, iterator it2) {
754  OGDF_ASSERT(it1.valid());
755  OGDF_ASSERT(it2.valid());
756  OGDF_ASSERT(it1 != it2);
757  ListElement<E> *pX = it1, *pY = it2;
758 
759  std::swap(pX->m_next,pY->m_next);
760  std::swap(pX->m_prev,pY->m_prev);
761 #ifdef OGDF_DEBUG
762  std::swap(pX->m_list,pY->m_list);
763 #endif
764 
765  if(pX->m_next == pX) {
766  pX->m_next = pY; pY->m_prev = pX;
767  }
768  if(pX->m_prev == pX) {
769  pX->m_prev = pY; pY->m_next = pX;
770  }
771 
772  if(pX->m_prev) pX->m_prev->m_next = pX;
773  else m_head = pX;
774 
775  if(pY->m_prev) pY->m_prev->m_next = pY;
776  else m_head = pY;
777 
778  if(pX->m_next) pX->m_next->m_prev = pX;
779  else m_tail = pX;
780 
781  if(pY->m_next) pY->m_next->m_prev = pY;
782  else m_tail = pY;
783  }
784 
786 
790  OGDF_ASSERT(it.listOf() == this);
791  // remove it
792  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
793  //already at front
794  if (!pPrev) return;
795 
796  //update old position
797  if (pPrev) pPrev->m_next = pNext;
798  if (pNext) pNext->m_prev = pPrev;
799  else m_tail = pPrev;
800  // insert it at front
801  pX->m_prev = nullptr;
802  pX->m_next = m_head;
803  m_head = m_head->m_prev = pX;
804  }
805 
807 
810  void moveToBack(iterator it) {
811  OGDF_ASSERT(it.listOf() == this);
812  // remove it
813  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
814  //already at back
815  if (!pNext) return;
816 
817  //update old position
818  if (pPrev) pPrev->m_next = pNext;
819  else m_head = pNext;
820  if (pNext) pNext->m_prev = pPrev;
821  // insert it at back
822  pX->m_prev = m_tail;
823  pX->m_next = nullptr;
824  m_tail = m_tail->m_next = pX;
825  }
826 
828 
831  void moveToSucc(iterator it, iterator itBefore) {
832  OGDF_ASSERT(it.listOf() == this);
833  OGDF_ASSERT(itBefore.listOf() == this);
834  // move it
835  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
836  //the same of already in place
837  ListElement<E> *pY = itBefore;
838  if(pX == pY || pPrev == pY) return;
839 
840  // update old position
841  if (pPrev) pPrev->m_next = pNext;
842  else m_head = pNext;
843  if (pNext) pNext->m_prev = pPrev;
844  else m_tail = pPrev;
845  // move it after itBefore
846  ListElement<E> *pYnext = pX->m_next = pY->m_next;
847  (pX->m_prev = pY)->m_next = pX;
848  if (pYnext) pYnext->m_prev = pX;
849  else m_tail = pX;
850  }
851 
853 
856  void moveToPrec(iterator it, iterator itAfter) {
857  OGDF_ASSERT(it.listOf() == this);
858  OGDF_ASSERT(itAfter.listOf() == this);
859  // move it
860  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
861  //the same of already in place
862  ListElement<E> *pY = itAfter;
863  if(pX == pY || pNext == pY) return;
864 
865  // update old position
866  if (pPrev) pPrev->m_next = pNext;
867  else m_head = pNext;
868  if (pNext) pNext->m_prev = pPrev;
869  else m_tail = pPrev;
870  // move it before itAfter
871  ListElement<E> *pYprev = pX->m_prev = pY->m_prev;
872  (pX->m_next = pY)->m_prev = pX;
873  if (pYprev) pYprev->m_next = pX;
874  else m_head = pX;
875  }
876 
878 
882  OGDF_ASSERT(it.listOf() == this);
883  OGDF_ASSERT(this != &L2);
884  // remove it
885  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
886  if (pPrev) pPrev->m_next = pNext;
887  else m_head = pNext;
888  if (pNext) pNext->m_prev = pPrev;
889  else m_tail = pPrev;
890  // insert it at front of L2
891  pX->m_prev = nullptr;
892  if ((pX->m_next = L2.m_head) != nullptr)
893  L2.m_head = L2.m_head->m_prev = pX;
894  else
895  L2.m_head = L2.m_tail = pX;
896 
897 #ifdef OGDF_DEBUG
898  pX->m_list = &L2;
899 #endif
900  }
901 
903 
907  OGDF_ASSERT(it.listOf() == this);
908  OGDF_ASSERT(this != &L2);
909  // remove it
910  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
911  if (pPrev) pPrev->m_next = pNext;
912  else m_head = pNext;
913  if (pNext) pNext->m_prev = pPrev;
914  else m_tail = pPrev;
915  // insert it at back of L2
916  pX->m_next = nullptr;
917  if ((pX->m_prev = L2.m_tail) != nullptr)
918  L2.m_tail = L2.m_tail->m_next = pX;
919  else
920  L2.m_head = L2.m_tail = pX;
921 
922 #ifdef OGDF_DEBUG
923  pX->m_list = this;
924 #endif
925  }
926 
928 
932  void moveToSucc(iterator it, ListPure<E> &L2, iterator itBefore) {
933  OGDF_ASSERT(it.listOf() == this);
934  OGDF_ASSERT(itBefore.listOf() == &L2);
935  OGDF_ASSERT(this != &L2);
936  // remove it
937  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
938  if (pPrev) pPrev->m_next = pNext;
939  else m_head = pNext;
940  if (pNext) pNext->m_prev = pPrev;
941  else m_tail = pPrev;
942  // insert it in list L2 after itBefore
943  ListElement<E> *pY = itBefore;
944  ListElement<E> *pYnext = pX->m_next = pY->m_next;
945  (pX->m_prev = pY)->m_next = pX;
946  if (pYnext) pYnext->m_prev = pX;
947  else L2.m_tail = pX;
948 
949 #ifdef OGDF_DEBUG
950  pX->m_list = &L2;
951 #endif
952  }
953 
955 
959  void moveToPrec(iterator it, ListPure<E> &L2, iterator itAfter) {
960  OGDF_ASSERT(it.listOf() == this);
961  OGDF_ASSERT(itAfter.listOf() == &L2);
962  OGDF_ASSERT(this != &L2);
963  // remove it
964  ListElement<E> *pX = it, *pPrev = pX->m_prev, *pNext = pX->m_next;
965  if (pPrev) pPrev->m_next = pNext;
966  else m_head = pNext;
967  if (pNext) pNext->m_prev = pPrev;
968  else m_tail = pPrev;
969  // insert it in list L2 after itBefore
970  ListElement<E> *pY = itAfter;
971  ListElement<E> *pYprev = pX->m_prev = pY->m_prev;
972  (pX->m_next = pY)->m_prev = pX;
973  if (pYprev) pYprev->m_next = pX;
974  else L2.m_head = pX;
975 
976 #ifdef OGDF_DEBUG
977  pX->m_list = &L2;
978 #endif
979  }
980 
982  void conc(ListPure<E> &L2) {
983  OGDF_ASSERT(this != &L2);
984  if (m_head)
985  m_tail->m_next = L2.m_head;
986  else
987  m_head = L2.m_head;
988  if (L2.m_head) {
989  L2.m_head->m_prev = m_tail;
990  m_tail = L2.m_tail;
991  }
992 
993  reassignListRefs(L2.m_head);
994 
995  L2.m_head = L2.m_tail = nullptr;
996  }
997 
999  void concFront(ListPure<E> &L2) {
1000  OGDF_ASSERT(this != &L2);
1001  if (m_head)
1002  m_head->m_prev = L2.m_tail;
1003  else
1004  m_tail = L2.m_tail;
1005  if (L2.m_head) {
1006  L2.m_tail->m_next = m_head;
1007  m_head = L2.m_head;
1008  }
1009 
1010  reassignListRefs(L2.m_head);
1011 
1012  L2.m_head = L2.m_tail = nullptr;
1013  }
1014 
1016  void swap(ListPure<E> &other) {
1017  std::swap(m_head, other.m_head);
1018  std::swap(m_tail, other.m_tail);
1019 
1020  reassignListRefs();
1021  other.reassignListRefs();
1022  }
1023 
1025 
1035  OGDF_ASSERT(!it.valid() || it.listOf() == this);
1036  if (&L1 != this) L1.clear();
1037  if (&L2 != this) L2.clear();
1038 
1039  if (it.valid()){
1040  L1.m_head = m_head;
1041  L2.m_tail = m_tail;
1042  if (dir == Direction::before){
1043  L2.m_head = it;
1044  L1.m_tail = L2.m_head->m_prev;
1045  }
1046  else {
1047  L1.m_tail = it;
1048  L2.m_head = L1.m_tail->m_next;
1049  }
1050  L2.m_head->m_prev = L1.m_tail->m_next = nullptr;
1051 
1052  } else {
1053  L1.m_head = L1.m_tail = nullptr;
1054  L2.m_head = m_head;
1055  L2.m_tail = m_tail;
1056  }
1057 
1058  if (this != &L1 && this != &L2) {
1059  m_head = m_tail = nullptr;
1060  }
1061 
1062  L1.reassignListRefs();
1063  L2.reassignListRefs();
1064  }
1065 
1068  OGDF_ASSERT(it.listOf() == this);
1069  OGDF_ASSERT(this != &L2);
1070  L2.clear();
1071  ListElement<E> *pX = it;
1072  if (pX != m_tail) {
1073  (L2.m_head = pX->m_next)->m_prev = nullptr;
1074  pX->m_next = nullptr;
1075  L2.m_tail = m_tail;
1076  m_tail = pX;
1077  }
1078 
1079  L2.reassignListRefs();
1080  }
1081 
1084  OGDF_ASSERT(it.listOf() == this);
1085  OGDF_ASSERT(this != &L2);
1086  L2.clear();
1087  ListElement<E> *pX = it;
1088  L2.m_head = pX; L2.m_tail = m_tail;
1089  if ((m_tail = pX->m_prev) == nullptr)
1090  m_head = nullptr;
1091  else
1092  m_tail->m_next = nullptr;
1093  pX->m_prev = nullptr;
1094 
1095  L2.reassignListRefs();
1096  }
1097 
1099  void reverse() {
1100  ListElement<E> *pX = m_head;
1101  m_head = m_tail;
1102  m_tail = pX;
1103  while(pX) {
1104  ListElement<E> *pY = pX->m_next;
1105  pX->m_next = pX->m_prev;
1106  pX = pX->m_prev = pY;
1107  }
1108  }
1109 
1111 
1116 
1118  ListConstIterator<E> search(const E& e) const {
1120  for (i = begin(); i.valid(); ++i)
1121  if (*i == e) return i;
1122  return i;
1123  }
1124 
1126  ListIterator<E> search(const E& e) {
1127  ListIterator<E> i;
1128  for (i = begin(); i.valid(); ++i)
1129  if (*i == e) return i;
1130  return i;
1131  }
1132 
1134  template<class COMPARER>
1135  ListConstIterator<E> search(const E &e, const COMPARER &comp) const {
1137  for (i = begin(); i.valid(); ++i)
1138  if (comp.equal(*i, e)) return i;
1139  return i;
1140  }
1141 
1143  template<class COMPARER>
1144  ListIterator<E> search(const E &e, const COMPARER &comp) {
1145  ListIterator<E> i;
1146  for (i = begin(); i.valid(); ++i)
1147  if (comp.equal(*i, e)) return i;
1148  return i;
1149  }
1150 
1152  void quicksort() {
1153  ogdf::quicksortTemplate(*this);
1154  }
1155 
1157  template<class COMPARER>
1158  void quicksort(const COMPARER &comp) {
1159  ogdf::quicksortTemplate(*this,comp);
1160  }
1161 
1163 
1170  void bucketSort(int l, int h, BucketFunc<E> &f);
1171 
1173 
1178 
1188  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1189  bool isFastTest = true) const {
1190  return chooseIteratorFrom(*this, includeElement, isFastTest);
1191  }
1192 
1195  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1196  bool isFastTest = true) {
1197  return chooseIteratorFrom(*this, includeElement, isFastTest);
1198  }
1199 
1209  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1210  bool isFastTest = true) const {
1211  const_iterator result = chooseIterator(includeElement, isFastTest);
1212  OGDF_ASSERT(result.valid());
1213  return *result;
1214  }
1215 
1218  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
1219  bool isFastTest = true) {
1220  iterator result = chooseIterator(includeElement, isFastTest);
1221  OGDF_ASSERT(result.valid());
1222  return *result;
1223  }
1224 
1226  void permute() {
1227  std::minstd_rand rng(randomSeed());
1228  permute(size(), rng);
1229  }
1230 
1232  template<class RNG>
1233  void permute(RNG &rng) {
1234  permute(size(), rng);
1235  }
1236 
1238 
1239 protected:
1240  void copy(const ListPure<E> &L) {
1241  for(ListElement<E> *pX = L.m_head; pX != nullptr; pX = pX->m_next)
1242  pushBack(pX->m_x);
1243  }
1244 
1245  template<class RNG>
1246 
1248  void permute(const int n, RNG &rng);
1249 
1251  inline void reassignListRefs(ListElement<E> *start = nullptr) {
1252 #ifdef OGDF_DEBUG
1253  for(auto e = start == nullptr ? m_head : start; e != nullptr; e = e->m_next) {
1254  e->m_list = this;
1255  }
1256 #endif
1257  }
1258 
1260 };
1261 
1263 
1272 template<class E>
1273 class List : private ListPure<E> {
1274  int m_count;
1275 
1276 public:
1277  using typename ListPure<E>::value_type;
1278  using typename ListPure<E>::reference;
1279  using typename ListPure<E>::const_reference;
1280  using typename ListPure<E>::const_iterator;
1281  using typename ListPure<E>::iterator;
1282  using typename ListPure<E>::const_reverse_iterator;
1283  using typename ListPure<E>::reverse_iterator;
1284 
1286  List() : m_count(0) { }
1287 
1289  List(std::initializer_list<E> init) : ListPure<E>(init), m_count((int)init.size()) { }
1290 
1292  List(const List<E> &L) : ListPure<E>(L), m_count(L.m_count) { }
1293 
1295 
1298  List(List<E> &&L) : ListPure<E>(std::move(L)), m_count(L.m_count) {
1299  L.m_count = 0;
1300  }
1301 
1307 
1309 
1312  int size() const { return m_count; }
1313 
1315  const ListPure<E> &getListPure() const { return *this; }
1316 
1318 
1323 
1327  m_count = L.m_count;
1328  return *this;
1329  }
1330 
1332 
1336  m_count = L.m_count;
1338  L.m_count = 0;
1339  return *this;
1340  }
1341 
1343  bool operator==(const List<E> &L) const {
1344  return (m_count == L.m_count) && ListPure<E>::operator==(L);
1345  }
1346 
1348  bool operator!=(const List<E> &L) const {
1349  return !operator==(L);
1350  }
1351 
1353 
1358 
1360  iterator pushFront(const E &x) {
1361  ++m_count;
1362  return ListPure<E>::pushFront(x);
1363  }
1364 
1366  template<class ... Args>
1367  iterator emplaceFront(Args && ... args) {
1368  ++m_count;
1369  return ListPure<E>::emplaceFront(std::forward<Args>(args)...);
1370  }
1371 
1373  iterator pushBack(const E &x) {
1374  ++m_count;
1375  return ListPure<E>::pushBack(x);
1376  }
1377 
1379  template<class ... Args>
1380  iterator emplaceBack(Args && ... args) {
1381  ++m_count;
1382  return ListPure<E>::emplaceBack(std::forward<Args>(args)...);
1383  }
1384 
1387  ++m_count;
1388  return ListPure<E>::insert(x,it,dir);
1389  }
1390 
1392  iterator insertBefore(const E &x, iterator it) {
1393  ++m_count;
1394  return ListPure<E>::insertBefore(x,it);
1395  }
1396 
1398  iterator insertAfter(const E &x, iterator it) {
1399  ++m_count;
1400  return ListPure<E>::insertAfter(x,it);
1401  }
1402 
1404 
1409 
1411  void popFront() {
1412  --m_count;
1414  }
1415 
1418  E el = front();
1419  popFront();
1420  return el;
1421  }
1422 
1424  void popBack() {
1425  --m_count;
1427  }
1428 
1431  E el = back();
1432  popBack();
1433  return el;
1434  }
1435 
1437  void del(iterator it) {
1438  --m_count;
1439  ListPure<E>::del(it);
1440  }
1441 
1443  bool removeFirst(const E &x) {
1444  bool hasRemoved = ListPure<E>::removeFirst(x);
1445  if(hasRemoved)
1446  --m_count;
1447  return hasRemoved;
1448  }
1449 
1451  void clear() {
1452  m_count = 0;
1454  }
1455 
1457 
1462 
1464  void moveToFront(iterator it, List<E> &L2) {
1465  ListPure<E>::moveToFront(it,L2);
1466  --m_count; ++L2.m_count;
1467  }
1468 
1470  void moveToBack(iterator it, List<E> &L2) {
1471  ListPure<E>::moveToBack(it,L2);
1472  --m_count; ++L2.m_count;
1473  }
1474 
1476  void moveToSucc(iterator it, List<E> &L2, iterator itBefore) {
1477  ListPure<E>::moveToSucc(it,L2,itBefore);
1478  --m_count; ++L2.m_count;
1479  }
1480 
1482  void moveToPrec(iterator it, List<E> &L2, iterator itAfter) {
1483  ListPure<E>::moveToPrec(it,L2,itAfter);
1484  --m_count; ++L2.m_count;
1485  }
1486 
1488  void conc(List<E> &L2) {
1489  ListPure<E>::conc(L2);
1490  m_count += L2.m_count;
1491  L2.m_count = 0;
1492  }
1493 
1495  void concFront(List<E> &L2) {
1497  m_count += L2.m_count;
1498  L2.m_count = 0;
1499  }
1500 
1502  void swap(List<E> &other) {
1503  ListPure<E>::swap(other);
1504  std::swap(m_count, other.m_count);
1505  }
1506 
1509  ListPure<E>::split(it,L1,L2,dir);
1510  int countL = m_count, countL1 = 0;
1511  for(ListElement<E> *pX = L1.m_head; pX != nullptr; pX = pX->m_next)
1512  ++countL1;
1513 
1514  L1.m_count = countL1;
1515  L2.m_count = countL - countL1;
1516  if (this->m_head == nullptr) m_count = 0;
1517  }
1518 
1519  using ListPure<E>::empty;
1520  using ListPure<E>::front;
1521  using ListPure<E>::back;
1522  using ListPure<E>::get;
1523  using ListPure<E>::pos;
1524  using ListPure<E>::begin;
1525  using ListPure<E>::cbegin;
1526  using ListPure<E>::end;
1527  using ListPure<E>::cend;
1528  using ListPure<E>::rbegin;
1529  using ListPure<E>::crbegin;
1530  using ListPure<E>::rend;
1531  using ListPure<E>::crend;
1534  using ListPure<E>::exchange;
1539  using ListPure<E>::reverse;
1540  using ListPure<E>::search;
1541  using ListPure<E>::quicksort;
1545  using ListPure<E>::permute;
1546 
1548 };
1549 
1550 template<class E>
1552 {
1553  if (m_head == m_tail) return;
1554 
1555  Array<ListElement<E> *> head(l,h,nullptr), tail(l,h);
1556 
1557  ListElement<E> *pX;
1558  for (pX = m_head; pX; pX = pX->m_next) {
1559  int i = f.getBucket(pX->m_x);
1560  if (head[i])
1561  tail[i] = ((pX->m_prev = tail[i])->m_next = pX);
1562  else
1563  head[i] = tail[i] = pX;
1564  }
1565 
1566  ListElement<E> *pY = nullptr;
1567  for (int i = l; i <= h; i++) {
1568  pX = head[i];
1569  if (pX) {
1570  if (pY) {
1571  (pY->m_next = pX)->m_prev = pY;
1572  } else
1573  (m_head = pX)->m_prev = nullptr;
1574  pY = tail[i];
1575  }
1576  }
1577 
1578  m_tail = pY;
1579  pY->m_next = nullptr;
1580 }
1581 
1582 template<class E>
1583 template<class RNG>
1584 void ListPure<E>::permute(const int n, RNG &rng)
1585 {
1586  //if n==0 do nothing
1587  if (n == 0) { return; }
1588 
1589  Array<ListElement<E> *> A(n+2);
1590  A[0] = A[n+1] = nullptr;
1591 
1592  int i = 1;
1593  ListElement<E> *pX;
1594  for (pX = m_head; pX; pX = pX->m_next)
1595  A[i++] = pX;
1596 
1597  A.permute(1,n,rng);
1598 
1599  for (i = 1; i <= n; i++) {
1600  pX = A[i];
1601  pX->m_next = A[i+1];
1602  pX->m_prev = A[i-1];
1603  }
1604 
1605  m_head = A[1];
1606  m_tail = A[n];
1607 }
1608 
1610 template<class E>
1611 void print(std::ostream &os, const ListPure<E> &L, char delim = ' ')
1612 {
1613  typename ListPure<E>::const_iterator pX = L.begin();
1614  if (pX.valid()) {
1615  os << *pX;
1616  for(++pX; pX.valid(); ++pX)
1617  os << delim << *pX;
1618  }
1619 }
1620 
1622 template<class E>
1623 void print(std::ostream &os, const List<E> &L, char delim = ' ')
1624 {
1625  print(os, L.getListPure(), delim);
1626 }
1627 
1629 template<class E>
1630 std::ostream &operator<<(std::ostream &os, const ListPure<E> &L)
1631 {
1632  print(os,L);
1633  return os;
1634 }
1635 
1637 template<class E>
1638 std::ostream &operator<<(std::ostream &os, const List<E> &L)
1639 {
1640  return os << L.getListPure();
1641 }
1642 
1643 template<class E, class Master>
1644 class ListContainer : public List<E> {
1645  friend Master;
1646 
1647 public:
1652 
1654  iterator begin() const { return List<E>::cbegin(); }
1655 
1657  iterator end() const { return List<E>::cend(); }
1658 
1661 
1663  reverse_iterator rend() const { return List<E>::crend(); }
1664 
1666  int size() const { return List<E>::size(); }
1667 };
1668 
1669 }
void concFront(ListPure< E > &L2)
Prepends L2 to this list and makes L2 empty.
Definition: List.h:999
void clear()
Removes all elements from the list.
Definition: List.h:1451
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: List.h:382
reverse_iterator rend() const
Returns a reverse iterator to the one-before-first element in the container.
Definition: List.h:1663
E & reference
Provides a reference to an element stored in a list.
Definition: List.h:211
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:1135
ListElement< E > * m_tail
Pointer to last element.
Definition: List.h:205
void moveToBack(iterator it)
Moves it to the end of the list.
Definition: List.h:810
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:547
ListIteratorBase< E, isConst, isReverse > operator++(int)
Increment operator (postfix).
Definition: List.h:170
ListPure(ListPure< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
Definition: List.h:241
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
ListElement< E > * m_prev
Pointer to predecessor element.
Definition: List.h:59
typename std::conditional< isConst, const ogdf::ClusterGraphObserver *, ogdf::ClusterGraphObserver * >::type Elem
The underlying type, depending on isConst.
Definition: List.h:100
bool operator==(const ListPure< E > &L) const
Equality operator.
Definition: List.h:523
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:145
void quicksortTemplate(LIST &L)
ListIteratorBase< E, isConst, isReverse > operator--(int)
Decrement operator (postfix).
Definition: List.h:183
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1373
void moveToPrec(iterator it, List< E > &L2, iterator itAfter)
Moves it before itAfter.
Definition: List.h:1482
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
Definition: List.h:434
Elem & operator*() const
Returns a reference to the element content.
Definition: List.h:155
void conc(List< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition: List.h:1488
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition: List.h:721
void splitAfter(iterator it, ListPure< E > &L2)
Splits the list after it.
Definition: List.h:1067
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:571
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: List.h:1380
void popFront()
Removes the first element from the list.
Definition: List.h:1411
Doubly linked lists.
Definition: List.h:41
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations...
Definition: List.h:213
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:1034
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:352
iterator begin() const
Returns an iterator to the first element in the container.
Definition: List.h:1654
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:1508
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:1398
ListIteratorBase< E, isConst, isReverse > & operator=(const ListIteratorBase< E, isConst, isReverse > &it)
Assignment operator.
Definition: List.h:158
List< E > & operator=(List< E > &&L)
Assignment operator (move semantics).
Definition: List.h:1335
const_iterator cyclicSucc(const_iterator it) const
Returns a const iterator to the cyclic successor of it.
Definition: List.h:424
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1430
void moveToFront(iterator it)
Moves it to the begin of the list.
Definition: List.h:789
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:1194
void moveToSucc(iterator it, List< E > &L2, iterator itBefore)
Moves it after itBefore.
Definition: List.h:1476
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: GML.h:110
void conc(ListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition: List.h:982
void moveToSucc(iterator it, ListPure< E > &L2, iterator itBefore)
Moves it to list L2 and inserts it after itBefore.
Definition: List.h:932
bool operator!=(const ListIteratorBase< E, isConst, isReverse > &it) const
Inequality operator.
Definition: List.h:140
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Definition: List.h:462
const_reverse_iterator crbegin() const
Returns a const iterator to the last element of the list.
Definition: List.h:400
virtual int size() const
Returns the number of elements in the list.
Definition: List.h:263
ListIteratorBase< E, isConst, isReverse > & operator--()
Decrement operator (prefix).
Definition: List.h:177
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:1126
void init()
Definition: graphics.h:472
ListElement(ListPure< E > *list, const E &x)
Constructs a ListElement.
Definition: List.h:73
bool operator==(const List< E > &L) const
Equality operator.
Definition: List.h:1343
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition: Array.h:503
iterator cyclicPred(iterator it)
Returns an iterator to the cyclic predecessor of it.
Definition: List.h:472
void del(iterator it)
Removes it from the list.
Definition: List.h:704
void popBack()
Removes the last element from the list.
Definition: List.h:1424
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
Definition: List.h:1660
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
Definition: List.h:1551
List(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
Definition: List.h:1289
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:124
void del(iterator it)
Removes it from the list.
Definition: List.h:1437
ListPure(std::initializer_list< E > init)
Constructs a doubly linked list containing the elements in init.
Definition: List.h:227
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns a random element.
Definition: List.h:1208
ListIteratorBase(const ListIteratorBase< E, isConst, isReverse > &it)
Copy constructor.
Definition: List.h:121
void moveToBack(iterator it, List< E > &L2)
Moves it to the end of the list.
Definition: List.h:1470
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
reference front()
Returns a reference to the first element.
Definition: List.h:283
Implementation of the Reverse class for the reverse iteration of containers.
ListElement< E > * m_next
Pointer to successor element.
Definition: List.h:58
const_reverse_iterator rend() const
Returns a const iterator to one-before-first element of the list.
Definition: List.h:412
void reverse()
Reverses the order of the list elements.
Definition: List.h:1099
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
Definition: List.h:1158
void quicksort()
Sorts the list using Quicksort.
Definition: List.h:1152
const ListPure< E > & getListPure() const
Conversion to const ListPure.
Definition: List.h:1315
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns a random element.
Definition: List.h:1217
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:1144
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1360
ListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
Definition: List.h:110
bool operator!=(const ListPure< E > &L) const
Inequality operator.
Definition: List.h:535
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: List.h:585
reference back()
Returns a reference to the last element.
Definition: List.h:301
static void copy(const T &from, T &to)
Definition: Alg.h:61
const_reference front() const
Returns a const reference to the first element.
Definition: List.h:274
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition: List.h:561
iterator end() const
Returns an iterator to the one-past-last element in the container.
Definition: List.h:1657
void swap(List< E > &other)
Exchanges the contents of this list and other in constant time.
Definition: List.h:1502
void moveToPrec(iterator it, iterator itAfter)
Moves it before itAfter.
Definition: List.h:856
List(List< E > &&L)
Constructs a doubly linked list containing the elements of L (move semantics).
Definition: List.h:1298
void swap(ListPure< E > &other)
Exchanges the contents of this list and other in constant time.
Definition: List.h:1016
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
Definition: List.h:150
ListElement(ListPure< E > *list, const E &x, ListElement< E > *next, ListElement< E > *prev)
Constructs a ListElement.
Definition: List.h:66
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:694
E m_x
Stores the content.
Definition: List.h:60
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
ListPure(const ListPure< E > &L)
Constructs a doubly linked list that is a copy of L.
Definition: List.h:233
Structure for elements of doubly linked lists.
Definition: List.h:50
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: List.h:370
void clear()
Removes all elements from the list.
Definition: List.h:730
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: List.h:364
Direction
Definition: basic.h:126
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:1417
void moveToBack(iterator it, ListPure< E > &L2)
Moves it to the end of L2.
Definition: List.h:906
void exchange(iterator it1, iterator it2)
Exchanges the positions of it1 and it2 in the list.
Definition: List.h:753
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:671
const_iterator begin() const
Returns a const iterator to the first element of the list.
Definition: List.h:358
Encapsulates a pointer to a list element.
Definition: List.h:42
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
const_reverse_iterator crend() const
Returns a const iterator to one-before-first element of the list.
Definition: List.h:418
const T & move(const T &v)
Definition: backward.hpp:243
void reassignListRefs(ListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
Definition: List.h:1251
Implementation of algorithms as templates working with different list types.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Definition: List.h:1386
Abstract base class for bucket functions.
Definition: basic.h:226
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Definition: List.h:602
void bucketSort(Array< E > &a, int min, int max, BucketFunc< E > &f)
Bucket-sort array a using bucket assignment f; the values of f must be in the interval [min...
Definition: SList.h:1092
void moveToFront(iterator it, List< E > &L2)
Moves it to the begin of the list.
Definition: List.h:1464
const_reverse_iterator cyclicSucc(const_reverse_iterator it) const
Returns a const iterator to the cyclic successor of it.
Definition: List.h:443
ListElem * m_pX
pointer to list element
Definition: List.h:103
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition: List.h:623
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
Definition: List.h:388
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
Definition: List.h:332
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition: List.h:1443
void moveToFront(iterator it, ListPure< E > &L2)
Moves it to the begin of L2.
Definition: List.h:881
void moveToSucc(iterator it, iterator itBefore)
Moves it after itBefore.
Definition: List.h:831
reverse_iterator rend()
Returns an iterator to one-before-first element of the list.
Definition: List.h:406
int size() const
Returns the number of elements in the list.
Definition: List.h:1312
reverse_iterator cyclicPred(reverse_iterator it)
Returns a const iterator to the cyclic predecessor of it.
Definition: List.h:490
void splitBefore(iterator it, ListPure< E > &L2)
Splits the list before it.
Definition: List.h:1083
E value_type
Represents the data type stored in a list element.
Definition: List.h:209
int m_count
The length of the list.
Definition: List.h:1274
List(const List< E > &L)
Constructs a doubly linked list that is a copy of L.
Definition: List.h:1292
void popFront()
Removes the first element from the list.
Definition: List.h:658
virtual int getBucket(const E &x)=0
Returns the bucket of x.
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition: List.h:1367
virtual ~ListPure()
Destructor.
Definition: List.h:246
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition: List.h:1392
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:1187
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
Definition: List.h:376
void popBack()
Removes the last element from the list.
Definition: List.h:681
const_reverse_iterator rbegin() const
Returns a const iterator to the last element of the list.
Definition: List.h:394
void concFront(List< E > &L2)
Prepends L2 to this list and makes L2 empty.
Definition: List.h:1495
List()
Constructs an empty doubly linked list.
Definition: List.h:1286
The namespace for all OGDF objects.
ListIteratorBase()
Constructs an invalid iterator.
Definition: List.h:113
ListPure()
Constructs an empty doubly linked list.
Definition: List.h:224
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
Definition: List.h:1233
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:931
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:637
void copy(const ListPure< E > &L)
Definition: List.h:1240
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition: List.h:1325
bool operator!=(const List< E > &L) const
Inequality operator.
Definition: List.h:1348
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:76
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:1118
ListPure< E > & operator=(ListPure< E > &&L)
Assignment operator (move semantics).
Definition: List.h:513
const_reverse_iterator cyclicPred(const_reverse_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Definition: List.h:481
reverse_iterator cyclicSucc(reverse_iterator it)
Returns a const iterator to the cyclic successor of it.
Definition: List.h:452
ListElement< E > * m_head
Pointer to first element.
Definition: List.h:204
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition: tuples.h:76
bool empty() const
Returns true iff the list is empty.
Definition: List.h:256
int size() const
Returns the number of elements in the container.
Definition: List.h:1666
ListIteratorBase(const ListIteratorBase< E, isArgConst, isArgReverse > &it)
Constructs an iterator that is a copy of it.
Definition: List.h:117
void moveToPrec(iterator it, ListPure< E > &L2, iterator itAfter)
Moves it to list L2 and inserts it before itAfter.
Definition: List.h:959
void permute()
Randomly permutes the elements in the list.
Definition: List.h:1226
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
ListIteratorBase< E, isConst, isReverse > & operator++()
Increment operator (prefix).
Definition: List.h:164
ListPure< E > & operator=(const ListPure< E > &L)
Assignment operator.
Definition: List.h:504
const_reference back() const
Returns a const reference to the last element.
Definition: List.h:292