Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

Array.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/comparer.h>
36 #include <ogdf/basic/memory.h>
37 #include <ogdf/basic/exceptions.h>
38 #include <ogdf/basic/Reverse.h>
39 #include <random>
40 #include <type_traits>
41 
42 
43 namespace ogdf {
44 
45 template<class E, class INDEX> class ArrayBuffer;
46 
47 template<class E, bool isConst> class ArrayReverseIteratorBase;
48 template<class E> using ArrayConstIterator = const E*;
49 template<class E> using ArrayIterator = E*;
52 
54 
62 template<class E, bool isConst> class ArrayReverseIteratorBase {
63  friend class ArrayReverseIteratorBase<E, !isConst>;
64 
67 
70 
71 public:
73  ArrayReverseIteratorBase(E *pX) : m_pX(pX) { }
74 
77  ArrayReverseIteratorBase(const E *pX) : m_pX(pX) { }
78 
81 
85 
87  operator std::conditional<isConst, const E, E> *() const { return m_pX; }
88 
91  return m_pX == it.m_pX;
92  }
93 
96  return m_pX != it.m_pX;
97  }
98 
100  Elem &operator*() const { return *m_pX; }
101 
104  m_pX = it.m_pX;
105  return *this;
106  }
107 
110  m_pX--;
111  return *this;
112  }
113 
117  m_pX--;
118  return it;
119  }
120 
123  m_pX++;
124  return *this;
125  }
126 
130  m_pX++;
131  return it;
132  }
133 
136  m_pX -= rhs;
137  return *this;
138  }
139 
142  m_pX += rhs;
143  return *this;
144  }
145 
148  return ArrayReverseIteratorBase<E, isConst>(m_pX - rhs);
149  }
150 
154  const int &lhs, ArrayReverseIteratorBase<E, isConst> rhs) {
155  return ArrayReverseIteratorBase<E, isConst>(rhs.m_pX - lhs);
156  }
157 
160  return ArrayReverseIteratorBase<E, isConst>(m_pX + rhs);
161  }
162 
164  template<bool isArgConst>
166  return rhs.m_pX - m_pX;
167  }
168 
170  bool operator< (ArrayReverseIteratorBase<E, isConst> &it) const { return m_pX > it.m_pX; }
171 
173  bool operator> (ArrayReverseIteratorBase<E, isConst> &it) const { return m_pX < it.m_pX; }
174 
176  bool operator<=(ArrayReverseIteratorBase<E, isConst> &it) const { return m_pX >= it.m_pX; }
177 
179  bool operator>=(ArrayReverseIteratorBase<E, isConst> &it) const { return m_pX <= it.m_pX; }
180 
182  Elem &operator[](std::size_t idx) { return m_pX[-idx]; }
183 
185  const Elem &operator[](std::size_t idx) const { return m_pX[-idx]; }
186 
188 };
189 
191 
200 template<class E, class INDEX = int> class Array {
201 public:
204  static const int maxSizeInsertionSort = 40;
205 
207  using value_type = E;
209  using reference = E&;
211  using const_reference = const E&;
220 
222  Array() { construct(0,-1); }
223 
225  explicit Array(INDEX s) : Array(0, s - 1) { }
226 
228  Array(INDEX a, INDEX b) {
229  construct(a,b); initialize();
230  }
231 
233  Array(INDEX a, INDEX b, const E &x) {
234  construct(a,b); initialize(x);
235  }
236 
238 
241  Array(std::initializer_list<E> initList) {
242  construct(0, ((INDEX) initList.size()) - 1);
243  initialize(initList);
244  }
245 
248  copy(A);
249  }
250 
252 
256  : m_vpStart(A.m_vpStart), m_pStart(A.m_pStart), m_pStop(A.m_pStop), m_low(A.m_low), m_high(A.m_high)
257  {
258  A.construct(0,-1);
259  }
260 
262  Array(const ArrayBuffer<E,INDEX> &A);
263 
265  ~Array() {
266  deconstruct();
267  }
268 
274 
276  INDEX low() const { return m_low; }
277 
279  INDEX high() const { return m_high; }
280 
282  INDEX size() const { return m_high - m_low + 1; }
283 
285  bool empty() const { return size() == 0; }
286 
288  const_reference operator[](INDEX i) const {
289  OGDF_ASSERT(m_low <= i);
290  OGDF_ASSERT(i <= m_high);
291  return m_vpStart[i];
292  }
293 
296  OGDF_ASSERT(m_low <= i);
297  OGDF_ASSERT(i <= m_high);
298  return m_vpStart[i];
299  }
300 
301 
303 
308 
310  iterator begin() { return m_pStart; }
311 
313  const_iterator begin() const { return m_pStart; }
314 
316  const_iterator cbegin() const { return m_pStart; }
317 
319  iterator end() { return m_pStop; }
320 
322  const_iterator end() const { return m_pStop; }
323 
325  const_iterator cend() const { return m_pStop; }
326 
328  reverse_iterator rbegin() { return m_pStop-1; }
329 
331  const_reverse_iterator rbegin() const { return m_pStop-1; }
332 
334  const_reverse_iterator crbegin() const { return m_pStop-1; }
335 
337  reverse_iterator rend() { return m_pStart-1; }
338 
340  const_reverse_iterator rend() const { return m_pStart-1; }
341 
343  const_reverse_iterator crend() const { return m_pStart-1; }
344 
345 
347 
352 
354  void init() {
355  deconstruct();
356  construct(0,-1);
357  }
358 
360 
363  void init(INDEX s) { init(0,s-1); }
364 
366 
369  void init(INDEX a, INDEX b) {
370  deconstruct();
371  construct(a,b);
372  initialize();
373  }
374 
376  void init(INDEX a, INDEX b, const E &x) {
377  deconstruct();
378  construct(a,b);
379  initialize(x);
380  }
381 
383  void fill(const E &x) {
384  E *pDest = m_pStop;
385  while(pDest > m_pStart)
386  *--pDest = x;
387  }
388 
390  void fill(INDEX i, INDEX j, const E &x) {
391  OGDF_ASSERT(m_low <= i);
392  OGDF_ASSERT(i <= m_high);
393  OGDF_ASSERT(m_low <= j);
394  OGDF_ASSERT(j <= m_high);
395 
396  E *pI = m_vpStart + i, *pJ = m_vpStart + j+1;
397  while(pJ > pI)
398  *--pJ = x;
399  }
400 
402 
407  void grow(INDEX add, const E &x);
408 
410 
414  void grow(INDEX add);
415 
417 
422  void resize(INDEX newSize, const E &x) { grow(newSize - size(), x); }
423 
425 
429  void resize(INDEX newSize) { grow(newSize - size()); }
430 
433  deconstruct();
434  copy(A);
435  return *this;
436  }
437 
439 
443  deconstruct();
444 
445  m_vpStart = A.m_vpStart;
446  m_pStart = A.m_pStart;
447  m_pStop = A.m_pStop;
448  m_low = A.m_low;
449  m_high = A.m_high;
450 
451  A.construct(0,-1);
452  return *this;
453  }
454 
458 
460  bool operator==(const Array<E, INDEX> &L) const {
461  if (size() != L.size()) {
462  return false;
463  }
464 
465  auto thisIterator = begin();
466  auto thatIterator = L.begin();
467 
468  while (thisIterator != end() && thatIterator != L.end()) {
469  if (*thisIterator != *thatIterator) {
470  return false;
471  }
472  ++thisIterator;
473  ++thatIterator;
474  }
475 
476  OGDF_ASSERT(thisIterator == end() && thatIterator == L.end());
477  return true;
478  }
479 
481  bool operator!=(const Array<E, INDEX> &L) const {
482  return !operator==(L);
483  }
484 
486 
491 
493  void swap(INDEX i, INDEX j) {
494  OGDF_ASSERT(m_low <= i);
495  OGDF_ASSERT(i <= m_high);
496  OGDF_ASSERT(m_low <= j);
497  OGDF_ASSERT(j <= m_high);
498 
499  std::swap(m_vpStart[i], m_vpStart[j]);
500  }
501 
503  void permute(INDEX l, INDEX r) {
504  std::minstd_rand rng(randomSeed());
505  permute(l, r, rng);
506  }
507 
509  void permute() {
510  permute(low(), high());
511  }
512 
519  template<class RNG>
520  void permute(INDEX l, INDEX r, RNG &rng);
521 
526  template<class RNG>
527  void permute(RNG &rng) {
528  if(!empty()) {
529  permute(low(), high(), rng);
530  }
531  }
532 
533 
535 
540 
542 
546  inline int binarySearch (const E& e) const {
547  return binarySearch(low(), high(), e, StdComparer<E>());
548  }
549 
551 
555  inline int binarySearch (INDEX l, INDEX r, const E& e) const {
556  return binarySearch(l, r, e, StdComparer<E>());
557  }
558 
560 
564  template<class COMPARER>
565  inline int binarySearch(const E& e, const COMPARER &comp) const {
566  return binarySearch(low(), high(), e, comp);
567  }
568 
570 
574  template<class COMPARER>
575  INDEX binarySearch(INDEX l, INDEX r, const E& e, const COMPARER &comp) const {
576  if(r<l) return low()-1;
577  while(r>l) {
578  INDEX m = (r + l)/2;
579  if(comp.greater(e, m_vpStart[m]))
580  l = m+1;
581  else
582  r = m;
583  }
584  return comp.equal(e, m_vpStart[l]) ? l : low()-1;
585  }
587 
592  inline INDEX linearSearch (const E& e) const {
593  int i;
594  for(i = size(); i-- > 0; )
595  if(e == m_pStart[i]) break;
596  return i+low(); }
597 
599 
604  template<class COMPARER>
605  INDEX linearSearch(const E& e, const COMPARER &comp) const {
606  int i;
607  for(i = size(); i-- > 0; )
608  if(comp.equal(e, m_pStart[i])) break;
609  return i+low();
610  }
611 
613  inline void quicksort() {
614  quicksort(StdComparer<E>());
615  }
616 
618  inline void quicksort(INDEX l, INDEX r) {
619  quicksort(l, r, StdComparer<E>());
620  }
621 
623 
626  template<class COMPARER>
627  inline void quicksort(const COMPARER &comp) {
628  if(low() < high())
629  quicksortInt(m_pStart,m_pStop-1,comp);
630  }
631 
633 
638  template<class COMPARER>
639  void quicksort(INDEX l, INDEX r, const COMPARER &comp) {
640  OGDF_ASSERT(low() <= l);
641  OGDF_ASSERT(l <= high());
642  OGDF_ASSERT(low() <= r);
643  OGDF_ASSERT(r <= high());
644  if(l < r)
645  quicksortInt(m_vpStart+l,m_vpStart+r,comp);
646  }
647 
649 
660  void leftShift(ArrayBuffer<INDEX, INDEX> &ind);
661 
663 
673  void leftShift(ArrayBuffer<INDEX, INDEX> &ind, const E& val) {
674  leftShift(ind);
675  fill(high()-ind.size(),high(),val);
676  }
677 
679 
680  template<class F, class I> friend class ArrayBuffer; // for efficient ArrayBuffer::compact-method
681 
682 private:
684  E *m_pStart;
685  E *m_pStop;
686  INDEX m_low;
687  INDEX m_high;
688 
690  void construct(INDEX a, INDEX b);
691 
693  void initialize();
694 
696  void initialize(const E &x);
697 
699  void initialize(std::initializer_list<E> initList);
700 
702  void deconstruct();
703 
705  void copy(const Array<E,INDEX> &A);
706 
708  void expandArray(INDEX add);
709 
711  template<class COMPARER>
712  static void quicksortInt(E *pL, E *pR, const COMPARER &comp) {
713  size_t s = pR-pL;
714 
715  // use insertion sort for small instances
716  if (s < maxSizeInsertionSort) {
717  for (E *pI = pL+1; pI <= pR; pI++) {
718  E v = *pI;
719  E *pJ = pI;
720  while (--pJ >= pL && comp.less(v,*pJ)) {
721  *(pJ+1) = *pJ;
722  }
723  *(pJ+1) = v;
724  }
725  return;
726  }
727 
728  E *pI = pL, *pJ = pR;
729  E x = *(pL+(s>>1));
730 
731  do {
732  while (comp.less(*pI,x)) pI++;
733  while (comp.less(x,*pJ)) pJ--;
734  if (pI <= pJ) std::swap(*pI++,*pJ--);
735  } while (pI <= pJ);
736 
737  if (pL < pJ) quicksortInt(pL,pJ,comp);
738  if (pI < pR) quicksortInt(pI,pR,comp);
739  }
740 
742 };
743 
744 // enlarges storage for array and moves old entries
745 template<class E, class INDEX>
747 {
748  INDEX sOld = size(), sNew = sOld + add;
749 
750  // expand allocated memory block
751  if (m_pStart != nullptr) {
752  // if the element type is trivially copiable, just use realloc
753 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
754  // g++ 4.8/4.9 does not have is_trivially_copyable, but
755  // clang 3.5 (which is also __GNUC__ < 5) has it
756  if (std::has_trivial_copy_assign<E>::value) {
757 #else
758  if (std::is_trivially_copyable<E>::value) {
759 #endif
760  E *p = static_cast<E *>( realloc(m_pStart, sNew*sizeof(E)) );
761  if (p == nullptr) OGDF_THROW(InsufficientMemoryException);
762  m_pStart = p;
763 
764  // otherwise allocate new block, move elements, and free old block
765  } else {
766  E *p = static_cast<E *>( malloc(sNew*sizeof(E)) );
767  if (p == nullptr) OGDF_THROW(InsufficientMemoryException);
768 
769  for (int i = 0; i < min(sOld,sNew); ++i) {
770  new (&p[i]) E(std::move(m_pStart[i]));
771  }
772 
773  deconstruct();
774  m_pStart = p;
775  }
776 
777  } else {
778  m_pStart = static_cast<E *>( malloc(sNew*sizeof(E)) );
779  if (m_pStart == nullptr) OGDF_THROW(InsufficientMemoryException);
780  }
781 
782  m_vpStart = m_pStart - m_low;
783  m_pStop = m_pStart + sNew;
784  m_high += add;
785 }
786 
787 // enlarges array by add elements and sets new elements to x
788 template<class E, class INDEX>
789 void Array<E,INDEX>::grow(INDEX add, const E &x)
790 {
791  if(add == 0) return;
792 
793  INDEX sOld = size();
794  expandArray(add);
795 
796  // initialize new array entries
797  for (E *pDest = m_pStart+sOld; pDest < m_pStop; pDest++)
798  new (pDest) E(x);
799 }
800 
801 // enlarges array by add elements (initialized with default constructor)
802 template<class E, class INDEX>
803 void Array<E,INDEX>::grow(INDEX add)
804 {
805  if(add == 0) return;
806 
807  INDEX sOld = size();
808  expandArray(add);
809 
810  // initialize new array entries
811  for (E *pDest = m_pStart+sOld; pDest < m_pStop; pDest++)
812  new (pDest) E;
813 }
814 
815 template<class E, class INDEX>
816 void Array<E,INDEX>::construct(INDEX a, INDEX b)
817 {
818  m_low = a; m_high = b;
819  INDEX s = b-a+1;
820 
821  if (s < 1) {
822  m_pStart = m_vpStart = m_pStop = nullptr;
823 
824  } else {
825  m_pStart = static_cast<E *>( malloc(s*sizeof(E)) );
826  if (m_pStart == nullptr) OGDF_THROW(InsufficientMemoryException);
827 
828  m_vpStart = m_pStart - a;
829  m_pStop = m_pStart + s;
830  }
831 }
832 
833 
834 template<class E, class INDEX>
836 {
837  E *pDest = m_pStart;
838  try {
839  for (; pDest < m_pStop; pDest++)
840  new(pDest) E;
841  } catch (...) {
842  while(--pDest >= m_pStart)
843  pDest->~E();
844  free(m_pStart);
845  throw;
846  }
847 }
848 
849 
850 template<class E, class INDEX>
852 {
853  E *pDest = m_pStart;
854  try {
855  for (; pDest < m_pStop; pDest++)
856  new(pDest) E(x);
857  } catch (...) {
858  while(--pDest >= m_pStart)
859  pDest->~E();
860  free(m_pStart);
861  throw;
862  }
863 }
864 
865 
866 template<class E, class INDEX>
867 void Array<E, INDEX>::initialize(std::initializer_list<E> initList)
868 {
869  E *pDest = m_pStart;
870  try {
871  for (const E &x : initList)
872  new(pDest++) E(x);
873  }
874  catch (...) {
875  while (--pDest >= m_pStart)
876  pDest->~E();
877  free(m_pStart);
878  throw;
879  }
880 }
881 
882 
883 template<class E, class INDEX>
885 {
886  if (!std::is_trivially_destructible<E>::value) {
887  for (E *pDest = m_pStart; pDest < m_pStop; pDest++)
888  pDest->~E();
889  }
890  free(m_pStart);
891 }
892 
893 
894 template<class E, class INDEX>
896 {
897  construct(array2.m_low, array2.m_high);
898 
899  if (m_pStart != nullptr) {
900  E *pSrc = array2.m_pStop;
901  E *pDest = m_pStop;
902  while(pDest > m_pStart)
903 #if 0
904  *--pDest = *--pSrc;
905 #endif
906  new (--pDest) E(*--pSrc);
907  }
908 }
909 
910 
911 // permutes array a from a[l] to a[r] randomly
912 template<class E, class INDEX>
913 template<class RNG>
914 void Array<E,INDEX>::permute (INDEX l, INDEX r, RNG &rng)
915 {
916  OGDF_ASSERT(low() <= l);
917  OGDF_ASSERT(l <= high());
918  OGDF_ASSERT(low() <= r);
919  OGDF_ASSERT(r <= high());
920 
921  std::uniform_int_distribution<int> dist(0,r-l);
922 
923  E *pI = m_vpStart+l, *pStart = m_vpStart+l, *pStop = m_vpStart+r;
924  while(pI <= pStop)
925  std::swap( *pI++, *(pStart + dist(rng)) );
926 }
927 
928 
930 template<class E, class INDEX>
931 void print(std::ostream &os, const Array<E,INDEX> &a, char delim = ' ')
932 {
933  for (int i = a.low(); i <= a.high(); i++) {
934  if (i > a.low()) os << delim;
935  os << a[i];
936  }
937 }
938 
939 
941 template<class E, class INDEX>
942 std::ostream &operator<<(std::ostream &os, const ogdf::Array<E,INDEX> &a)
943 {
944  print(os,a);
945  return os;
946 }
947 
948 }
949 
950 #include <ogdf/basic/ArrayBuffer.h>
951 
952 namespace ogdf {
953 
955 template<class E, class INDEX>
957  const INDEX nInd = ind.size();
958  if (nInd == 0) return;
959 
960  OGDF_ASSERT(ind[0] >= low());
961  OGDF_ASSERT(ind[0] <= high());
962 
963  INDEX j, current = ind[0];
964  for (INDEX i = 0; i < nInd - 1; i++) {
965  OGDF_ASSERT(ind[i+1] >= low());
966  OGDF_ASSERT(ind[i+1] <= high());
967 
968  const INDEX last = ind[i+1];
969  for(j = ind[i]+1; j < last; j++)
970  m_vpStart[current++] = m_vpStart[j];
971  }
972 
974  for (j = ind[nInd - 1]+1; j < size(); j++)
975  m_vpStart[current++] = m_vpStart[j];
976 }
977 
978 template<class E, class INDEX>
980  construct(0,-1);
981  A.compactCopy(*this);
982 }
983 
984 }
Array(Array< E, INDEX > &&A)
Creates an array containing the elements of A (move semantics).
Definition: Array.h:255
ArrayReverseIteratorBase< E, isConst > & operator=(const ArrayReverseIteratorBase< E, isConst > &it)
Assignment operator.
Definition: Array.h:103
Declarations for Comparer objects.
Array()
Creates an array with empty index set.
Definition: Array.h:222
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:233
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
bool operator>(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than operator.
Definition: Array.h:173
Declaration of memory manager for allocating small pieces of memory.
int operator-(ArrayReverseIteratorBase< E, isArgConst > &rhs)
Subtraction operator.
Definition: Array.h:165
ArrayReverseIteratorBase< E, isConst > operator--(int)
Decrement operator (postfix).
Definition: Array.h:128
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:575
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:555
void swap(INDEX i, INDEX j)
Swaps the elements at position i and j.
Definition: Array.h:493
void deconstruct()
Deallocates array.
Definition: Array.h:884
void leftShift(ArrayBuffer< INDEX, INDEX > &ind)
Removes the components listed in ind by shifting the remaining components to the left.
Definition: Array.h:956
Declaration and implementation of ArrayBuffer class.
void permute()
Randomly permutes the array.
Definition: Array.h:509
bool operator>=(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than-or-equals operator.
Definition: Array.h:179
void init()
Reinitializes the array to an array with empty index set.
Definition: Array.h:354
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:65
typename std::conditional< isConst, const E, E >::type Elem
The underlying element, depending on isConst.
Definition: Array.h:66
INDEX high() const
Returns the maximal array index.
Definition: Array.h:279
void fill(INDEX i, INDEX j, const E &x)
Sets elements in the intervall [i..j] to x.
Definition: Array.h:390
const_reverse_iterator rend() const
Returns a const reverse iterator to one before the first element.
Definition: Array.h:340
INDEX m_high
The highest index.
Definition: Array.h:687
Elem * m_pX
The pointer to the array element.
Definition: Array.h:69
Further information about the cages of vertices in UML diagrams.
Definition: OrthoRep.h:278
ArrayReverseIteratorBase< E, isConst > & operator-=(const int &rhs)
Compound assignment operator (-).
Definition: Array.h:141
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:639
Array(INDEX a, INDEX b)
Creates an array with index set [a..b].
Definition: Array.h:228
void init(INDEX s)
Reinitializes the array to an array with index set [0..s-1].
Definition: Array.h:363
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:45
INDEX linearSearch(const E &e) const
Performs a linear search for element e.
Definition: Array.h:592
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:153
const_iterator cend() const
Returns a const iterator to one past the last element.
Definition: Array.h:325
int binarySearch(const E &e, const COMPARER &comp) const
Performs a binary search for element e with comparer comp.
Definition: Array.h:565
reverse_iterator rbegin()
Returns an reverse iterator to the last element.
Definition: Array.h:328
Array< E, INDEX > & operator=(Array< E, INDEX > &&A)
Assignment operator (move semantics).
Definition: Array.h:442
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition: Array.h:503
const_reverse_iterator crend() const
Returns a const reverse iterator to one before the first element.
Definition: Array.h:343
void init(INDEX a, INDEX b)
Reinitializes the array to an array with index set [a..b].
Definition: Array.h:369
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:376
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
Definition: Array.h:84
Standard comparer (valid as a static comparer).
Definition: comparer.h:58
ArrayReverseIteratorBase()
Constructs an invalid iterator.
Definition: Array.h:80
bool operator==(const Array< E, INDEX > &L) const
Equality operator.
Definition: Array.h:460
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
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:673
Implementation of the Reverse class for the reverse iteration of containers.
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
Definition: Array.h:895
INDEX m_low
The lowest index.
Definition: Array.h:686
Elem & operator[](std::size_t idx)
Member access operator.
Definition: Array.h:182
bool empty() const
Returns true iff there are no elements in the array.
Definition: Array.h:285
ArrayReverseIteratorBase< E, isConst > & operator+=(const int &rhs)
Compound assignment operator (+).
Definition: Array.h:135
E * m_vpStart
The virtual start of the array (address of A[0]).
Definition: Array.h:683
ArrayReverseIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
Definition: Array.h:109
Random-access reverse iterator based on a pointer to an array element.
Definition: Array.h:47
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:282
static void copy(const T &from, T &to)
Definition: Alg.h:61
Definition of exception classes.
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
Definition: Array.h:789
ArrayReverseIteratorBase(E *pX)
Constructs an iterator that points to E* pX.
Definition: Array.h:73
ArrayIterator< ogdf::OrthoRep::VertexInfoUML * > iterator
Provides a random-access iterator that can read or modify any element in an array.
Definition: Array.h:215
Exception thrown when not enough memory is available to execute an algorithm.
Definition: exceptions.h:213
const_iterator end() const
Returns a const iterator to one past the last element.
Definition: Array.h:322
#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
INDEX size() const
Returns number of elements in the buffer.
Definition: ArrayBuffer.h:122
int binarySearch(const E &e) const
Performs a binary search for element e.
Definition: Array.h:546
bool operator!=(const Array< E, INDEX > &L) const
Inequality operator.
Definition: Array.h:481
iterator begin()
Returns an iterator to the first element.
Definition: Array.h:310
reverse_iterator rend()
Returns an reverse iterator to one before the first element.
Definition: Array.h:337
reference operator[](INDEX i)
Returns a reference to the element at position i.
Definition: Array.h:295
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:422
ArrayReverseIteratorBase(const E *pX)
Constructs an iterator that points to const E* pX.
Definition: Array.h:77
iterator end()
Returns an iterator to one past the last element.
Definition: Array.h:319
void quicksort()
Sorts array using Quicksort.
Definition: Array.h:613
E * ArrayIterator
Definition: Array.h:49
void construct(INDEX a, INDEX b)
Allocates new array with index set [a, ..., b].
Definition: Array.h:816
ArrayReverseIteratorBase< E, isConst > operator+(const int &rhs)
Addition operator with int on the right-hand side.
Definition: Array.h:147
ArrayConstIterator< ogdf::OrthoRep::VertexInfoUML * > const_iterator
Provides a random-access iterator that can read a const element in an array.
Definition: Array.h:213
void compactCopy(Array< E, INDEX > &A2) const
Generates a compact copy holding the current elements.
Definition: ArrayBuffer.h:232
const_reverse_iterator crbegin() const
Returns a const reverse iterator to the last element.
Definition: Array.h:334
const_reverse_iterator rbegin() const
Returns a const reverse iterator to the last element.
Definition: Array.h:331
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition: Array.h:432
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:288
const E * ArrayConstIterator
Definition: Array.h:48
E * m_pStart
The real start of the array (address of A[m_low]).
Definition: Array.h:684
void fill(const E &x)
Sets all elements to x.
Definition: Array.h:383
The namespace for all OGDF objects.
E * m_pStop
Successor of last element (address of A[m_high+1]).
Definition: Array.h:685
void permute(RNG &rng)
Randomly permutes the array using random number generator rng.
Definition: Array.h:527
const_iterator begin() const
Returns a const iterator to the first element.
Definition: Array.h:313
ArrayReverseIteratorBase< E, isConst > operator-(const int &rhs)
Subtraction operator with int on the right-hand side.
Definition: Array.h:159
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition: Array.h:931
void quicksort(INDEX l, INDEX r)
Sorts subarray with index set [l, ..., r] using Quicksort.
Definition: Array.h:618
bool operator!=(const ArrayReverseIteratorBase< E, isConst > &it) const
Inequality operator.
Definition: Array.h:95
const Elem & operator[](std::size_t idx) const
Const member access operator.
Definition: Array.h:185
static void quicksortInt(E *pL, E *pR, const COMPARER &comp)
Internal Quicksort implementation with comparer template.
Definition: Array.h:712
ArrayReverseIteratorBase< E, isConst > & operator--()
Decrement operator (prefix).
Definition: Array.h:122
bool operator==(const ArrayReverseIteratorBase< E, isConst > &it) const
Equality operator.
Definition: Array.h:90
void resize(INDEX newSize)
Resizes (enlarges or shrinks) the array to hold newSize elements.
Definition: Array.h:429
Array(std::initializer_list< E > initList)
Creates an array containing the elements in the initializer list initList.
Definition: Array.h:241
INDEX linearSearch(const E &e, const COMPARER &comp) const
Performs a linear search for element e with comparer comp.
Definition: Array.h:605
Elem & operator*() const
Returns the element this iterator points to.
Definition: Array.h:100
INDEX low() const
Returns the minimal array index.
Definition: Array.h:276
void quicksort(const COMPARER &comp)
Sorts array using Quicksort and a user-defined comparer comp.
Definition: Array.h:627
ArrayReverseIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
Definition: Array.h:115
Array(INDEX s)
Creates an array with index set [0..s-1].
Definition: Array.h:225
void initialize()
Initializes elements with default constructor.
Definition: Array.h:835
Array(const Array< E, INDEX > &A)
Creates an array that is a copy of A.
Definition: Array.h:247
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
~Array()
Destruction.
Definition: Array.h:265
void expandArray(INDEX add)
Used by grow() to enlarge the array.
Definition: Array.h:746
const_iterator cbegin() const
Returns a const iterator to the first element.
Definition: Array.h:316