|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
42 #include <initializer_list>
46 #include <type_traits>
50 template<
class E,
bool isConst>
52 template<
class E,
class INDEX>
73 template<
class E,
bool isConst>
105 operator std::conditional<isConst, const E, E>*()
const {
return m_pX; }
182 template<
bool isArgConst>
218 template<
class E,
class INDEX =
int>
253 Array(INDEX a, INDEX b,
const E& x) {
262 Array(std::initializer_list<E> initList) {
263 construct(0, ((INDEX)initList.size()) - 1);
394 void init(INDEX a, INDEX b,
const E& x) {
409 void fill(INDEX i, INDEX j,
const E& x) {
427 void grow(INDEX add,
const E& x);
434 void grow(INDEX add);
485 auto thisIterator =
begin();
486 auto thatIterator = L.
begin();
488 while (thisIterator !=
end() && thatIterator != L.
end()) {
489 if (*thisIterator != *thatIterator) {
536 void permute(INDEX l, INDEX
r, RNG& rng);
579 template<
class COMPARER>
589 template<
class COMPARER>
590 INDEX
binarySearch(INDEX l, INDEX
r,
const E& e,
const COMPARER& comp)
const {
595 INDEX m = (
r + l) / 2;
613 for (i =
size(); i-- > 0;) {
627 template<
class COMPARER>
630 for (i =
size(); i-- > 0;) {
648 template<
class COMPARER>
661 template<
class COMPARER>
704 template<
class F,
class I>
724 void initialize(std::initializer_list<E> initList);
736 template<typename EE = E, typename std::enable_if<OGDF_TRIVIALLY_COPYABLE<EE>::value,
int>
::type = 0>
739 E* p =
static_cast<E*
>(realloc(
m_pStart, sNew *
sizeof(E)));
747 template<typename EE = E, typename std::enable_if<!OGDF_TRIVIALLY_COPYABLE<EE>::value,
int>
::type = 0>
751 E* p =
static_cast<E*
>(malloc(sNew *
sizeof(E)));
756 for (
int i = 0; i < min(sOld, sNew); ++i) {
765 template<
class COMPARER>
771 for (E* pI = pL + 1; pI <= pR; pI++) {
774 while (--pJ >= pL && comp.less(v, *pJ)) {
782 E *pI = pL, *pJ = pR;
783 E x = *(pL + (s >> 1));
786 while (comp.less(*pI, x)) {
789 while (comp.less(x, *pJ)) {
793 std::swap(*pI++, *pJ--);
809 template<
class E,
class INDEX>
811 INDEX sOld = size(), sNew = sOld + add;
814 if (m_pStart !=
nullptr) {
815 expandArrayHelper(sOld, sNew);
817 m_pStart =
static_cast<E*
>(malloc(sNew *
sizeof(E)));
818 if (m_pStart ==
nullptr) {
823 m_vpStart = m_pStart - m_low;
824 m_pStop = m_pStart + sNew;
829 template<
class E,
class INDEX>
839 for (E* pDest = m_pStart + sOld; pDest < m_pStop; pDest++) {
845 template<
class E,
class INDEX>
855 for (E* pDest = m_pStart + sOld; pDest < m_pStop; pDest++) {
860 template<
class E,
class INDEX>
867 m_pStart = m_vpStart = m_pStop =
nullptr;
870 m_pStart =
static_cast<E*
>(malloc(s *
sizeof(E)));
871 if (m_pStart ==
nullptr) {
875 m_vpStart = m_pStart - a;
876 m_pStop = m_pStart + s;
880 template<
class E,
class INDEX>
884 for (; pDest < m_pStop; pDest++) {
888 while (--pDest >= m_pStart) {
896 template<
class E,
class INDEX>
900 for (; pDest < m_pStop; pDest++) {
904 while (--pDest >= m_pStart) {
912 template<
class E,
class INDEX>
916 for (
const E& x : initList) {
920 while (--pDest >= m_pStart) {
928 template<
class E,
class INDEX>
930 if (!std::is_trivially_destructible<E>::value) {
931 for (E* pDest = m_pStart; pDest < m_pStop; pDest++) {
938 template<
class E,
class INDEX>
942 if (m_pStart !=
nullptr) {
945 while (pDest > m_pStart)
949 new (--pDest) E(*--pSrc);
954 template<
class E,
class INDEX>
962 std::uniform_int_distribution<int> dist(0,
r - l);
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)));
971 template<
class E,
class INDEX>
973 for (
int i = a.
low(); i <= a.
high(); i++) {
982 template<
class E,
class INDEX>
993 template<
class E,
class INDEX>
995 const INDEX nInd = ind.
size();
1003 INDEX j, current = ind[0];
1004 for (INDEX i = 0; i < nInd - 1; i++) {
1008 const INDEX last = ind[i + 1];
1009 for (j = ind[i] + 1; j < last; j++) {
1010 m_vpStart[current++] = m_vpStart[j];
1015 for (j = ind[nInd - 1] + 1; j < size(); j++) {
1016 m_vpStart[current++] = m_vpStart[j];
1020 template<
class E,
class INDEX>
1023 A.compactCopy(*
this);
void quicksort(INDEX l, INDEX r)
Sorts subarray with index set [l, ..., r] using Quicksort.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
The namespace for all OGDF objects.
ArrayReverseIteratorBase< E, isConst > & operator=(const ArrayReverseIteratorBase< E, isConst > &it)
Assignment operator.
void resize(INDEX newSize)
Resizes (enlarges or shrinks) the array to hold newSize elements.
E * m_vpStart
The virtual start of the array (address of A[0]).
INDEX m_high
The highest index.
Array(INDEX a, INDEX b, const E &x)
Creates an array with index set [a..b] and initializes each element with x.
Definition of exception classes.
bool operator>(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than operator.
Exception thrown when not enough memory is available to execute an algorithm.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
bool operator!=(const Array< E, INDEX > &L) const
Inequality operator.
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isConst > &it)
Copy constructor. clang10 does not see the above templated one match this case and requires it explic...
ArrayReverseIteratorBase< E, isConst > & operator+=(const int &rhs)
Compound assignment operator (+).
bool operator!=(const ArrayReverseIteratorBase< E, isConst > &it) const
Inequality operator.
Standard comparer (valid as a static comparer).
reference operator[](INDEX i)
Returns a reference to the element at position i.
Array(INDEX s)
Creates an array with index set [0..s-1].
bool operator<(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than operator.
void construct(INDEX a, INDEX b)
Allocates new array with index set [a, ..., b].
void initialize()
Initializes elements with default constructor.
INDEX high() const
Returns the maximal array index.
Array(const Array< E, INDEX > &A)
Creates an array that is a copy of A.
ArrayReverseIteratorBase(E *pX)
Constructs an iterator that points to E* pX.
const PathType & const_reference
Provides a reference to a const element stored in an array for reading and performing const operation...
void swap(INDEX i, INDEX j)
Swaps the elements at position i and j.
void deconstruct()
Deallocates array.
Array(Array< E, INDEX > &&A) noexcept
Creates an array containing the elements of A (move semantics).
Random-access reverse iterator based on a pointer to an array element.
void leftShift(ArrayBuffer< INDEX, INDEX > &ind)
Removes the components listed in ind by shifting the remaining components to the left.
void permute()
Randomly permutes the array.
const Elem & operator[](std::size_t idx) const
Const member access operator.
Array()
Creates an array with empty index set.
ArrayIterator< PathType > iterator
Provides a random-access iterator that can read or modify any element in an array.
ArrayReverseIteratorBase< E, isConst > operator-(const int &rhs)
Subtraction operator with int on the right-hand side.
E * m_pStop
Successor of last element (address of A[m_high+1]).
void init()
Reinitializes the array to an array with empty index set.
const_iterator end() const
Returns a const iterator to one past the last element.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
ArrayReverseIteratorBase< E, isConst > & operator--()
Decrement operator (prefix).
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.
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
ArrayReverseIteratorBase(const E *pX)
Constructs an iterator that points to const E* pX.
void leftShift(ArrayBuffer< INDEX, INDEX > &ind, const E &val)
Removes the components listed in ind by shifting the remaining components to the left.
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
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.
INDEX m_low
The lowest index.
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.
ArrayReverseIteratorBase< E, isConst > operator--(int)
Decrement operator (postfix).
static void quicksortInt(E *pL, E *pR, const COMPARER &comp)
Internal Quicksort implementation with comparer template.
int operator-(ArrayReverseIteratorBase< E, isArgConst > &rhs)
Subtraction operator.
ArrayReverseIteratorBase< E, isConst > operator+(const int &rhs)
Addition operator with int on the right-hand side.
void init(INDEX s)
Reinitializes the array to an array with index set [0..s-1].
ArrayReverseIteratorBase< E, isConst > operator++(int)
Increment operator (postfix).
#define OGDF_THROW(CLASS)
Replacement for throw.
int binarySearch(const E &e, const COMPARER &comp) const
Performs a binary search for element e with comparer comp.
const T & move(const T &v)
The parameterized class Array implements dynamic arrays of type E.
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.
ArrayReverseIteratorBase< E, isConst > & operator++()
Increment operator (prefix).
void expandArrayHelper(INDEX sOld, INDEX sNew)
Used by expandArray() to reallocate the array elements.
reverse_iterator rbegin()
Returns an reverse iterator to the last element.
const_reverse_iterator rbegin() const
Returns a const reverse iterator to the last element.
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
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...
INDEX size() const
Returns number of elements in the buffer.
void fill(const E &x)
Sets all elements to x.
PathType & reference
Provides a reference to an element stored in an array.
void init(INDEX a, INDEX b)
Reinitializes the array to an array with index set [a..b].
ArrayReverseIteratorBase(const ArrayReverseIteratorBase< E, isArgConst > &it)
Constructs an iterator that is a copy of it.
const_iterator begin() const
Returns a const iterator to the first element.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
iterator begin()
Returns an iterator to the first element.
Elem & operator*() const
Returns the element this iterator points to.
reverse_iterator rend()
Returns an reverse iterator to one before the first element.
bool operator==(const Array< E, INDEX > &L) const
Equality operator.
bool operator<=(ArrayReverseIteratorBase< E, isConst > &it) const
Less-than-or-equals operator.
void fill(INDEX i, INDEX j, const E &x)
Sets elements in the intervall [i..j] to x.
iterator end()
Returns an iterator to one past the last element.
void quicksort(const COMPARER &comp)
Sorts array using Quicksort and a user-defined comparer comp.
const_iterator cend() const
Returns a const iterator to one past the last element.
Elem & operator[](std::size_t idx)
Member access operator.
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
ArrayReverseIteratorBase()
Constructs an invalid iterator.
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x.
Array< E, INDEX > & operator=(Array< E, INDEX > &&A)
Assignment operator (move semantics).
E * m_pStart
The real start of the array (address of A[m_low]).
ArrayConstIterator< PathType > const_iterator
Provides a random-access iterator that can read a const element in an array.
Basic declarations, included by all source files.
typename std::conditional< isConst, const E, E >::type Elem
The underlying element, depending on isConst.
void permute(RNG &rng)
Randomly permutes the array using random number generator rng.
int binarySearch(const E &e) const
Performs a binary search for element e.
const_reverse_iterator crbegin() const
Returns a const reverse iterator to the last element.
int binarySearch(INDEX l, INDEX r, const E &e) const
Performs a binary search for element e within the array section [l, ..., r] .
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
bool operator==(const ArrayReverseIteratorBase< E, isConst > &it) const
Equality operator.
INDEX low() const
Returns the minimal array index.
void quicksort()
Sorts array using Quicksort.
INDEX size() const
Returns the size (number of elements) of the array.
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
Elem * m_pX
The pointer to the array element.
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
static const int maxSizeInsertionSort
Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeIn...
bool operator>=(ArrayReverseIteratorBase< E, isConst > &it) const
Greater-than-or-equals operator.
ArrayReverseIteratorBase< E, isConst > & operator-=(const int &rhs)
Compound assignment operator (-).
INDEX linearSearch(const E &e, const COMPARER &comp) const
Performs a linear search for element e with comparer comp.
Declarations for Comparer objects.
Declaration of memory manager for allocating small pieces of memory.
INDEX linearSearch(const E &e) const
Performs a linear search for element e.
PathType value_type
Represents the data type stored in an array element.
Array(INDEX a, INDEX b)
Creates an array with index set [a..b].
bool empty() const
Returns true iff there are no elements in the array.
const_reverse_iterator rend() const
Returns a const reverse iterator to one before the first element.
Array(std::initializer_list< E > initList)
Creates an array containing the elements in the initializer list initList.
const_iterator cbegin() const
Returns a const iterator to the first element.
const E * ArrayConstIterator