Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Array.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/basic.h>
36#include <ogdf/basic/comparer.h>
38#include <ogdf/basic/memory.h>
39
40#include <algorithm>
41#include <cstdlib>
42#include <initializer_list>
43#include <new>
44#include <ostream>
45#include <random>
46#include <type_traits>
47
48namespace ogdf {
49
50template<class E, bool isConst>
51class ArrayReverseIteratorBase;
52template<class E, class INDEX>
53class ArrayBuffer;
54
55template<class E>
56using ArrayConstIterator = const E*;
57template<class E>
58using ArrayIterator = E*;
59template<class E>
61template<class E>
63
65
73template<class E, bool isConst>
75 friend class ArrayReverseIteratorBase<E, !isConst>;
76
78 using Elem = typename std::conditional<isConst, const E, E>::type;
79
82
83public:
86
88 template<bool isConstSFINAE = isConst, typename std::enable_if<isConstSFINAE, int>::type = 0>
89 ArrayReverseIteratorBase(const E* pX) : m_pX(pX) { }
90
93
95 template<bool isArgConst, typename std::enable_if<isConst || !isArgConst, int>::type = 0>
98
103
105 operator std::conditional<isConst, const E, E>*() const { return m_pX; }
106
109 return m_pX == it.m_pX;
110 }
111
114 return m_pX != it.m_pX;
115 }
116
118 Elem& operator*() const { return *m_pX; }
119
125
128 m_pX--;
129 return *this;
130 }
131
138
141 m_pX++;
142 return *this;
143 }
144
151
154 m_pX -= rhs;
155 return *this;
156 }
157
160 m_pX += rhs;
161 return *this;
162 }
163
168
175
180
182 template<bool isArgConst>
184 return rhs.m_pX - m_pX;
185 }
186
189
192
195
198
200 Elem& operator[](std::size_t idx) { return m_pX[-idx]; }
201
203 const Elem& operator[](std::size_t idx) const { return m_pX[-idx]; }
204
206};
207
209
218template<class E, class INDEX = int>
219class Array {
220public:
223 static const int maxSizeInsertionSort = 40;
224
226 using value_type = E;
228 using reference = E&;
230 using const_reference = const E&;
239
241 Array() { construct(0, -1); }
242
244 explicit Array(INDEX s) : Array(0, s - 1) { }
245
247 Array(INDEX a, INDEX b) {
248 construct(a, b);
249 initialize();
250 }
251
253 Array(INDEX a, INDEX b, const E& x) {
254 construct(a, b);
255 initialize(x);
256 }
257
259
262 Array(std::initializer_list<E> initList) {
263 construct(0, ((INDEX)initList.size()) - 1);
264 initialize(initList);
265 }
266
269
271
275 : m_vpStart(A.m_vpStart)
276 , m_pStart(A.m_pStart)
277 , m_pStop(A.m_pStop)
278 , m_low(A.m_low)
279 , m_high(A.m_high) {
280 A.construct(0, -1);
281 }
282
285
288
294
296 INDEX low() const { return m_low; }
297
299 INDEX high() const { return m_high; }
300
302 INDEX size() const { return m_high - m_low + 1; }
303
305 bool empty() const { return size() == 0; }
306
309 OGDF_ASSERT(m_low <= i);
310 OGDF_ASSERT(i <= m_high);
311 return m_vpStart[i];
312 }
313
316 OGDF_ASSERT(m_low <= i);
317 OGDF_ASSERT(i <= m_high);
318 return m_vpStart[i];
319 }
320
322
327
329 iterator begin() { return m_pStart; }
330
332 const_iterator begin() const { return m_pStart; }
333
335 const_iterator cbegin() const { return m_pStart; }
336
338 iterator end() { return m_pStop; }
339
341 const_iterator end() const { return m_pStop; }
342
344 const_iterator cend() const { return m_pStop; }
345
348
350 const_reverse_iterator rbegin() const { return m_pStop - 1; }
351
353 const_reverse_iterator crbegin() const { return m_pStop - 1; }
354
357
359 const_reverse_iterator rend() const { return m_pStart - 1; }
360
362 const_reverse_iterator crend() const { return m_pStart - 1; }
363
365
370
372 void init() {
373 deconstruct();
374 construct(0, -1);
375 }
376
378
381 void init(INDEX s) { init(0, s - 1); }
382
384
387 void init(INDEX a, INDEX b) {
388 deconstruct();
389 construct(a, b);
390 initialize();
391 }
392
394 void init(INDEX a, INDEX b, const E& x) {
395 deconstruct();
396 construct(a, b);
397 initialize(x);
398 }
399
401 void fill(const E& x) {
402 E* pDest = m_pStop;
403 while (pDest > m_pStart) {
404 *--pDest = x;
405 }
406 }
407
409 void fill(INDEX i, INDEX j, const E& x) {
410 OGDF_ASSERT(m_low <= i);
411 OGDF_ASSERT(i <= m_high);
412 OGDF_ASSERT(m_low <= j);
413 OGDF_ASSERT(j <= m_high);
414
415 E *pI = m_vpStart + i, *pJ = m_vpStart + j + 1;
416 while (pJ > pI) {
417 *--pJ = x;
418 }
419 }
420
422
427 void grow(INDEX add, const E& x);
428
430
434 void grow(INDEX add);
435
437
442 void resize(INDEX newSize, const E& x) { grow(newSize - size(), x); }
443
445
449 void resize(INDEX newSize) { grow(newSize - size()); }
450
453 deconstruct();
454 copy(A);
455 return *this;
456 }
457
459
463 deconstruct();
464
465 m_vpStart = A.m_vpStart;
466 m_pStart = A.m_pStart;
467 m_pStop = A.m_pStop;
468 m_low = A.m_low;
469 m_high = A.m_high;
470
471 A.construct(0, -1);
472 return *this;
473 }
474
478
480 bool operator==(const Array<E, INDEX>& L) const {
481 if (size() != L.size()) {
482 return false;
483 }
484
485 auto thisIterator = begin();
486 auto thatIterator = L.begin();
487
488 while (thisIterator != end() && thatIterator != L.end()) {
489 if (*thisIterator != *thatIterator) {
490 return false;
491 }
492 ++thisIterator;
493 ++thatIterator;
494 }
495
496 OGDF_ASSERT(thisIterator == end() && thatIterator == L.end());
497 return true;
498 }
499
501 bool operator!=(const Array<E, INDEX>& L) const { return !operator==(L); }
502
504
509
511 void swap(INDEX i, INDEX j) {
512 OGDF_ASSERT(m_low <= i);
513 OGDF_ASSERT(i <= m_high);
514 OGDF_ASSERT(m_low <= j);
515 OGDF_ASSERT(j <= m_high);
516
517 std::swap(m_vpStart[i], m_vpStart[j]);
518 }
519
521 void permute(INDEX l, INDEX r) {
522 std::minstd_rand rng(randomSeed());
523 permute(l, r, rng);
524 }
525
527 void permute() { permute(low(), high()); }
528
535 template<class RNG>
536 void permute(INDEX l, INDEX r, RNG& rng);
537
542 template<class RNG>
543 void permute(RNG& rng) {
544 if (!empty()) {
545 permute(low(), high(), rng);
546 }
547 }
548
550
555
557
561 inline int binarySearch(const E& e) const {
562 return binarySearch(low(), high(), e, StdComparer<E>());
563 }
564
566
570 inline int binarySearch(INDEX l, INDEX r, const E& e) const {
571 return binarySearch(l, r, e, StdComparer<E>());
572 }
573
575
579 template<class COMPARER>
580 inline int binarySearch(const E& e, const COMPARER& comp) const {
581 return binarySearch(low(), high(), e, comp);
582 }
583
585
589 template<class COMPARER>
590 INDEX binarySearch(INDEX l, INDEX r, const E& e, const COMPARER& comp) const {
591 if (r < l) {
592 return low() - 1;
593 }
594 while (r > l) {
595 INDEX m = (r + l) / 2;
596 if (comp.greater(e, m_vpStart[m])) {
597 l = m + 1;
598 } else {
599 r = m;
600 }
601 }
602 return comp.equal(e, m_vpStart[l]) ? l : low() - 1;
603 }
604
606
611 inline INDEX linearSearch(const E& e) const {
612 int i;
613 for (i = size(); i-- > 0;) {
614 if (e == m_pStart[i]) {
615 break;
616 }
617 }
618 return i + low();
619 }
620
622
627 template<class COMPARER>
628 INDEX linearSearch(const E& e, const COMPARER& comp) const {
629 int i;
630 for (i = size(); i-- > 0;) {
631 if (comp.equal(e, m_pStart[i])) {
632 break;
633 }
634 }
635 return i + low();
636 }
637
639 inline void quicksort() { quicksort(StdComparer<E>()); }
640
642 inline void quicksort(INDEX l, INDEX r) { quicksort(l, r, StdComparer<E>()); }
643
645
648 template<class COMPARER>
649 inline void quicksort(const COMPARER& comp) {
650 if (low() < high()) {
651 quicksortInt(m_pStart, m_pStop - 1, comp);
652 }
653 }
654
656
661 template<class COMPARER>
662 void quicksort(INDEX l, INDEX r, const COMPARER& comp) {
663 OGDF_ASSERT(low() <= l);
664 OGDF_ASSERT(l <= high());
665 OGDF_ASSERT(low() <= r);
666 OGDF_ASSERT(r <= high());
667 if (l < r) {
668 quicksortInt(m_vpStart + l, m_vpStart + r, comp);
669 }
670 }
671
673
685
687
697 void leftShift(ArrayBuffer<INDEX, INDEX>& ind, const E& val) {
698 leftShift(ind);
699 fill(high() - ind.size(), high(), val);
700 }
701
703
704 template<class F, class I>
705 friend class ArrayBuffer; // for efficient ArrayBuffer::compact-method
706
707private:
711 INDEX m_low;
712 INDEX m_high;
713
715 void construct(INDEX a, INDEX b);
716
719
721 void initialize(const E& x);
722
724 void initialize(std::initializer_list<E> initList);
725
728
730 void copy(const Array<E, INDEX>& A);
731
733 void expandArray(INDEX add);
734
736 template<typename EE = E, typename std::enable_if<OGDF_TRIVIALLY_COPYABLE<EE>::value, int>::type = 0>
737 void expandArrayHelper(INDEX sOld, INDEX sNew) {
738 // If the element type is trivially copiable, just use realloc.
739 E* p = static_cast<E*>(realloc(m_pStart, sNew * sizeof(E)));
740 if (p == nullptr) {
742 }
743 m_pStart = p;
744 }
745
747 template<typename EE = E, typename std::enable_if<!OGDF_TRIVIALLY_COPYABLE<EE>::value, int>::type = 0>
748 void expandArrayHelper(INDEX sOld, INDEX sNew) {
749 // If the element type is not trivially copiable,
750 // allocate a new block, move the elements, and free the old block.
751 E* p = static_cast<E*>(malloc(sNew * sizeof(E)));
752 if (p == nullptr) {
754 }
755
756 for (int i = 0; i < min(sOld, sNew); ++i) {
757 new (&p[i]) E(std::move(m_pStart[i]));
758 }
759
760 deconstruct();
761 m_pStart = p;
762 }
763
765 template<class COMPARER>
766 static void quicksortInt(E* pL, E* pR, const COMPARER& comp) {
767 size_t s = pR - pL;
768
769 // use insertion sort for small instances
770 if (s < maxSizeInsertionSort) {
771 for (E* pI = pL + 1; pI <= pR; pI++) {
772 E v = *pI;
773 E* pJ = pI;
774 while (--pJ >= pL && comp.less(v, *pJ)) {
775 *(pJ + 1) = *pJ;
776 }
777 *(pJ + 1) = v;
778 }
779 return;
780 }
781
782 E *pI = pL, *pJ = pR;
783 E x = *(pL + (s >> 1));
784
785 do {
786 while (comp.less(*pI, x)) {
787 pI++;
788 }
789 while (comp.less(x, *pJ)) {
790 pJ--;
791 }
792 if (pI <= pJ) {
793 std::swap(*pI++, *pJ--);
794 }
795 } while (pI <= pJ);
796
797 if (pL < pJ) {
798 quicksortInt(pL, pJ, comp);
799 }
800 if (pI < pR) {
801 quicksortInt(pI, pR, comp);
802 }
803 }
804
806};
807
808// enlarges storage for array and moves old entries
809template<class E, class INDEX>
811 INDEX sOld = size(), sNew = sOld + add;
812
813 // expand allocated memory block
814 if (m_pStart != nullptr) {
815 expandArrayHelper(sOld, sNew);
816 } else {
817 m_pStart = static_cast<E*>(malloc(sNew * sizeof(E)));
818 if (m_pStart == nullptr) {
820 }
821 }
822
823 m_vpStart = m_pStart - m_low;
824 m_pStop = m_pStart + sNew;
825 m_high += add;
826}
827
828// enlarges array by add elements and sets new elements to x
829template<class E, class INDEX>
830void Array<E, INDEX>::grow(INDEX add, const E& x) {
831 if (add == 0) {
832 return;
833 }
834
835 INDEX sOld = size();
836 expandArray(add);
837
838 // initialize new array entries
839 for (E* pDest = m_pStart + sOld; pDest < m_pStop; pDest++) {
840 new (pDest) E(x);
841 }
842}
843
844// enlarges array by add elements (initialized with default constructor)
845template<class E, class INDEX>
846void Array<E, INDEX>::grow(INDEX add) {
847 if (add == 0) {
848 return;
849 }
850
851 INDEX sOld = size();
852 expandArray(add);
853
854 // initialize new array entries
855 for (E* pDest = m_pStart + sOld; pDest < m_pStop; pDest++) {
856 new (pDest) E();
857 }
858}
859
860template<class E, class INDEX>
861void Array<E, INDEX>::construct(INDEX a, INDEX b) {
862 m_low = a;
863 m_high = b;
864 INDEX s = b - a + 1;
865
866 if (s < 1) {
867 m_pStart = m_vpStart = m_pStop = nullptr;
868
869 } else {
870 m_pStart = static_cast<E*>(malloc(s * sizeof(E)));
871 if (m_pStart == nullptr) {
873 }
874
875 m_vpStart = m_pStart - a;
876 m_pStop = m_pStart + s;
877 }
878}
879
880template<class E, class INDEX>
882 E* pDest = m_pStart;
883 try {
884 for (; pDest < m_pStop; pDest++) {
885 new (pDest) E();
886 }
887 } catch (...) {
888 while (--pDest >= m_pStart) {
889 pDest->~E();
890 }
891 free(m_pStart);
892 throw;
893 }
894}
895
896template<class E, class INDEX>
898 E* pDest = m_pStart;
899 try {
900 for (; pDest < m_pStop; pDest++) {
901 new (pDest) E(x);
902 }
903 } catch (...) {
904 while (--pDest >= m_pStart) {
905 pDest->~E();
906 }
907 free(m_pStart);
908 throw;
909 }
910}
911
912template<class E, class INDEX>
913void Array<E, INDEX>::initialize(std::initializer_list<E> initList) {
914 E* pDest = m_pStart;
915 try {
916 for (const E& x : initList) {
917 new (pDest++) E(x);
918 }
919 } catch (...) {
920 while (--pDest >= m_pStart) {
921 pDest->~E();
922 }
923 free(m_pStart);
924 throw;
925 }
926}
927
928template<class E, class INDEX>
930 if (!std::is_trivially_destructible<E>::value) {
931 for (E* pDest = m_pStart; pDest < m_pStop; pDest++) {
932 pDest->~E();
933 }
934 }
935 free(m_pStart);
936}
937
938template<class E, class INDEX>
940 construct(array2.m_low, array2.m_high);
941
942 if (m_pStart != nullptr) {
943 E* pSrc = array2.m_pStop;
944 E* pDest = m_pStop;
945 while (pDest > m_pStart)
946#if 0
947 *--pDest = *--pSrc;
948#endif
949 new (--pDest) E(*--pSrc);
950 }
951}
952
953// permutes array a from a[l] to a[r] randomly
954template<class E, class INDEX>
955template<class RNG>
956void Array<E, INDEX>::permute(INDEX l, INDEX r, RNG& rng) {
957 OGDF_ASSERT(low() <= l);
958 OGDF_ASSERT(l <= high());
959 OGDF_ASSERT(low() <= r);
960 OGDF_ASSERT(r <= high());
961
962 std::uniform_int_distribution<int> dist(0, r - l);
963
964 E *pI = m_vpStart + l, *pStart = m_vpStart + l, *pStop = m_vpStart + r;
965 while (pI <= pStop) {
966 std::swap(*pI++, *(pStart + dist(rng)));
967 }
968}
969
971template<class E, class INDEX>
972void print(std::ostream& os, const Array<E, INDEX>& a, char delim = ' ') {
973 for (int i = a.low(); i <= a.high(); i++) {
974 if (i > a.low()) {
975 os << delim;
976 }
977 os << a[i];
978 }
979}
980
982template<class E, class INDEX>
983std::ostream& operator<<(std::ostream& os, const ogdf::Array<E, INDEX>& a) {
984 print(os, a);
985 return os;
986}
987
988}
989
990namespace ogdf {
991
993template<class E, class INDEX>
995 const INDEX nInd = ind.size();
996 if (nInd == 0) {
997 return;
998 }
999
1000 OGDF_ASSERT(ind[0] >= low());
1001 OGDF_ASSERT(ind[0] <= high());
1002
1003 INDEX j, current = ind[0];
1004 for (INDEX i = 0; i < nInd - 1; i++) {
1005 OGDF_ASSERT(ind[i + 1] >= low());
1006 OGDF_ASSERT(ind[i + 1] <= high());
1007
1008 const INDEX last = ind[i + 1];
1009 for (j = ind[i] + 1; j < last; j++) {
1010 m_vpStart[current++] = m_vpStart[j];
1011 }
1012 }
1013
1015 for (j = ind[nInd - 1] + 1; j < size(); j++) {
1016 m_vpStart[current++] = m_vpStart[j];
1017 }
1018}
1019
1020template<class E, class INDEX>
1022 construct(0, -1);
1023 A.compactCopy(*this);
1024}
1025
1026}
Basic declarations, included by all source files.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
INDEX size() const
Returns number of elements in the buffer.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
iterator begin()
Returns an iterator to the first element.
Definition Array.h:329
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition Array.h:308
void quicksort(const COMPARER &comp)
Sorts array using Quicksort and a user-defined comparer comp.
Definition Array.h:649
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:442
reference operator[](INDEX i)
Returns a reference to the element at position i.
Definition Array.h:315
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
Definition Array.h:830
void deconstruct()
Deallocates array.
Definition Array.h:929
void swap(INDEX i, INDEX j)
Swaps the elements at position i and j.
Definition Array.h:511
const_reverse_iterator rend() const
Returns a const reverse iterator to one before the first element.
Definition Array.h:359
E * m_pStop
Successor of last element (address of A[m_high+1]).
Definition Array.h:710
static const int maxSizeInsertionSort
Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeIn...
Definition Array.h:223
INDEX high() const
Returns the maximal array index.
Definition Array.h:299
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition Array.h:521
reverse_iterator rbegin()
Returns an reverse iterator to the last element.
Definition Array.h:347
INDEX m_low
The lowest index.
Definition Array.h:711
reverse_iterator rend()
Returns an reverse iterator to one before the first element.
Definition Array.h:356
INDEX linearSearch(const E &e) const
Performs a linear search for element e.
Definition Array.h:611
void leftShift(ArrayBuffer< INDEX, INDEX > &ind)
Removes the components listed in ind by shifting the remaining components to the left.
Definition Array.h:994
Array(const ArrayBuffer< E, INDEX > &A)
Creates an array that is a copy of A. The array-size is set to be the number of elements (not the cap...
Definition Array.h:1021
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:590
const_iterator cend() const
Returns a const iterator to one past the last element.
Definition Array.h:344
static void quicksortInt(E *pL, E *pR, const COMPARER &comp)
Internal Quicksort implementation with comparer template.
Definition Array.h:766
const_iterator begin() const
Returns a const iterator to the first element.
Definition Array.h:332
void grow(INDEX add)
Enlarges the array by add elements.
Definition Array.h:846
int binarySearch(const E &e, const COMPARER &comp) const
Performs a binary search for element e with comparer comp.
Definition Array.h:580
void permute(RNG &rng)
Randomly permutes the array using random number generator rng.
Definition Array.h:543
void construct(INDEX a, INDEX b)
Allocates new array with index set [a, ..., b].
Definition Array.h:861
iterator end()
Returns an iterator to one past the last element.
Definition Array.h:338
bool empty() const
Returns true iff there are no elements in the array.
Definition Array.h:305
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:662
void init()
Reinitializes the array to an array with empty index set.
Definition Array.h:372
void fill(const E &x)
Sets all elements to x.
Definition Array.h:401
void initialize(const E &x)
Initializes elements with x.
Definition Array.h:897
void quicksort()
Sorts array using Quicksort.
Definition Array.h:639
void expandArray(INDEX add)
Used by grow() to enlarge the array.
Definition Array.h:810
const_reverse_iterator crend() const
Returns a const reverse iterator to one before the first element.
Definition Array.h:362
void init(INDEX a, INDEX b)
Reinitializes the array to an array with index set [a..b].
Definition Array.h:387
void expandArrayHelper(INDEX sOld, INDEX sNew)
Used by expandArray() to reallocate the array elements.
Definition Array.h:737
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:253
Array(Array< E, INDEX > &&A) noexcept
Creates an array containing the elements of A (move semantics).
Definition Array.h:274
bool operator!=(const Array< E, INDEX > &L) const
Inequality operator.
Definition Array.h:501
E & reference
Provides a reference to an element stored in an array.
Definition Array.h:228
int binarySearch(const E &e) const
Performs a binary search for element e.
Definition Array.h:561
ArrayConstIterator< E > const_iterator
Provides a random-access iterator that can read a const element in an array.
Definition Array.h:232
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition Array.h:452
INDEX low() const
Returns the minimal array index.
Definition Array.h:296
void initialize()
Initializes elements with default constructor.
Definition Array.h:881
void permute()
Randomly permutes the array.
Definition Array.h:527
void quicksort(INDEX l, INDEX r)
Sorts subarray with index set [l, ..., r] using Quicksort.
Definition Array.h:642
INDEX size() const
Returns the size (number of elements) of the array.
Definition Array.h:302
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:570
const_reverse_iterator crbegin() const
Returns a const reverse iterator to the last element.
Definition Array.h:353
~Array()
Destruction.
Definition Array.h:287
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:697
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
Definition Array.h:939
void resize(INDEX newSize)
Resizes (enlarges or shrinks) the array to hold newSize elements.
Definition Array.h:449
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:394
const_iterator end() const
Returns a const iterator to one past the last element.
Definition Array.h:341
void fill(INDEX i, INDEX j, const E &x)
Sets elements in the intervall [i..j] to x.
Definition Array.h:409
INDEX m_high
The highest index.
Definition Array.h:712
void initialize(std::initializer_list< E > initList)
Initializes elements from given initializer list initList.
Definition Array.h:913
ArrayIterator< E > iterator
Provides a random-access iterator that can read or modify any element in an array.
Definition Array.h:234
bool operator==(const Array< E, INDEX > &L) const
Equality operator.
Definition Array.h:480
Array(INDEX a, INDEX b)
Creates an array with index set [a..b].
Definition Array.h:247
E * m_vpStart
The virtual start of the array (address of A[0]).
Definition Array.h:708
E * m_pStart
The real start of the array (address of A[m_low]).
Definition Array.h:709
Array()
Creates an array with empty index set.
Definition Array.h:241
E value_type
Represents the data type stored in an array element.
Definition Array.h:226
Array(const Array< E, INDEX > &A)
Creates an array that is a copy of A.
Definition Array.h:268
Array(INDEX s)
Creates an array with index set [0..s-1].
Definition Array.h:244
const_iterator cbegin() const
Returns a const iterator to the first element.
Definition Array.h:335
void init(INDEX s)
Reinitializes the array to an array with index set [0..s-1].
Definition Array.h:381
void permute(INDEX l, INDEX r, RNG &rng)
Randomly permutes the subarray with index set [l..r] using random number generator rng.
Definition Array.h:956
INDEX linearSearch(const E &e, const COMPARER &comp) const
Performs a linear search for element e with comparer comp.
Definition Array.h:628
const E & const_reference
Provides a reference to a const element stored in an array for reading and performing const operation...
Definition Array.h:230
Array< E, INDEX > & operator=(Array< E, INDEX > &&A)
Assignment operator (move semantics).
Definition Array.h:462
const_reverse_iterator rbegin() const
Returns a const reverse iterator to the last element.
Definition Array.h:350
Array(std::initializer_list< E > initList)
Creates an array containing the elements in the initializer list initList.
Definition Array.h:262
Random-access reverse iterator based on a pointer to an array element.
Definition Array.h:74
bool operator<=(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than-or-equals operator.
Definition Array.h:194
ArrayReverseIteratorBase< E, isConst > operator-(const int &rhs)
Subtraction operator with int on the right-hand side.
Definition Array.h:177
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:171
const Elem & operator[](std::size_t idx) const
Const member access operator.
Definition Array.h:203
bool operator!=(const ArrayReverseIteratorBase< E, isConst > &it) const
Inequality operator.
Definition Array.h:113
ArrayReverseIteratorBase()
Constructs an invalid iterator.
Definition Array.h:92
int operator-(ArrayReverseIteratorBase< E, isArgConst > &rhs)
Subtraction operator.
Definition Array.h:183
ArrayReverseIteratorBase(E *pX)
Constructs an iterator that points to E* pX.
Definition Array.h:85
ArrayReverseIteratorBase(const E *pX)
Constructs an iterator that points to const E* pX.
Definition Array.h:89
ArrayReverseIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
Definition Array.h:127
bool operator>=(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than-or-equals operator.
Definition Array.h:197
ArrayReverseIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
Definition Array.h:133
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:101
bool operator==(const ArrayReverseIteratorBase< E, isConst > &it) const
Equality operator.
Definition Array.h:108
ArrayReverseIteratorBase< E, isConst > & operator=(const ArrayReverseIteratorBase< E, isConst > &it)
Assignment operator.
Definition Array.h:121
ArrayReverseIteratorBase< E, isConst > operator+(const int &rhs)
Addition operator with int on the right-hand side.
Definition Array.h:165
Elem * m_pX
The pointer to the array element.
Definition Array.h:81
bool operator>(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than operator.
Definition Array.h:191
ArrayReverseIteratorBase< E, isConst > & operator--()
Decrement operator (prefix).
Definition Array.h:140
Elem & operator*() const
Returns the element this iterator points to.
Definition Array.h:118
ArrayReverseIteratorBase< E, isConst > operator--(int)
Decrement operator (postfix).
Definition Array.h:146
Elem & operator[](std::size_t idx)
Member access operator.
Definition Array.h:200
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
Definition Array.h:96
ArrayReverseIteratorBase< E, isConst > & operator+=(const int &rhs)
Compound assignment operator (+).
Definition Array.h:153
ArrayReverseIteratorBase< E, isConst > & operator-=(const int &rhs)
Compound assignment operator (-).
Definition Array.h:159
bool operator<(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than operator.
Definition Array.h:188
typename std::conditional< isConst, const E, E >::type Elem
The underlying element, depending on isConst.
Definition Array.h:78
Exception thrown when not enough memory is available to execute an algorithm.
Definition exceptions.h:209
Standard comparer (valid as a static comparer).
Definition comparer.h:63
Declarations for Comparer objects.
Definition of exception classes.
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition exceptions.h:67
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983
E * ArrayIterator
Definition Array.h:58
const E * ArrayConstIterator
Definition Array.h:56
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:972