Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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