Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Array.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/Reverse.h>
36 #include <ogdf/basic/comparer.h>
37 #include <ogdf/basic/exceptions.h>
38 #include <ogdf/basic/memory.h>
39 
40 #include <random>
41 #include <type_traits>
42 
43 namespace ogdf {
44 
45 template<class E, class INDEX>
47 
48 template<class E, bool isConst>
50 template<class E>
51 using ArrayConstIterator = const E*;
52 template<class E>
53 using ArrayIterator = E*;
54 template<class E>
56 template<class E>
58 
60 
68 template<class E, bool isConst>
70  friend class ArrayReverseIteratorBase<E, !isConst>;
71 
74 
77 
78 public:
80  ArrayReverseIteratorBase(E* pX) : m_pX(pX) { }
81 
84  ArrayReverseIteratorBase(const E* pX) : m_pX(pX) { }
85 
88 
93 
98 
100  operator std::conditional<isConst, const E, E>*() const { return m_pX; }
101 
104  return m_pX == it.m_pX;
105  }
106 
109  return m_pX != it.m_pX;
110  }
111 
113  Elem& operator*() const { return *m_pX; }
114 
117  m_pX = it.m_pX;
118  return *this;
119  }
120 
123  m_pX--;
124  return *this;
125  }
126 
130  m_pX--;
131  return it;
132  }
133 
136  m_pX++;
137  return *this;
138  }
139 
143  m_pX++;
144  return it;
145  }
146 
149  m_pX -= rhs;
150  return *this;
151  }
152 
155  m_pX += rhs;
156  return *this;
157  }
158 
162  }
163 
168  return ArrayReverseIteratorBase<E, isConst>(rhs.m_pX - lhs);
169  }
170 
174  }
175 
177  template<bool isArgConst>
179  return rhs.m_pX - m_pX;
180  }
181 
183  bool operator<(ArrayReverseIteratorBase<E, isConst>& it) const { return m_pX > it.m_pX; }
184 
186  bool operator>(ArrayReverseIteratorBase<E, isConst>& it) const { return m_pX < it.m_pX; }
187 
189  bool operator<=(ArrayReverseIteratorBase<E, isConst>& it) const { return m_pX >= it.m_pX; }
190 
192  bool operator>=(ArrayReverseIteratorBase<E, isConst>& it) const { return m_pX <= it.m_pX; }
193 
195  Elem& operator[](std::size_t idx) { return m_pX[-idx]; }
196 
198  const Elem& operator[](std::size_t idx) const { return m_pX[-idx]; }
199 
201 };
202 
204 
213 template<class E, class INDEX = int>
214 class Array {
215 public:
218  static const int maxSizeInsertionSort = 40;
219 
221  using value_type = E;
223  using reference = E&;
225  using const_reference = const E&;
234 
236  Array() { construct(0, -1); }
237 
239  explicit Array(INDEX s) : Array(0, s - 1) { }
240 
242  Array(INDEX a, INDEX b) {
243  construct(a, b);
244  initialize();
245  }
246 
248  Array(INDEX a, INDEX b, const E& x) {
249  construct(a, b);
250  initialize(x);
251  }
252 
254 
257  Array(std::initializer_list<E> initList) {
258  construct(0, ((INDEX)initList.size()) - 1);
259  initialize(initList);
260  }
261 
263  Array(const Array<E, INDEX>& A) { copy(A); }
264 
266 
269  Array(Array<E, INDEX>&& A) noexcept
270  : m_vpStart(A.m_vpStart)
271  , m_pStart(A.m_pStart)
272  , m_pStop(A.m_pStop)
273  , m_low(A.m_low)
274  , m_high(A.m_high) {
275  A.construct(0, -1);
276  }
277 
279  Array(const ArrayBuffer<E, INDEX>& A);
280 
283 
288 
291  INDEX low() const { return m_low; }
292 
294  INDEX high() const { return m_high; }
295 
297  INDEX size() const { return m_high - m_low + 1; }
298 
300  bool empty() const { return size() == 0; }
301 
303  const_reference operator[](INDEX i) const {
304  OGDF_ASSERT(m_low <= i);
305  OGDF_ASSERT(i <= m_high);
306  return m_vpStart[i];
307  }
308 
311  OGDF_ASSERT(m_low <= i);
312  OGDF_ASSERT(i <= m_high);
313  return m_vpStart[i];
314  }
315 
317 
321 
324  iterator begin() { return m_pStart; }
325 
327  const_iterator begin() const { return m_pStart; }
328 
330  const_iterator cbegin() const { return m_pStart; }
331 
333  iterator end() { return m_pStop; }
334 
336  const_iterator end() const { return m_pStop; }
337 
339  const_iterator cend() const { return m_pStop; }
340 
342  reverse_iterator rbegin() { return m_pStop - 1; }
343 
345  const_reverse_iterator rbegin() const { return m_pStop - 1; }
346 
348  const_reverse_iterator crbegin() const { return m_pStop - 1; }
349 
351  reverse_iterator rend() { return m_pStart - 1; }
352 
354  const_reverse_iterator rend() const { return m_pStart - 1; }
355 
357  const_reverse_iterator crend() const { return m_pStart - 1; }
358 
360 
364 
367  void init() {
368  deconstruct();
369  construct(0, -1);
370  }
371 
373 
376  void init(INDEX s) { init(0, s - 1); }
377 
379 
382  void init(INDEX a, INDEX b) {
383  deconstruct();
384  construct(a, b);
385  initialize();
386  }
387 
389  void init(INDEX a, INDEX b, const E& x) {
390  deconstruct();
391  construct(a, b);
392  initialize(x);
393  }
394 
396  void fill(const E& x) {
397  E* pDest = m_pStop;
398  while (pDest > m_pStart) {
399  *--pDest = x;
400  }
401  }
402 
404  void fill(INDEX i, INDEX j, const E& x) {
405  OGDF_ASSERT(m_low <= i);
406  OGDF_ASSERT(i <= m_high);
407  OGDF_ASSERT(m_low <= j);
408  OGDF_ASSERT(j <= m_high);
409 
410  E *pI = m_vpStart + i, *pJ = m_vpStart + j + 1;
411  while (pJ > pI) {
412  *--pJ = x;
413  }
414  }
415 
417 
422  void grow(INDEX add, const E& x);
423 
425 
429  void grow(INDEX add);
430 
432 
437  void resize(INDEX newSize, const E& x) { grow(newSize - size(), x); }
438 
440 
444  void resize(INDEX newSize) { grow(newSize - size()); }
445 
448  deconstruct();
449  copy(A);
450  return *this;
451  }
452 
454 
458  deconstruct();
459 
460  m_vpStart = A.m_vpStart;
461  m_pStart = A.m_pStart;
462  m_pStop = A.m_pStop;
463  m_low = A.m_low;
464  m_high = A.m_high;
465 
466  A.construct(0, -1);
467  return *this;
468  }
469 
473 
475  bool operator==(const Array<E, INDEX>& L) const {
476  if (size() != L.size()) {
477  return false;
478  }
479 
480  auto thisIterator = begin();
481  auto thatIterator = L.begin();
482 
483  while (thisIterator != end() && thatIterator != L.end()) {
484  if (*thisIterator != *thatIterator) {
485  return false;
486  }
487  ++thisIterator;
488  ++thatIterator;
489  }
490 
491  OGDF_ASSERT(thisIterator == end() && thatIterator == L.end());
492  return true;
493  }
494 
496  bool operator!=(const Array<E, INDEX>& L) const { return !operator==(L); }
497 
499 
503 
506  void swap(INDEX i, INDEX j) {
507  OGDF_ASSERT(m_low <= i);
508  OGDF_ASSERT(i <= m_high);
509  OGDF_ASSERT(m_low <= j);
510  OGDF_ASSERT(j <= m_high);
511 
512  std::swap(m_vpStart[i], m_vpStart[j]);
513  }
514 
516  void permute(INDEX l, INDEX r) {
517  std::minstd_rand rng(randomSeed());
518  permute(l, r, rng);
519  }
520 
522  void permute() { permute(low(), high()); }
523 
530  template<class RNG>
531  void permute(INDEX l, INDEX r, RNG& rng);
532 
537  template<class RNG>
538  void permute(RNG& rng) {
539  if (!empty()) {
540  permute(low(), high(), rng);
541  }
542  }
543 
545 
549 
552 
556  inline int binarySearch(const E& e) const {
557  return binarySearch(low(), high(), e, StdComparer<E>());
558  }
559 
561 
565  inline int binarySearch(INDEX l, INDEX r, const E& e) const {
566  return binarySearch(l, r, e, StdComparer<E>());
567  }
568 
570 
574  template<class COMPARER>
575  inline int binarySearch(const E& e, const COMPARER& comp) const {
576  return binarySearch(low(), high(), e, comp);
577  }
578 
580 
584  template<class COMPARER>
585  INDEX binarySearch(INDEX l, INDEX r, const E& e, const COMPARER& comp) const {
586  if (r < l) {
587  return low() - 1;
588  }
589  while (r > l) {
590  INDEX m = (r + l) / 2;
591  if (comp.greater(e, m_vpStart[m])) {
592  l = m + 1;
593  } else {
594  r = m;
595  }
596  }
597  return comp.equal(e, m_vpStart[l]) ? l : low() - 1;
598  }
599 
601 
606  inline INDEX linearSearch(const E& e) const {
607  int i;
608  for (i = size(); i-- > 0;) {
609  if (e == m_pStart[i]) {
610  break;
611  }
612  }
613  return i + low();
614  }
615 
617 
622  template<class COMPARER>
623  INDEX linearSearch(const E& e, const COMPARER& comp) const {
624  int i;
625  for (i = size(); i-- > 0;) {
626  if (comp.equal(e, m_pStart[i])) {
627  break;
628  }
629  }
630  return i + low();
631  }
632 
634  inline void quicksort() { quicksort(StdComparer<E>()); }
635 
637  inline void quicksort(INDEX l, INDEX r) { quicksort(l, r, StdComparer<E>()); }
638 
640 
643  template<class COMPARER>
644  inline void quicksort(const COMPARER& comp) {
645  if (low() < high()) {
646  quicksortInt(m_pStart, m_pStop - 1, comp);
647  }
648  }
649 
651 
656  template<class COMPARER>
657  void quicksort(INDEX l, INDEX r, const COMPARER& comp) {
658  OGDF_ASSERT(low() <= l);
659  OGDF_ASSERT(l <= high());
660  OGDF_ASSERT(low() <= r);
661  OGDF_ASSERT(r <= high());
662  if (l < r) {
663  quicksortInt(m_vpStart + l, m_vpStart + r, comp);
664  }
665  }
666 
668 
680 
682 
692  void leftShift(ArrayBuffer<INDEX, INDEX>& ind, const E& val) {
693  leftShift(ind);
694  fill(high() - ind.size(), high(), val);
695  }
696 
698 
699  template<class F, class I>
700  friend class ArrayBuffer; // for efficient ArrayBuffer::compact-method
701 
702 private:
704  E* m_pStart;
705  E* m_pStop;
706  INDEX m_low;
707  INDEX m_high;
708 
710  void construct(INDEX a, INDEX b);
711 
713  void initialize();
714 
716  void initialize(const E& x);
717 
719  void initialize(std::initializer_list<E> initList);
720 
722  void deconstruct();
723 
725  void copy(const Array<E, INDEX>& A);
726 
728  void expandArray(INDEX add);
729 
731  template<typename EE = E, typename std::enable_if<OGDF_TRIVIALLY_COPYABLE<EE>::value, int>::type = 0>
732  void expandArrayHelper(INDEX sOld, INDEX sNew) {
733  // If the element type is trivially copiable, just use realloc.
734  E* p = static_cast<E*>(realloc(m_pStart, sNew * sizeof(E)));
735  if (p == nullptr) {
737  }
738  m_pStart = p;
739  }
740 
742  template<typename EE = E, typename std::enable_if<!OGDF_TRIVIALLY_COPYABLE<EE>::value, int>::type = 0>
743  void expandArrayHelper(INDEX sOld, INDEX sNew) {
744  // If the element type is not trivially copiable,
745  // allocate a new block, move the elements, and free the old block.
746  E* p = static_cast<E*>(malloc(sNew * sizeof(E)));
747  if (p == nullptr) {
749  }
750 
751  for (int i = 0; i < min(sOld, sNew); ++i) {
752  new (&p[i]) E(std::move(m_pStart[i]));
753  }
754 
755  deconstruct();
756  m_pStart = p;
757  }
758 
760  template<class COMPARER>
761  static void quicksortInt(E* pL, E* pR, const COMPARER& comp) {
762  size_t s = pR - pL;
763 
764  // use insertion sort for small instances
765  if (s < maxSizeInsertionSort) {
766  for (E* pI = pL + 1; pI <= pR; pI++) {
767  E v = *pI;
768  E* pJ = pI;
769  while (--pJ >= pL && comp.less(v, *pJ)) {
770  *(pJ + 1) = *pJ;
771  }
772  *(pJ + 1) = v;
773  }
774  return;
775  }
776 
777  E *pI = pL, *pJ = pR;
778  E x = *(pL + (s >> 1));
779 
780  do {
781  while (comp.less(*pI, x)) {
782  pI++;
783  }
784  while (comp.less(x, *pJ)) {
785  pJ--;
786  }
787  if (pI <= pJ) {
788  std::swap(*pI++, *pJ--);
789  }
790  } while (pI <= pJ);
791 
792  if (pL < pJ) {
793  quicksortInt(pL, pJ, comp);
794  }
795  if (pI < pR) {
796  quicksortInt(pI, pR, comp);
797  }
798  }
799 
801 };
802 
803 // enlarges storage for array and moves old entries
804 template<class E, class INDEX>
806  INDEX sOld = size(), sNew = sOld + add;
807 
808  // expand allocated memory block
809  if (m_pStart != nullptr) {
810  expandArrayHelper(sOld, sNew);
811  } else {
812  m_pStart = static_cast<E*>(malloc(sNew * sizeof(E)));
813  if (m_pStart == nullptr) {
815  }
816  }
817 
818  m_vpStart = m_pStart - m_low;
819  m_pStop = m_pStart + sNew;
820  m_high += add;
821 }
822 
823 // enlarges array by add elements and sets new elements to x
824 template<class E, class INDEX>
825 void Array<E, INDEX>::grow(INDEX add, const E& x) {
826  if (add == 0) {
827  return;
828  }
829 
830  INDEX sOld = size();
831  expandArray(add);
832 
833  // initialize new array entries
834  for (E* pDest = m_pStart + sOld; pDest < m_pStop; pDest++) {
835  new (pDest) E(x);
836  }
837 }
838 
839 // enlarges array by add elements (initialized with default constructor)
840 template<class E, class INDEX>
841 void Array<E, INDEX>::grow(INDEX add) {
842  if (add == 0) {
843  return;
844  }
845 
846  INDEX sOld = size();
847  expandArray(add);
848 
849  // initialize new array entries
850  for (E* pDest = m_pStart + sOld; pDest < m_pStop; pDest++) {
851  new (pDest) E();
852  }
853 }
854 
855 template<class E, class INDEX>
856 void Array<E, INDEX>::construct(INDEX a, INDEX b) {
857  m_low = a;
858  m_high = b;
859  INDEX s = b - a + 1;
860 
861  if (s < 1) {
862  m_pStart = m_vpStart = m_pStop = nullptr;
863 
864  } else {
865  m_pStart = static_cast<E*>(malloc(s * sizeof(E)));
866  if (m_pStart == nullptr) {
868  }
869 
870  m_vpStart = m_pStart - a;
871  m_pStop = m_pStart + s;
872  }
873 }
874 
875 template<class E, class INDEX>
877  E* pDest = m_pStart;
878  try {
879  for (; pDest < m_pStop; pDest++) {
880  new (pDest) E();
881  }
882  } catch (...) {
883  while (--pDest >= m_pStart) {
884  pDest->~E();
885  }
886  free(m_pStart);
887  throw;
888  }
889 }
890 
891 template<class E, class INDEX>
892 void Array<E, INDEX>::initialize(const E& x) {
893  E* pDest = m_pStart;
894  try {
895  for (; pDest < m_pStop; pDest++) {
896  new (pDest) E(x);
897  }
898  } catch (...) {
899  while (--pDest >= m_pStart) {
900  pDest->~E();
901  }
902  free(m_pStart);
903  throw;
904  }
905 }
906 
907 template<class E, class INDEX>
908 void Array<E, INDEX>::initialize(std::initializer_list<E> initList) {
909  E* pDest = m_pStart;
910  try {
911  for (const E& x : initList) {
912  new (pDest++) E(x);
913  }
914  } catch (...) {
915  while (--pDest >= m_pStart) {
916  pDest->~E();
917  }
918  free(m_pStart);
919  throw;
920  }
921 }
922 
923 template<class E, class INDEX>
925  if (!std::is_trivially_destructible<E>::value) {
926  for (E* pDest = m_pStart; pDest < m_pStop; pDest++) {
927  pDest->~E();
928  }
929  }
930  free(m_pStart);
931 }
932 
933 template<class E, class INDEX>
935  construct(array2.m_low, array2.m_high);
936 
937  if (m_pStart != nullptr) {
938  E* pSrc = array2.m_pStop;
939  E* pDest = m_pStop;
940  while (pDest > m_pStart)
941 #if 0
942  *--pDest = *--pSrc;
943 #endif
944  new (--pDest) E(*--pSrc);
945  }
946 }
947 
948 // permutes array a from a[l] to a[r] randomly
949 template<class E, class INDEX>
950 template<class RNG>
951 void Array<E, INDEX>::permute(INDEX l, INDEX r, RNG& rng) {
952  OGDF_ASSERT(low() <= l);
953  OGDF_ASSERT(l <= high());
954  OGDF_ASSERT(low() <= r);
955  OGDF_ASSERT(r <= high());
956 
957  std::uniform_int_distribution<int> dist(0, r - l);
958 
959  E *pI = m_vpStart + l, *pStart = m_vpStart + l, *pStop = m_vpStart + r;
960  while (pI <= pStop) {
961  std::swap(*pI++, *(pStart + dist(rng)));
962  }
963 }
964 
966 template<class E, class INDEX>
967 void print(std::ostream& os, const Array<E, INDEX>& a, char delim = ' ') {
968  for (int i = a.low(); i <= a.high(); i++) {
969  if (i > a.low()) {
970  os << delim;
971  }
972  os << a[i];
973  }
974 }
975 
977 template<class E, class INDEX>
978 std::ostream& operator<<(std::ostream& os, const ogdf::Array<E, INDEX>& a) {
979  print(os, a);
980  return os;
981 }
982 
983 }
984 
985 #include <ogdf/basic/ArrayBuffer.h>
986 
987 namespace ogdf {
988 
990 template<class E, class INDEX>
992  const INDEX nInd = ind.size();
993  if (nInd == 0) {
994  return;
995  }
996 
997  OGDF_ASSERT(ind[0] >= low());
998  OGDF_ASSERT(ind[0] <= high());
999 
1000  INDEX j, current = ind[0];
1001  for (INDEX i = 0; i < nInd - 1; i++) {
1002  OGDF_ASSERT(ind[i + 1] >= low());
1003  OGDF_ASSERT(ind[i + 1] <= high());
1004 
1005  const INDEX last = ind[i + 1];
1006  for (j = ind[i] + 1; j < last; j++) {
1007  m_vpStart[current++] = m_vpStart[j];
1008  }
1009  }
1010 
1012  for (j = ind[nInd - 1] + 1; j < size(); j++) {
1013  m_vpStart[current++] = m_vpStart[j];
1014  }
1015 }
1016 
1017 template<class E, class INDEX>
1019  construct(0, -1);
1020  A.compactCopy(*this);
1021 }
1022 
1023 }
ogdf::Array::quicksort
void quicksort(INDEX l, INDEX r)
Sorts subarray with index set [l, ..., r] using Quicksort.
Definition: Array.h:637
ogdf::ArrayBuffer
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition: Array.h:46
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::ArrayReverseIteratorBase::operator=
ArrayReverseIteratorBase< E, isConst > & operator=(const ArrayReverseIteratorBase< E, isConst > &it)
Assignment operator.
Definition: Array.h:116
ogdf::Array::resize
void resize(INDEX newSize)
Resizes (enlarges or shrinks) the array to hold newSize elements.
Definition: Array.h:444
ogdf::Array::m_vpStart
E * m_vpStart
The virtual start of the array (address of A[0]).
Definition: Array.h:703
ArrayBuffer.h
Declaration and implementation of ArrayBuffer class.
ogdf::Array::m_high
INDEX m_high
The highest index.
Definition: Array.h:707
ogdf::Array::Array
Array(INDEX a, INDEX b, const E &x)
Creates an array with index set [a..b] and initializes each element with x.
Definition: Array.h:248
exceptions.h
Definition of exception classes.
ogdf::ArrayReverseIteratorBase::operator>
bool operator>(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than operator.
Definition: Array.h:186
ogdf::InsufficientMemoryException
Exception thrown when not enough memory is available to execute an algorithm.
Definition: exceptions.h:205
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::Array::operator!=
bool operator!=(const Array< E, INDEX > &L) const
Inequality operator.
Definition: Array.h:496
ogdf::ArrayReverseIteratorBase::ArrayReverseIteratorBase
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isConst > &it)
Copy constructor. clang10 does not see the above templated one match this case and requires it explic...
Definition: Array.h:96
ogdf::ArrayReverseIteratorBase::operator+=
ArrayReverseIteratorBase< E, isConst > & operator+=(const int &rhs)
Compound assignment operator (+).
Definition: Array.h:148
ogdf::ArrayReverseIteratorBase::operator!=
bool operator!=(const ArrayReverseIteratorBase< E, isConst > &it) const
Inequality operator.
Definition: Array.h:108
ogdf::StdComparer
Standard comparer (valid as a static comparer).
Definition: comparer.h:59
ogdf::Array::operator[]
reference operator[](INDEX i)
Returns a reference to the element at position i.
Definition: Array.h:310
ogdf::Array::Array
Array(INDEX s)
Creates an array with index set [0..s-1].
Definition: Array.h:239
ogdf::ArrayReverseIteratorBase::operator<
bool operator<(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than operator.
Definition: Array.h:183
ogdf::Array::construct
void construct(INDEX a, INDEX b)
Allocates new array with index set [a, ..., b].
Definition: Array.h:856
ogdf::Array::initialize
void initialize()
Initializes elements with default constructor.
Definition: Array.h:876
ogdf::whaType::A
@ A
ogdf::ArrayIterator
E * ArrayIterator
Definition: Array.h:53
ogdf::Array::high
INDEX high() const
Returns the maximal array index.
Definition: Array.h:294
ogdf::Array::Array
Array(const Array< E, INDEX > &A)
Creates an array that is a copy of A.
Definition: Array.h:263
ogdf::ArrayReverseIteratorBase::ArrayReverseIteratorBase
ArrayReverseIteratorBase(E *pX)
Constructs an iterator that points to E* pX.
Definition: Array.h:80
ogdf::Array< PathType >::const_reference
const PathType & const_reference
Provides a reference to a const element stored in an array for reading and performing const operation...
Definition: Array.h:225
ogdf::Array::swap
void swap(INDEX i, INDEX j)
Swaps the elements at position i and j.
Definition: Array.h:506
ogdf::Array::deconstruct
void deconstruct()
Deallocates array.
Definition: Array.h:924
ogdf::Array::Array
Array(Array< E, INDEX > &&A) noexcept
Creates an array containing the elements of A (move semantics).
Definition: Array.h:269
ogdf::ArrayReverseIteratorBase
Random-access reverse iterator based on a pointer to an array element.
Definition: Array.h:49
ogdf::Array::leftShift
void leftShift(ArrayBuffer< INDEX, INDEX > &ind)
Removes the components listed in ind by shifting the remaining components to the left.
Definition: Array.h:991
ogdf::Array::permute
void permute()
Randomly permutes the array.
Definition: Array.h:522
ogdf::ArrayReverseIteratorBase::operator[]
const Elem & operator[](std::size_t idx) const
Const member access operator.
Definition: Array.h:198
ogdf::Array::Array
Array()
Creates an array with empty index set.
Definition: Array.h:236
ogdf::Array< PathType >::iterator
ArrayIterator< PathType > iterator
Provides a random-access iterator that can read or modify any element in an array.
Definition: Array.h:229
ogdf::ArrayReverseIteratorBase::operator-
ArrayReverseIteratorBase< E, isConst > operator-(const int &rhs)
Subtraction operator with int on the right-hand side.
Definition: Array.h:172
ogdf::Array::m_pStop
E * m_pStop
Successor of last element (address of A[m_high+1]).
Definition: Array.h:705
ogdf::Array::init
void init()
Reinitializes the array to an array with empty index set.
Definition: Array.h:367
ogdf::Array::end
const_iterator end() const
Returns a const iterator to one past the last element.
Definition: Array.h:336
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:84
ogdf::ArrayReverseIteratorBase::operator--
ArrayReverseIteratorBase< E, isConst > & operator--()
Decrement operator (prefix).
Definition: Array.h:135
ogdf::Array::expandArray
void expandArray(INDEX add)
Used by grow() to enlarge the array.
Definition: Array.h:805
ogdf::Array::crend
const_reverse_iterator crend() const
Returns a const reverse iterator to one before the first element.
Definition: Array.h:357
ogdf::Array::operator=
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition: Array.h:447
ogdf::ArrayReverseIteratorBase::ArrayReverseIteratorBase
ArrayReverseIteratorBase(const E *pX)
Constructs an iterator that points to const E* pX.
Definition: Array.h:84
ogdf::Array::leftShift
void leftShift(ArrayBuffer< INDEX, INDEX > &ind, const E &val)
Removes the components listed in ind by shifting the remaining components to the left.
Definition: Array.h:692
ogdf::Array::permute
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition: Array.h:516
ogdf::Array::init
void init(INDEX a, INDEX b, const E &x)
Reinitializes the array to an array with index set [a..b] and sets all entries to x.
Definition: Array.h:389
ogdf::Array::m_low
INDEX m_low
The lowest index.
Definition: Array.h:706
r
int r[]
Definition: hierarchical-ranking.cpp:8
ogdf::Array::quicksort
void quicksort(INDEX l, INDEX r, const COMPARER &comp)
Sorts the subarray with index set [l, ..., r] using Quicksort and a user-defined comparer comp.
Definition: Array.h:657
ogdf::ArrayReverseIteratorBase::operator--
ArrayReverseIteratorBase< E, isConst > operator--(int)
Decrement operator (postfix).
Definition: Array.h:141
ogdf::Array::quicksortInt
static void quicksortInt(E *pL, E *pR, const COMPARER &comp)
Internal Quicksort implementation with comparer template.
Definition: Array.h:761
ogdf::ArrayReverseIteratorBase::operator-
int operator-(ArrayReverseIteratorBase< E, isArgConst > &rhs)
Subtraction operator.
Definition: Array.h:178
ogdf::ArrayReverseIteratorBase::operator+
ArrayReverseIteratorBase< E, isConst > operator+(const int &rhs)
Addition operator with int on the right-hand side.
Definition: Array.h:160
ogdf::Array::init
void init(INDEX s)
Reinitializes the array to an array with index set [0..s-1].
Definition: Array.h:376
backward::Color::type
type
Definition: backward.hpp:1716
ogdf::ArrayReverseIteratorBase::operator++
ArrayReverseIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
Definition: Array.h:128
OGDF_THROW
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:70
ogdf::Array::binarySearch
int binarySearch(const E &e, const COMPARER &comp) const
Performs a binary search for element e with comparer comp.
Definition: Array.h:575
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:214
ogdf::Array::binarySearch
INDEX binarySearch(INDEX l, INDEX r, const E &e, const COMPARER &comp) const
Performs a binary search for element e within the array section [l, ..., r] with comparer comp.
Definition: Array.h:585
ogdf::ArrayReverseIteratorBase::operator++
ArrayReverseIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
Definition: Array.h:122
ogdf::Array::expandArrayHelper
void expandArrayHelper(INDEX sOld, INDEX sNew)
Used by expandArray() to reallocate the array elements.
Definition: Array.h:732
ogdf::Array::rbegin
reverse_iterator rbegin()
Returns an reverse iterator to the last element.
Definition: Array.h:342
ogdf::Array::rbegin
const_reverse_iterator rbegin() const
Returns a const reverse iterator to the last element.
Definition: Array.h:345
ogdf::Array::operator[]
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:303
ogdf::ArrayReverseIteratorBase::operator+
friend ArrayReverseIteratorBase< E, isConst > operator+(const int &lhs, ArrayReverseIteratorBase< E, isConst > rhs)
Addition operator with int on the left-hand side. Returns the same result as addition with int on the...
Definition: Array.h:166
ogdf::ArrayBuffer::size
INDEX size() const
Returns number of elements in the buffer.
Definition: ArrayBuffer.h:236
ogdf::Array::fill
void fill(const E &x)
Sets all elements to x.
Definition: Array.h:396
ogdf::Array< PathType >::reference
PathType & reference
Provides a reference to an element stored in an array.
Definition: Array.h:223
ogdf::Array::init
void init(INDEX a, INDEX b)
Reinitializes the array to an array with index set [a..b].
Definition: Array.h:382
ogdf::ArrayReverseIteratorBase::ArrayReverseIteratorBase
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
Definition: Array.h:91
ogdf::Array::begin
const_iterator begin() const
Returns a const iterator to the first element.
Definition: Array.h:327
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::ArrayReverseIteratorBase::operator*
Elem & operator*() const
Returns the element this iterator points to.
Definition: Array.h:113
ogdf::Array::rend
reverse_iterator rend()
Returns an reverse iterator to one before the first element.
Definition: Array.h:351
ogdf::Array::operator==
bool operator==(const Array< E, INDEX > &L) const
Equality operator.
Definition: Array.h:475
ogdf::ArrayReverseIteratorBase::operator<=
bool operator<=(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than-or-equals operator.
Definition: Array.h:189
ogdf::Array::fill
void fill(INDEX i, INDEX j, const E &x)
Sets elements in the intervall [i..j] to x.
Definition: Array.h:404
ogdf::Array::end
iterator end()
Returns an iterator to one past the last element.
Definition: Array.h:333
ogdf::Array::quicksort
void quicksort(const COMPARER &comp)
Sorts array using Quicksort and a user-defined comparer comp.
Definition: Array.h:644
ogdf::Array::cend
const_iterator cend() const
Returns a const iterator to one past the last element.
Definition: Array.h:339
ogdf::ArrayReverseIteratorBase::operator[]
Elem & operator[](std::size_t idx)
Member access operator.
Definition: Array.h:195
ogdf::randomSeed
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
ogdf::ArrayReverseIteratorBase::ArrayReverseIteratorBase
ArrayReverseIteratorBase()
Constructs an invalid iterator.
Definition: Array.h:87
Reverse.h
Implementation of the Reverse class for the reverse iteration of containers.
ogdf::Array::resize
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x.
Definition: Array.h:437
ogdf::Array::operator=
Array< E, INDEX > & operator=(Array< E, INDEX > &&A)
Assignment operator (move semantics).
Definition: Array.h:457
ogdf::Array::m_pStart
E * m_pStart
The real start of the array (address of A[m_low]).
Definition: Array.h:704
ogdf::Array< PathType >::const_iterator
ArrayConstIterator< PathType > const_iterator
Provides a random-access iterator that can read a const element in an array.
Definition: Array.h:227
ogdf::ArrayReverseIteratorBase::Elem
typename std::conditional< isConst, const E, E >::type Elem
The underlying element, depending on isConst.
Definition: Array.h:73
ogdf::Array::permute
void permute(RNG &rng)
Randomly permutes the array using random number generator rng.
Definition: Array.h:538
ogdf::Array::binarySearch
int binarySearch(const E &e) const
Performs a binary search for element e.
Definition: Array.h:556
ogdf::Array::crbegin
const_reverse_iterator crbegin() const
Returns a const reverse iterator to the last element.
Definition: Array.h:348
ogdf::Array::binarySearch
int binarySearch(INDEX l, INDEX r, const E &e) const
Performs a binary search for element e within the array section [l, ..., r] .
Definition: Array.h:565
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::ArrayReverseIteratorBase::operator==
bool operator==(const ArrayReverseIteratorBase< E, isConst > &it) const
Equality operator.
Definition: Array.h:103
ogdf::Array::low
INDEX low() const
Returns the minimal array index.
Definition: Array.h:291
ogdf::Array::quicksort
void quicksort()
Sorts array using Quicksort.
Definition: Array.h:634
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:297
ogdf::Array::grow
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
Definition: Array.h:825
ogdf::Array::~Array
~Array()
Destruction.
Definition: Array.h:282
ogdf::ArrayReverseIteratorBase::m_pX
Elem * m_pX
The pointer to the array element.
Definition: Array.h:76
ogdf::Array::copy
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
Definition: Array.h:934
ogdf::Array::maxSizeInsertionSort
static const int maxSizeInsertionSort
Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeIn...
Definition: Array.h:218
ogdf::ArrayReverseIteratorBase::operator>=
bool operator>=(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than-or-equals operator.
Definition: Array.h:192
ogdf::ArrayReverseIteratorBase::operator-=
ArrayReverseIteratorBase< E, isConst > & operator-=(const int &rhs)
Compound assignment operator (-).
Definition: Array.h:154
ogdf::Array::linearSearch
INDEX linearSearch(const E &e, const COMPARER &comp) const
Performs a linear search for element e with comparer comp.
Definition: Array.h:623
comparer.h
Declarations for Comparer objects.
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::Array::linearSearch
INDEX linearSearch(const E &e) const
Performs a linear search for element e.
Definition: Array.h:606
ogdf::Array< PathType >::value_type
PathType value_type
Represents the data type stored in an array element.
Definition: Array.h:221
ogdf::Array::Array
Array(INDEX a, INDEX b)
Creates an array with index set [a..b].
Definition: Array.h:242
ogdf::Array::empty
bool empty() const
Returns true iff there are no elements in the array.
Definition: Array.h:300
ogdf::Array::rend
const_reverse_iterator rend() const
Returns a const reverse iterator to one before the first element.
Definition: Array.h:354
ogdf::Array::Array
Array(std::initializer_list< E > initList)
Creates an array containing the elements in the initializer list initList.
Definition: Array.h:257
ogdf::Array::cbegin
const_iterator cbegin() const
Returns a const iterator to the first element.
Definition: Array.h:330
ogdf::ArrayConstIterator
const E * ArrayConstIterator
Definition: Array.h:51