45template<
class E,
class INDEX>
48template<
class E,
bool isConst>
49class ArrayReverseIteratorBase;
68template<
class E,
bool isConst>
73 using Elem =
typename std::conditional<isConst, const E, E>::type;
100 operator std::conditional<isConst, const E, E>*()
const {
return m_pX; }
177 template<
bool isArgConst>
213template<
class E,
class INDEX =
int>
476 if (
size() !=
L.size()) {
574 template<
class COMPARER>
584 template<
class COMPARER>
608 for (i =
size(); i-- > 0;) {
622 template<
class COMPARER>
625 for (i =
size(); i-- > 0;) {
643 template<
class COMPARER>
656 template<
class COMPARER>
699 template<
class F,
class I>
734 E* p =
static_cast<E*
>(realloc(
m_pStart,
sNew *
sizeof(E)));
746 E* p =
static_cast<E*
>(
malloc(
sNew *
sizeof(E)));
751 for (
int i = 0; i < min(
sOld,
sNew); ++i) {
752 new (&p[i]) E(std::move(
m_pStart[i]));
760 template<
class COMPARER>
778 E x = *(
pL + (s >> 1));
781 while (
comp.less(*
pI, x)) {
784 while (
comp.less(x, *
pJ)) {
788 std::swap(*
pI++, *
pJ--);
804template<
class E,
class INDEX>
809 if (m_pStart !=
nullptr) {
812 m_pStart =
static_cast<E*
>(
malloc(
sNew *
sizeof(E)));
813 if (m_pStart ==
nullptr) {
818 m_vpStart = m_pStart - m_low;
819 m_pStop = m_pStart +
sNew;
824template<
class E,
class INDEX>
840template<
class E,
class INDEX>
855template<
class E,
class INDEX>
862 m_pStart = m_vpStart = m_pStop =
nullptr;
865 m_pStart =
static_cast<E*
>(
malloc(s *
sizeof(E)));
866 if (m_pStart ==
nullptr) {
870 m_vpStart = m_pStart - a;
871 m_pStop = m_pStart + s;
875template<
class E,
class INDEX>
883 while (--
pDest >= m_pStart) {
891template<
class E,
class INDEX>
899 while (--
pDest >= m_pStart) {
907template<
class E,
class INDEX>
915 while (--
pDest >= m_pStart) {
923template<
class E,
class INDEX>
925 if (!std::is_trivially_destructible<E>::value) {
933template<
class E,
class INDEX>
937 if (m_pStart !=
nullptr) {
940 while (
pDest > m_pStart)
949template<
class E,
class INDEX>
957 std::uniform_int_distribution<int>
dist(0,
r -
l);
966template<
class E,
class INDEX>
968 for (
int i = a.
low(); i <= a.
high(); i++) {
977template<
class E,
class INDEX>
990template<
class E,
class INDEX>
1006 for (
j =
ind[i] + 1;
j < last;
j++) {
1007 m_vpStart[
current++] = m_vpStart[
j];
1012 for (
j =
ind[
nInd - 1] + 1;
j < size();
j++) {
1013 m_vpStart[
current++] = m_vpStart[
j];
1017template<
class E,
class INDEX>
1020 A.compactCopy(*
this);
Declaration and implementation of ArrayBuffer class.
Implementation of the Reverse class for the reverse iteration of containers.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
The parameterized class Array implements dynamic arrays of type E.
iterator begin()
Returns an iterator to the first element.
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
void quicksort(const COMPARER &comp)
Sorts array using Quicksort and a user-defined comparer comp.
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x.
reference operator[](INDEX i)
Returns a reference to the element at position i.
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
void deconstruct()
Deallocates array.
void swap(INDEX i, INDEX j)
Swaps the elements at position i and j.
const_reverse_iterator rend() const
Returns a const reverse iterator to one before the first element.
E * m_pStop
Successor of last element (address of A[m_high+1]).
static const int maxSizeInsertionSort
Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeIn...
INDEX high() const
Returns the maximal array index.
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
reverse_iterator rbegin()
Returns an reverse iterator to the last element.
INDEX m_low
The lowest index.
reverse_iterator rend()
Returns an reverse iterator to one before the first element.
INDEX linearSearch(const E &e) const
Performs a linear search for element e.
void leftShift(ArrayBuffer< INDEX, INDEX > &ind)
Removes the components listed in ind by shifting the remaining components to the left.
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...
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.
const_iterator cend() const
Returns a const iterator to one past the last element.
static void quicksortInt(E *pL, E *pR, const COMPARER &comp)
Internal Quicksort implementation with comparer template.
const_iterator begin() const
Returns a const iterator to the first element.
void grow(INDEX add)
Enlarges the array by add elements.
int binarySearch(const E &e, const COMPARER &comp) const
Performs a binary search for element e with comparer comp.
void permute(RNG &rng)
Randomly permutes the array using random number generator rng.
void construct(INDEX a, INDEX b)
Allocates new array with index set [a, ..., b].
iterator end()
Returns an iterator to one past the last element.
bool empty() const
Returns true iff there are no elements in the array.
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.
void init()
Reinitializes the array to an array with empty index set.
void fill(const E &x)
Sets all elements to x.
void initialize(const E &x)
Initializes elements with x.
void quicksort()
Sorts array using Quicksort.
void expandArray(INDEX add)
Used by grow() to enlarge the array.
const_reverse_iterator crend() const
Returns a const reverse iterator to one before the first element.
void init(INDEX a, INDEX b)
Reinitializes the array to an array with index set [a..b].
void expandArrayHelper(INDEX sOld, INDEX sNew)
Used by expandArray() to reallocate the array elements.
Array(INDEX a, INDEX b, const E &x)
Creates an array with index set [a..b] and initializes each element with x.
bool operator!=(const Array< E, INDEX > &L) const
Inequality operator.
E & reference
Provides a reference to an element stored in an array.
int binarySearch(const E &e) const
Performs a binary search for element e.
ArrayConstIterator< E > const_iterator
Provides a random-access iterator that can read a const element in an array.
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
INDEX low() const
Returns the minimal array index.
void initialize()
Initializes elements with default constructor.
void permute()
Randomly permutes the array.
void quicksort(INDEX l, INDEX r)
Sorts subarray with index set [l, ..., r] using Quicksort.
INDEX size() const
Returns the size (number of elements) of the array.
int binarySearch(INDEX l, INDEX r, const E &e) const
Performs a binary search for element e within the array section [l, ..., r] .
const_reverse_iterator crbegin() const
Returns a const reverse iterator to the last element.
void leftShift(ArrayBuffer< INDEX, INDEX > &ind, const E &val)
Removes the components listed in ind by shifting the remaining components to the left.
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
void resize(INDEX newSize)
Resizes (enlarges or shrinks) the array to hold newSize elements.
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.
const_iterator end() const
Returns a const iterator to one past the last element.
void fill(INDEX i, INDEX j, const E &x)
Sets elements in the intervall [i..j] to x.
Array(Array< E, INDEX > &&A)
Creates an array containing the elements of A (move semantics).
INDEX m_high
The highest index.
void initialize(std::initializer_list< E > initList)
Initializes elements from given initializer list initList.
ArrayIterator< E > iterator
Provides a random-access iterator that can read or modify any element in an array.
bool operator==(const Array< E, INDEX > &L) const
Equality operator.
Array(INDEX a, INDEX b)
Creates an array with index set [a..b].
E * m_vpStart
The virtual start of the array (address of A[0]).
E * m_pStart
The real start of the array (address of A[m_low]).
Array()
Creates an array with empty index set.
E value_type
Represents the data type stored in an array element.
Array(const Array< E, INDEX > &A)
Creates an array that is a copy of A.
Array(INDEX s)
Creates an array with index set [0..s-1].
const_iterator cbegin() const
Returns a const iterator to the first element.
void init(INDEX s)
Reinitializes the array to an array with index set [0..s-1].
void permute(INDEX l, INDEX r, RNG &rng)
Randomly permutes the subarray with index set [l..r] using random number generator rng.
INDEX linearSearch(const E &e, const COMPARER &comp) const
Performs a linear search for element e with comparer comp.
const E & const_reference
Provides a reference to a const element stored in an array for reading and performing const operation...
Array< E, INDEX > & operator=(Array< E, INDEX > &&A)
Assignment operator (move semantics).
const_reverse_iterator rbegin() const
Returns a const reverse iterator to the last element.
Array(std::initializer_list< E > initList)
Creates an array containing the elements in the initializer list initList.
Random-access reverse iterator based on a pointer to an array element.
bool operator<=(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than-or-equals operator.
ArrayReverseIteratorBase< E, isConst > operator-(const int &rhs)
Subtraction operator with int on the right-hand side.
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...
const Elem & operator[](std::size_t idx) const
Const member access operator.
bool operator!=(const ArrayReverseIteratorBase< E, isConst > &it) const
Inequality operator.
ArrayReverseIteratorBase()
Constructs an invalid iterator.
int operator-(ArrayReverseIteratorBase< E, isArgConst > &rhs)
Subtraction operator.
ArrayReverseIteratorBase(E *pX)
Constructs an iterator that points to E* pX.
ArrayReverseIteratorBase(const E *pX)
Constructs an iterator that points to const E* pX.
ArrayReverseIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
bool operator>=(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than-or-equals operator.
ArrayReverseIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isConst > &it)
Copy constructor. clang10 does not see the above templated one match this case and requires it explic...
bool operator==(const ArrayReverseIteratorBase< E, isConst > &it) const
Equality operator.
ArrayReverseIteratorBase< E, isConst > & operator=(const ArrayReverseIteratorBase< E, isConst > &it)
Assignment operator.
ArrayReverseIteratorBase< E, isConst > operator+(const int &rhs)
Addition operator with int on the right-hand side.
Elem * m_pX
The pointer to the array element.
bool operator>(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than operator.
ArrayReverseIteratorBase< E, isConst > & operator--()
Decrement operator (prefix).
Elem & operator*() const
Returns the element this iterator points to.
ArrayReverseIteratorBase< E, isConst > operator--(int)
Decrement operator (postfix).
Elem & operator[](std::size_t idx)
Member access operator.
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
ArrayReverseIteratorBase< E, isConst > & operator+=(const int &rhs)
Compound assignment operator (+).
ArrayReverseIteratorBase< E, isConst > & operator-=(const int &rhs)
Compound assignment operator (-).
bool operator<(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than operator.
typename std::conditional< isConst, const E, E >::type Elem
The underlying element, depending on isConst.
Exception thrown when not enough memory is available to execute an algorithm.
Standard comparer (valid as a static comparer).
Declarations for Comparer objects.
Definition of exception classes.
#define OGDF_THROW(CLASS)
Replacement for throw.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
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.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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.
const E * ArrayConstIterator
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.