55 template<
class E,
class INDEX =
int>
56 class ArrayBuffer :
private Array<E, INDEX> {
71 explicit ArrayBuffer(INDEX
size,
bool autogrow =
true) :
Array<E,INDEX>(size), num(0), growable(autogrow) {}
85 buffer.growable =
true;
174 growable = buffer.growable;
185 growable = buffer.growable;
187 buffer.growable =
true;
193 if (
size() != L.size()) {
197 auto thisIterator =
begin();
198 auto thatIterator = L.begin();
200 while (thisIterator !=
end() && thatIterator != L.end()) {
201 if (*thisIterator != *thatIterator) {
236 for(INDEX i = num; i-- > 0;)
281 memcpy(A2.
m_pStart,this->m_pStart,
sizeof(E)*num);
294 for(i = num; i-- > 0;)
305 template<
class COMPARER>
308 for(i = num; i-- > 0;)
325 template<
class COMPARER>
347 template<
class COMPARER>
396 const INDEX nInd = ind.size();
397 if (nInd == 0)
return;
402 INDEX j, current = ind[0];
403 for (INDEX i = 0; i < nInd - 1; i++) {
407 const INDEX last = ind[i+1];
408 for(j = ind[i]+1; j < last; j++)
413 for (j = ind[nInd - 1]+1; j <
size(); j++)
433 template<
class E,
class INDEX>
436 for (
int i = 0; i < a.size(); i++) {
437 if (i > 0) os << delim;
444 template<
class E,
class INDEX>
445 std::ostream &operator<<(std::ostream &os, const ogdf::ArrayBuffer<E,INDEX> &a)
bool operator!=(const ArrayBuffer< E, INDEX > &L) const
Inequality operator.
typename Array< abacus::Sub *, int >::const_iterator const_iterator
ArrayBuffer< E, INDEX > & operator=(ArrayBuffer< E, INDEX > &&buffer)
Assignment operator (move semantics).
typename Array< abacus::Sub *, int >::const_reverse_iterator const_reverse_iterator
void permute(INDEX l, INDEX r, RNG &rng)
Randomly permutes the subarray with index set [l..r] using random number generator rng...
void init(INDEX size)
Reinitializes the array, clearing it, and allocating memory for up to size elements.
INDEX binarySearch(const E &e, const COMPARER &comp) const
Performs a binary search for element e with comparer comp.
ArrayBuffer(INDEX size, bool autogrow=true)
Creates an empty array buffer, allocating memory for up to size elements; you may specify that the ar...
ArrayBuffer(const ArrayBuffer< E, INDEX > &buffer)
Creates an array buffer that is a copy of buffer.
void clear()
Clears the buffer.
INDEX linearSearch(const E &x) const
Performs a linear search for element x.
The parameterized class Array implements dynamic arrays of type E.
void pop()
Removes the newest element from the buffer.
void permute()
Randomly permutes the array.
void init()
Reinitializes the array to an array with empty index set.
bool operator==(const ArrayBuffer< E, INDEX > &L) const
Equality operator.
const_reverse_iterator rend() const
Returns a const reverse iterator to one before the first element.
E & operator[](INDEX i)
Returns a reference to the element at position i.
INDEX capacity() const
Returns the current capacity of the datastructure. Note that this value is rather irrelevant if the a...
reverse_iterator rend()
Returns a reverse iterator to one before the first element.
typename Array< abacus::Sub *, int >::reverse_iterator reverse_iterator
void push(E e)
Puts a new element in the buffer.
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
void permute()
Randomly permutes the array.
iterator begin()
Returns an iterator to the first element.
INDEX binarySearch(const E &e) const
Performs a binary search for element e.
void quicksort()
Sorts buffer using Quicksort.
const_iterator begin() const
Returns a const iterator to the first element.
Declaration and implementation of Array class and Array algorithms.
const_reverse_iterator rbegin() const
Returns a const reverse iterator to the last element.
void compactCpycon(Array< E, INDEX > &A2) const
Generates a compact copy holding the current elements.
ArrayBuffer< E, INDEX > & operator=(const ArrayBuffer< E, INDEX > &buffer)
Assignment operator.
Standard comparer (valid as a static comparer).
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
void quicksort(const COMPARER &comp)
Sorts buffer using Quicksort and a user-defined comparer comp.
void compactMemcpy(Array< E, INDEX > &A2) const
Generates a compact copy holding the current elements.
bool empty() const
Returns true if the buffer is empty, false otherwise.
bool full() const
Returns true iff the buffer is non-growable and filled.
Random-access reverse iterator based on a pointer to an array element.
INDEX size() const
Returns the size (number of elements) of the array.
ArrayBuffer()
Creates an empty array buffer, without initial memory allocation.
E & top()
Returns the newest element of the buffer.
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
reverse_iterator rbegin()
Returns a reverse iterator to the last element.
ArrayIterator< E > iterator
Provides a random-access iterator that can read or modify any element in an array.
typename Array< abacus::Sub *, int >::iterator iterator
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
void setGrowable(bool _growable)
Sets the flag whether the buffer will automatically expand if the initial size is insufficient...
ArrayBuffer(ArrayBuffer< E, INDEX > &&buffer)
Creates an array buffer containing the elements of buffer (move semantics).
const T & move(const T &v)
INDEX size() const
Returns number of elements in the buffer.
int binarySearch(const E &e) const
Performs a binary search for element e.
iterator begin()
Returns an iterator to the first element.
reverse_iterator rend()
Returns an reverse iterator to one before the first element.
void permute(RNG &rng)
Randomly permutes the array using random number generator rng.
E popRet()
Removes the newest element from the buffer and returns it.
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x...
void setCapacity(INDEX newCapacity)
Changes the capacity of the buffer (independent whether the buffer is growable of not)...
void quicksort()
Sorts array using Quicksort.
INDEX linearSearch(const E &x, const COMPARER &comp) const
Performs a linear search for element x with comparer comp.
ArrayBuffer(const Array< E, INDEX > &source, bool autogrow=true)
Creates an array buffer, initialized by the given array; you may specify that the array should not gr...
ArrayConstIterator< E > const_iterator
Provides a random-access iterator that can read a const element in an array.
void compactCopy(Array< E, INDEX > &A2) const
Generates a compact copy holding the current elements.
iterator end()
Returns an iterator to one past the last element.
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
E * m_pStart
The real start of the array (address of A[m_low]).
The namespace for all OGDF objects.
void leftShift(ArrayBuffer< INDEX, INDEX > &ind)
Removes the components listed in the buffer ind by shifting the remaining components to the left...
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
bool isGrowable() const
Returns whether the buffer will automatically expand if the initial size is insufficient.
void init()
Reinitializes the array, clearing it, and without initial memory allocation.
const E & operator[](INDEX i) const
Returns a reference to the element at position i.
const E & top() const
Returns the newest element of the buffer.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
const_iterator end() const
Returns a const iterator to one past the last element.
INDEX num
The number of elements in the buffer.