Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

SList.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 
36 namespace ogdf {
37 
38 template<class E> class SListPure;
39 template<class E> class StackPure;
40 template<class E, bool isConst> class SListIteratorBase;
42 template<class E> using SListIterator = SListIteratorBase<E, false>;
43 
45 template<class E>
46 class SListElement {
47  friend class SListPure<E>;
48  friend class StackPure<E>;
49  friend class SListIteratorBase<E, true>;
50  friend class SListIteratorBase<E, false>;
51 
53  E m_x;
54 #ifdef OGDF_DEBUG
55  SListPure<E> *m_list;
56 #endif
57 
59  SListElement(SListPure<E> *list, const E &x, SListElement<E> *next)
60  : m_next(next), m_x(x) {
61 #ifdef OGDF_DEBUG
62  m_list = list;
63 #endif
64  }
66  SListElement(SListPure<E> *list, const E &x) : SListElement(list, x, nullptr) { }
68  SListElement() : SListElement(nullptr, E()) { }
70  template<class ... Args>
71  SListElement(SListPure<E> *list, SListElement<E> *next, Args && ... args)
72  : SListElement(list, E(std::forward<Args>(args)...), next) { }
73 
75 };
76 
78 
87 template<class E, bool isConst> class SListIteratorBase {
88  friend class SListIteratorBase<E, !isConst>;
89  friend class SListPure<E>;
90 
92  using ListElem = typename std::conditional<isConst, const SListElement<E>, SListElement<E>>::type;
95 
96  ListElem *m_pX;
97 
99  operator ListElem *() { return m_pX; }
100 
101 public:
103  SListIteratorBase(ListElem *pX) : m_pX(pX) { }
104 
107 
111 
113  bool valid() const { return m_pX != nullptr; }
114 
115 #ifdef OGDF_DEBUG
116  SListPure<E> *listOf() {
119  OGDF_ASSERT(valid());
120  return m_pX->m_list;
121  }
122 #endif
123 
126  return m_pX == it.m_pX;
127  }
128 
131  return m_pX != it.m_pX;
132  }
133 
135  SListIteratorBase<E, isConst> succ() const { return m_pX->m_next; }
136 
138  Elem &operator*() const { return m_pX->m_x; }
139 
142  m_pX = it.m_pX;
143  return *this;
144  }
145 
148  m_pX = m_pX->m_next;
149  return *this;
150  }
151 
155  m_pX = m_pX->m_next;
156  return it;
157  }
158 
160 };
161 
163 
173 template<class E> class SListPure {
176 
177 public:
179  using value_type = E;
181  using reference = E&;
183  using const_reference = const E&;
188 
190  SListPure() : m_head(nullptr), m_tail(nullptr) { }
191 
193  SListPure(std::initializer_list<E> init) : m_head(nullptr), m_tail(nullptr) {
194  for (const E &x : init)
195  pushBack(x);
196  }
198  SListPure(const SListPure<E> &L) : m_head(nullptr), m_tail(nullptr) {
199  copy(L);
200  }
201 
203 
206  SListPure(SListPure<E> &&L) : m_head(L.m_head), m_tail(L.m_tail) {
207  L.m_head = L.m_tail = nullptr;
208  }
209 
211  virtual ~SListPure() { clear(); }
212 
218 
220  bool empty() const { return m_head == nullptr; }
221 
223 
227  virtual int size() const {
228  int count = 0;
229  for (SListElement<E> *pX = m_head; pX != nullptr; pX = pX->m_next)
230  ++count;
231  return count;
232  }
233 
235 
239  OGDF_ASSERT(m_head != nullptr);
240  return m_head->m_x;
241  }
242 
244 
248  OGDF_ASSERT(m_head != nullptr);
249  return m_head->m_x;
250  }
251 
253 
257  OGDF_ASSERT(m_tail != nullptr);
258  return m_tail->m_x;
259  }
260 
262 
266  OGDF_ASSERT(m_tail != nullptr);
267  return m_tail->m_x;
268  }
269 
271 
274  const_iterator get(int pos) const {
275  SListElement<E> *pX;
276  for(pX = m_head; pX != nullptr; pX = pX->m_next)
277  if (pos-- == 0) break;
278  return pX;
279  }
280 
282 
285  iterator get(int pos) {
286  SListElement<E> *pX;
287  for(pX = m_head; pX != nullptr; pX = pX->m_next)
288  if (pos-- == 0) break;
289  return pX;
290  }
291 
293 
297  int pos(const_iterator it) const {
298  OGDF_ASSERT(it.listOf() == this);
299  int p = 0;
300  for(SListElement<E> *pX = m_head; pX != nullptr; pX = pX->m_next, ++p)
301  if (pX == it) break;
302  return p;
303  }
304 
306 
311 
313 
316  iterator begin() { return m_head; }
317 
319 
322  const_iterator begin() const { return m_head; }
323 
325 
328  const_iterator cbegin() const { return m_head; }
329 
331 
334  iterator end() { return SListIterator<E>(); }
335 
337 
341 
343 
347 
349 
352  iterator rbegin() { return m_tail; }
353 
355 
358  const_iterator rbegin() const { return m_tail; }
359 
361 
364  const_iterator crbegin() const { return m_tail; }
365 
367 
371  OGDF_ASSERT(it.listOf() == this);
372  const SListElement<E> *pX = it;
373  return (pX->m_next) ? pX->m_next : m_head;
374  }
375 
377 
381  OGDF_ASSERT(it.listOf() == this);
382  SListElement<E> *pX = it;
383  return (pX->m_next) ? pX->m_next : m_head;
384  }
385 
387 
392 
395  clear(); copy(L);
396  return *this;
397  }
398 
400 
404  clear();
405  m_head = L.m_head;
406  m_tail = L.m_tail;
407  L.m_head = L.m_tail = nullptr;
408  reassignListRefs();
409  return *this;
410  }
411 
413  bool operator==(const SListPure<E> &L) const {
414  SListElement<E> *pX = m_head, *pY = L.m_head;
415  while(pX != nullptr && pY != nullptr) {
416  if(pX->m_x != pY->m_x)
417  return false;
418  pX = pX->m_next;
419  pY = pY->m_next;
420  }
421  return (pX == nullptr && pY == nullptr);
422  }
423 
425  bool operator!=(const SListPure<E> &L) const {
426  return !operator==(L);
427  }
428 
430 
435 
437  iterator pushFront(const E &x) {
438  m_head = new SListElement<E>(this, x, m_head);
439  if (m_tail == nullptr) m_tail = m_head;
440  return m_head;
441  }
442 
444 
447  template<class ... Args>
448  iterator emplaceFront(Args && ... args) {
449  m_head = new SListElement<E>(this, m_head, std::forward<Args>(args)...);
450  if (m_tail == nullptr) m_tail = m_head;
451  return m_head;
452  }
453 
455  iterator pushBack(const E &x) {
456  SListElement<E> *pNew = new SListElement<E>(this, x);
457  if (m_head == nullptr)
458  m_head = m_tail = pNew;
459  else
460  m_tail = m_tail->m_next = pNew;
461  return m_tail;
462  }
463 
465 
468  template<class ... Args>
469  iterator emplaceBack(Args && ... args) {
470  SListElement<E> *pNew = new SListElement<E>(this, nullptr, std::forward<Args>(args)...);
471  if (m_head == nullptr)
472  m_head = m_tail = pNew;
473  else
474  m_tail = m_tail->m_next = pNew;
475  return m_tail;
476  }
477 
479 
482  iterator insertAfter(const E &x, iterator itBefore) {
483  OGDF_ASSERT(itBefore.listOf() == this);
484  SListElement<E> *pBefore = itBefore;
485  SListElement<E> *pNew = new SListElement<E>(this, x, pBefore->m_next);
486  if (pBefore == m_tail) m_tail = pNew;
487  return (pBefore->m_next = pNew);
488  }
489 
491 
496 
498 
501  void popFront() {
502  OGDF_ASSERT(m_head != nullptr);
503  SListElement<E> *pX = m_head;
504  if ((m_head = m_head->m_next) == nullptr) m_tail = nullptr;
505  delete pX;
506  }
507 
509 
513  E el = front();
514  popFront();
515  return el;
516  }
517 
519 
522  void delSucc(iterator itBefore) {
523  OGDF_ASSERT(itBefore.listOf() == this);
524  SListElement<E> *pBefore = itBefore;
525  OGDF_ASSERT(pBefore != nullptr);
526  SListElement<E> *pDel = pBefore->m_next;
527  OGDF_ASSERT(pDel != nullptr);
528  if ((pBefore->m_next = pDel->m_next) == nullptr) m_tail = pBefore;
529  delete pDel;
530  }
531 
533  void clear() {
534  if (m_head == nullptr) return;
535 
536  if (!std::is_trivially_destructible<E>::value) {
537  for(SListElement<E> *pX = m_head; pX != nullptr; pX = pX->m_next)
538  pX->m_x.~E();
539  }
540  OGDF_ALLOCATOR::deallocateList(sizeof(SListElement<E>),m_head,m_tail);
541 
542  m_head = m_tail = nullptr;
543  }
544 
546 
551 
554  OGDF_ASSERT(m_head != nullptr);
555  OGDF_ASSERT(this != &L2);
556 
557  SListElement<E> *pX = m_head;
558  if ((m_head = m_head->m_next) == nullptr) m_tail = nullptr;
559  pX->m_next = L2.m_head;
560  L2.m_head = pX;
561  if (L2.m_tail == nullptr) L2.m_tail = L2.m_head;
562 
563  L2.m_head->m_list = &L2;
564  }
565 
568  OGDF_ASSERT(m_head != nullptr);
569  OGDF_ASSERT(this != &L2);
570 
571  SListElement<E> *pX = m_head;
572  if ((m_head = m_head->m_next) == nullptr) m_tail = nullptr;
573  pX->m_next = nullptr;
574  if (L2.m_head == nullptr)
575  L2.m_head = L2.m_tail = pX;
576  else
577  L2.m_tail = L2.m_tail->m_next = pX;
578 
579  L2.m_tail->m_list = &L2;
580  }
581 
583 
586  void moveFrontToSucc(SListPure<E> &L2, iterator itBefore) {
587  OGDF_ASSERT(m_head != nullptr);
588  OGDF_ASSERT(this != &L2);
589  OGDF_ASSERT(itBefore.listOf() == &L2);
590 
591  SListElement<E> *pBefore = itBefore;
592  SListElement<E> *pX = m_head;
593  if ((m_head = m_head->m_next) == nullptr) m_tail = nullptr;
594  pX->m_next = pBefore->m_next;
595  pBefore->m_next = pX;
596  if (pBefore == L2.m_tail) L2.m_tail = pX;
597 
598  pX->m_list = &L2;
599  }
600 
602  void conc(SListPure<E> &L2) {
603  if (m_head)
604  m_tail->m_next = L2.m_head;
605  else
606  m_head = L2.m_head;
607  if (L2.m_tail != nullptr) m_tail = L2.m_tail;
608 
609  reassignListRefs(L2.m_head);
610 
611  L2.m_head = L2.m_tail = nullptr;
612  }
613 
615  void reverse() {
616  SListElement<E> *p, *pNext, *pPred = nullptr;
617  for(p = m_head; p; p = pNext) {
618  pNext = p->m_next;
619  p->m_next = pPred;
620  pPred = p;
621  }
622  swap(m_head,m_tail);
623  }
624 
626 
631 
633  SListConstIterator<E> search(const E &e) const {
635  for (i = begin(); i.valid(); ++i)
636  if (*i == e) return i;
637  return i;
638  }
639 
641  SListIterator<E> search(const E &e) {
643  for (i = begin(); i.valid(); ++i)
644  if (*i == e) return i;
645  return i;
646  }
647 
649  template<class COMPARER>
650  SListConstIterator<E> search(const E &e, const COMPARER &comp) const {
652  for (i = begin(); i.valid(); ++i)
653  if (comp.equal(*i, e)) return i;
654  return i;
655  }
656 
658  template<class COMPARER>
659  SListIterator<E> search(const E &e, const COMPARER &comp) {
661  for (i = begin(); i.valid(); ++i)
662  if (comp.equal(*i, e)) return i;
663  return i;
664  }
665 
667  void quicksort() {
669  }
670 
672  template<class COMPARER>
673  void quicksort(const COMPARER &comp) {
674  ogdf::quicksortTemplate(*this,comp);
675  }
676 
678 
685  void bucketSort(int l, int h, BucketFunc<E> &f);
686 
688  void bucketSort(BucketFunc<E> &f);
689 
691 
696 
699  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
700  bool isFastTest = true) const {
701  return chooseIteratorFrom(*this, includeElement, isFastTest);
702  }
703 
706  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
707  bool isFastTest = true) {
708  return chooseIteratorFrom(*this, includeElement, isFastTest);
709  }
710 
713  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
714  bool isFastTest = true) const {
715  const_iterator result = chooseIterator(includeElement, isFastTest);
716  OGDF_ASSERT(result.valid());
717  return *result;
718  }
719 
722  std::function<bool(const E&)> includeElement = [](const E&) { return true; },
723  bool isFastTest = true) {
724  iterator result = chooseIterator(includeElement, isFastTest);
725  OGDF_ASSERT(result.valid());
726  return *result;
727  }
728 
730  void permute() {
731  std::minstd_rand rng(randomSeed());
732  permute(size(), rng);
733  }
734 
736  template<class RNG>
737  void permute(RNG &rng) {
738  permute(size(), rng);
739  }
740 
742 
743 protected:
744  void copy(const SListPure<E> &L) {
745  for(SListElement<E> *pX = L.m_head; pX != nullptr; pX = pX->m_next)
746  pushBack(pX->m_x);
747  }
748 
750  template<class RNG>
751  void permute(const int n, RNG &rng);
752 
754  inline void reassignListRefs(SListElement<E> *start = nullptr) {
755 #ifdef OGDF_DEBUG
756  for(auto e = start == nullptr ? m_head : start; e != nullptr; e = e->m_next) {
757  e->m_list = this;
758  }
759 #endif
760  }
761 
763 };
764 
766 
776 template<class E>
777 class SList : private SListPure<E> {
778 
779  int m_count;
780 
781 public:
782  using typename SListPure<E>::value_type;
783  using typename SListPure<E>::reference;
784  using typename SListPure<E>::const_reference;
785  using typename SListPure<E>::const_iterator;
786  using typename SListPure<E>::iterator;
787 
789  SList() : m_count(0) { }
790 
792  SList(std::initializer_list<E> init) : SListPure<E>(init), m_count((int) init.size()) { }
793 
795  SList(const SList<E> &L) : SListPure<E>(L), m_count(L.m_count) { }
796 
798 
801  SList(SList<E> &&L) : SListPure<E>(std::move(L)), m_count(L.m_count) {
802  L.m_count = 0;
803  }
804 
810 
812 
815  int size() const { return m_count; }
816 
818  const SListPure<E> &getSListPure() const { return *this; }
819 
821 
826 
830  m_count = L.m_count;
831  return *this;
832  }
833 
835 
839  m_count = L.m_count;
841  L.m_count = 0;
842  return *this;
843  }
844 
846  bool operator==(const SList<E> &L) const {
847  return (m_count == L.m_count) && SListPure<E>::operator==(L);
848  }
849 
851  bool operator!=(const SList<E> &L) const {
852  return !operator==(L);
853  }
854 
856 
861 
864  ++m_count;
865  return SListPure<E>::pushFront(x);
866  }
867 
869  template<class ... Args>
870  iterator emplaceFront(Args && ... args) {
871  ++m_count;
872  return SListPure<E>::emplaceFront(std::forward<Args>(args)...);
873  }
874 
877  ++m_count;
878  return SListPure<E>::pushBack(x);
879  }
880 
882  template<class ... Args>
883  iterator emplaceBack(Args && ... args) {
884  ++m_count;
885  return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
886  }
887 
890  ++m_count;
891  return SListPure<E>::insertAfter(x, itBefore);
892  }
893 
895 
900 
902  void popFront() {
903  --m_count;
905  }
906 
909  E el = front();
910  popFront();
911  return el;
912  }
913 
915  void delSucc(SListIterator<E> itBefore) {
916  --m_count;
917  SListPure<E>::delSucc(itBefore);
918  }
919 
921  void clear() {
922  m_count = 0;
924  }
925 
927 
932 
936  --m_count; ++L2.m_count;
937  }
938 
942  --m_count; ++L2.m_count;
943  }
944 
947  SListPure<E>::moveFrontToSucc(L2,itBefore);
948  --m_count; ++L2.m_count;
949  }
950 
952  void conc(SList<E> &L2) {
953  SListPure<E>::conc(L2);
954  m_count += L2.m_count;
955  L2.m_count = 0;
956  }
957 
958  using SListPure<E>::empty;
959  using SListPure<E>::front;
960  using SListPure<E>::back;
961  using SListPure<E>::get;
962  using SListPure<E>::pos;
963  using SListPure<E>::begin;
964  using SListPure<E>::cbegin;
965  using SListPure<E>::end;
966  using SListPure<E>::cend;
967  using SListPure<E>::rbegin;
968  using SListPure<E>::crbegin;
970  using SListPure<E>::reverse;
971  using SListPure<E>::search;
976  using SListPure<E>::permute;
977 
979 };
980 
981 template<class E>
983 {
984  // if less than two elements, nothing to do
985  if (m_head == m_tail) return;
986 
987  int l, h;
988  l = h = f.getBucket(m_head->m_x);
989 
990  SListElement<E> *pX;
991  for(pX = m_head->m_next; pX; pX = pX->m_next)
992  {
993  int i = f.getBucket(pX->m_x);
994  if (i < l) l = i;
995  if (i > h) h = i;
996  }
997 
998  bucketSort(l,h,f);
999 }
1000 
1001 template<class E>
1003 {
1004  // if less than two elements, nothing to do
1005  if (m_head == m_tail) return;
1006 
1007  Array<SListElement<E> *> head(l,h,nullptr), tail(l,h);
1008 
1009  SListElement<E> *pX;
1010  for (pX = m_head; pX; pX = pX->m_next) {
1011  int i = f.getBucket(pX->m_x);
1012  if (head[i])
1013  tail[i] = (tail[i]->m_next = pX);
1014  else
1015  head[i] = tail[i] = pX;
1016  }
1017 
1018  SListElement<E> *pY = nullptr;
1019  for (int i = l; i <= h; i++) {
1020  pX = head[i];
1021  if (pX) {
1022  if (pY)
1023  pY->m_next = pX;
1024  else
1025  m_head = pX;
1026  pY = tail[i];
1027  }
1028  }
1029 
1030  m_tail = pY;
1031  pY->m_next = nullptr;
1032 }
1033 
1034 template<class E>
1035 template<class RNG>
1036 void SListPure<E>::permute(const int n, RNG &rng)
1037 {
1038  Array<SListElement<E> *> A(n+1);
1039  A[n] = nullptr;
1040 
1041  int i = 0;
1042  SListElement<E> *pX;
1043  for (pX = m_head; pX; pX = pX->m_next)
1044  A[i++] = pX;
1045 
1046  A.permute(0,n-1,rng);
1047 
1048  for (i = 0; i < n; i++) {
1049  A[i]->m_next = A[i+1];
1050  }
1051 
1052  m_head = A[0];
1053  m_tail = A[n-1];
1054 }
1055 
1057 template<class E>
1058 void print(ostream &os, const SListPure<E> &L, char delim = ' ')
1059 {
1060  SListConstIterator<E> pX = L.begin();
1061  if (pX.valid()) {
1062  os << *pX;
1063  for(++pX; pX.valid(); ++pX)
1064  os << delim << *pX;
1065  }
1066 }
1067 
1069 template<class E>
1070 void print(ostream &os, const SList<E> &L, char delim = ' ')
1071 {
1072  print(os, L.getSListPure(), delim);
1073 }
1074 
1076 template<class E>
1077 ostream &operator<<(ostream &os, const SListPure<E> &L)
1078 {
1079  print(os,L);
1080  return os;
1081 }
1082 
1084 template<class E>
1085 ostream &operator<<(ostream &os, const SList<E> &L)
1086 {
1087  return operator<<(os,L.getSListPure());
1088 }
1089 
1092 template<class E>
1093 void bucketSort(Array<E> &a, int min, int max, BucketFunc<E> &f)
1094 {
1095  if (a.low() >= a.high()) return;
1096 
1097  Array<SListPure<E> > bucket(min,max);
1098 
1099  int i;
1100  for(i = a.low(); i <= a.high(); ++i)
1101  bucket[f.getBucket(a[i])].pushBack(a[i]);
1102 
1103  i = a.low();
1104  for(int j = min; j <= max; ++j) {
1105  SListConstIterator<E> it = bucket[j].begin();
1106  for(; it.valid(); ++it)
1107  a[i++] = *it;
1108  }
1109 }
1110 
1111 }
SList< E > & operator=(SList< E > &&L)
Assignment operator (move semantics).
Definition: SList.h:838
bool operator==(const SListIteratorBase< E, isConst > &it) const
Equality operator.
Definition: SList.h:125
SListElement(SListPure< E > *list, SListElement< E > *next, Args &&... args)
Constructs an SListElement with given arguments args for constructor of element type.
Definition: SList.h:71
SList(std::initializer_list< E > init)
Constructs a singly linked list containing the elements in init.
Definition: SList.h:792
bool operator!=(const SListIteratorBase< E, isConst > &it) const
Inequality operator.
Definition: SList.h:130
SListElement< E > * m_head
Pointer to first element.
Definition: SList.h:174
E value_type
Represents the data type stored in a list element.
Definition: SList.h:179
SListIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
Definition: SList.h:153
SListPure< E > & operator=(SListPure< E > &&L)
Assignment operator (move semantics).
Definition: SList.h:403
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:641
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition: SList.h:328
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:56
void delSucc(iterator itBefore)
Removes the succesor of itBefore.
Definition: SList.h:522
bool valid() const
Returns true iff the iterator points to an element.
Definition: SList.h:113
Contains the class UmlDiagramGraph which represents one particular diagram of the complete UML Model...
void moveFrontToSucc(SListPure< E > &L2, iterator itBefore)
Moves the first element of this list to list L2 inserted after itBefore.
Definition: SList.h:586
void quicksortTemplate(LIST &L)
const_reference back() const
Returns a reference to the last element.
Definition: SList.h:256
bool empty() const
Returns true iff the list is empty.
Definition: SList.h:220
void permute(RNG &rng)
Randomly permutes the elements in the list using random number generator rng.
Definition: SList.h:737
virtual ~SListPure()
Destructor.
Definition: SList.h:211
int size() const
Returns the number of elements in the list.
Definition: SList.h:815
Singly linked lists.
Definition: SList.h:38
INDEX high() const
Returns the maximal array index.
Definition: Array.h:131
reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
List::chooseElement.
Definition: SList.h:721
SListElement(SListPure< E > *list, const E &x)
Constructs an SListElement.
Definition: SList.h:66
const_iterator cyclicSucc(const_iterator it) const
Returns an iterator to the cyclic successor of it.
Definition: SList.h:370
const_iterator begin() const
Returns a const iterator to the first element of the list.
Definition: SList.h:322
const_iterator crbegin() const
Returns a const iterator to the last element of the list.
Definition: SList.h:364
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.
virtual int size() const
Returns the number of elements in the list.
Definition: SList.h:227
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:40
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
Definition: SList.h:1002
bool operator==(const SList< E > &L) const
Equality operator.
Definition: SList.h:846
const_iterator rbegin() const
Returns a const iterator to the last element of the list.
Definition: SList.h:358
SListIteratorBase< E, isConst > succ() const
Returns successor iterator.
Definition: SList.h:135
void reverse()
Reverses the order of the list elements.
Definition: SList.h:615
SListIteratorBase< E, isConst > & operator=(const SListIterator< E > &it)
Assignment operator.
Definition: SList.h:141
SListIterator< E > insertAfter(const E &x, SListIterator< E > itBefore)
Inserts element x after itBefore.
Definition: SList.h:889
SListPure()
Constructs an empty singly linked list.
Definition: SList.h:190
SListElement()
Constructs an SListElement.
Definition: SList.h:68
const_iterator end() const
Returns a const iterator to one-past-last element of the list.
Definition: SList.h:340
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:659
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:883
ListElem * m_pX
Pointer to slist element.
Definition: SList.h:96
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition: Array.h:326
Singly linked lists (maintaining the length of the list).
Definition: SList.h:777
void moveFrontToFront(SList< E > &L2)
Moves the first element of this list to the begin of list L2.
Definition: SList.h:934
void quicksort(const COMPARER &comp)
Sorts the list using Quicksort and comparer comp.
Definition: SList.h:673
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:764
SListIteratorBase(ListElem *pX)
Constructs an iterator that points to pX.
Definition: SList.h:103
bool operator==(const SListPure< E > &L) const
Equality operator.
Definition: SList.h:413
E popFrontRet()
Removes the first element from the list and returns it.
Definition: SList.h:908
SListElement< E > * m_next
Pointer to successor element.
Definition: SList.h:52
SListPure(std::initializer_list< E > init)
Constructs a singly linked list containing the elements in init.
Definition: SList.h:193
Elem & operator*() const
Returns a reference to the element content.
Definition: SList.h:138
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
void reassignListRefs(SListElement< E > *start=nullptr)
Sets the debug reference of all list elements starting at start to this.
Definition: SList.h:754
iterator begin()
Returns an iterator to the first element of the list.
Definition: SList.h:316
const SListPure< E > & getSListPure() const
Conversion to const SListPure.
Definition: SList.h:818
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition: SList.h:828
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:455
bool operator!=(const SListPure< E > &L) const
Inequality operator.
Definition: SList.h:425
void delSucc(SListIterator< E > itBefore)
Removes the succesor of itBefore.
Definition: SList.h:915
SList(SList< E > &&L)
Constructs a singly linked list containing the elements of L (move semantics).
Definition: SList.h:801
static void copy(const T &from, T &to)
Definition: Alg.h:61
SListPure(const SListPure< E > &L)
Constructs a singly linked list that is a copy of L.
Definition: SList.h:198
const_iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
Returns an iterator to a random element.
Definition: SList.h:698
List-based stacks.
Definition: SList.h:39
void conc(SListPure< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition: SList.h:602
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition: SList.h:469
int pos(const_iterator it) const
Returns the position (starting with 0) of it in the list.
Definition: SList.h:297
void popFront()
Removes the first element from the list.
Definition: SList.h:501
bool operator!=(const SList< E > &L) const
Inequality operator.
Definition: SList.h:851
void quicksort()
Sorts the list using Quicksort.
Definition: SList.h:667
E & reference
Provides a reference to an element stored in a list.
Definition: SList.h:181
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:650
void moveFrontToBack(SList< E > &L2)
Moves the first element of this list to the end of list L2.
Definition: SList.h:940
typename std::conditional< isConst, const ogdf::ExternE, ogdf::ExternE >::type Elem
The underlying type, depending on isConst.
Definition: SList.h:94
void conc(SList< E > &L2)
Appends L2 to this list and makes L2 empty.
Definition: SList.h:952
const_reference front() const
Returns a reference to the first element.
Definition: SList.h:238
iterator insertAfter(const E &x, iterator itBefore)
Inserts element x after itBefore.
Definition: SList.h:482
void copy(const SListPure< E > &L)
Definition: SList.h:744
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
const T & move(const T &v)
Definition: backward.hpp:243
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: SList.h:437
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:633
Implementation of algorithms as templates working with different list types.
const E & const_reference
Provides a reference to a const element stored in a list for reading and performing const operations...
Definition: SList.h:183
SListIterator< E > pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: SList.h:863
reference front()
Returns a reference to the first element.
Definition: SList.h:247
iterator begin()
Returns an iterator to the first element.
Definition: Array.h:162
E popFrontRet()
Removes the first element from the list and returns it.
Definition: SList.h:512
Abstract base class for bucket functions.
Definition: basic.h:255
void moveFrontToBack(SListPure< E > &L2)
Moves the first element of this list to the end of list L2.
Definition: SList.h:567
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:1093
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:876
int m_count
The length of the list.
Definition: SList.h:779
SListElement(SListPure< E > *list, const E &x, SListElement< E > *next)
Constructs an SListElement.
Definition: SList.h:59
iterator chooseIterator(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
Returns an iterator to a random element.
Definition: SList.h:705
E m_x
Stores the content.
Definition: SList.h:53
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition: SList.h:346
SList(const SList< E > &L)
Constructs a singly linked list that is a copy of L.
Definition: SList.h:795
SList()
Constructs an empty singly linked list.
Definition: SList.h:789
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition: SList.h:394
reference back()
Returns a reference to the last element.
Definition: SList.h:265
virtual int getBucket(const E &x)=0
Returns the bucket of x.
void clear()
Removes all elements from the list.
Definition: SList.h:533
The namespace for all OGDF objects.
Structure for elements of singly linked lists.
Definition: SList.h:46
const_reference chooseElement(std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
List::chooseElement.
Definition: SList.h:712
SListElement< E > * m_tail
Pointer to last element.
Definition: SList.h:175
void clear()
Removes all elements from the list.
Definition: SList.h:921
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition: SList.h:448
iterator rbegin()
Returns an iterator to the last element of the list.
Definition: SList.h:352
iterator emplaceFront(Args &&... args)
Adds a new element at the beginning of the list.
Definition: SList.h:870
void moveFrontToFront(SListPure< E > &L2)
Moves the first element of this list to the begin of list L2.
Definition: SList.h:553
SListIteratorBase(const SListIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
Definition: SList.h:110
void print(ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition: Array.h:753
INDEX low() const
Returns the minimal array index.
Definition: Array.h:128
void moveFrontToSucc(SList< E > &L2, SListIterator< E > itBefore)
Moves the first element of this list to list L2 inserted after itBefore.
Definition: SList.h:946
SListIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
Definition: SList.h:147
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition: tuples.h:75
SListPure(SListPure< E > &&L)
Constructs a singly linked list containing the elements of L (move semantics).
Definition: SList.h:206
iterator cyclicSucc(iterator it)
Returns an iterator to the cyclic successor of it.
Definition: SList.h:380
void popFront()
Removes the first element from the list.
Definition: SList.h:902
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
iterator end()
Returns an iterator to one-past-last element of the list.
Definition: SList.h:334
SListIteratorBase()
Constructs an invalid iterator.
Definition: SList.h:106
void permute()
Randomly permutes the elements in the list.
Definition: SList.h:730