55 template<
class E,
class INDEX =
int>
56 class ArrayBuffer :
private Array<E, INDEX> {
64 explicit ArrayBuffer(INDEX
size,
bool autogrow =
true) :
Array<E,INDEX>(size), num(0), growable(autogrow) {}
78 buffer.growable =
true;
169 growable = buffer.growable;
180 growable = buffer.growable;
182 buffer.growable =
true;
203 for(INDEX i = num; i-- > 0;)
248 memcpy(A2.
m_pStart,this->m_pStart,
sizeof(E)*num);
261 for(i = num; i-- > 0;)
272 template<
class COMPARER>
275 for(i = num; i-- > 0;)
292 template<
class COMPARER>
314 template<
class COMPARER>
338 const INDEX nInd = ind.size();
339 if (nInd == 0)
return;
344 INDEX j, current = ind[0];
345 for (INDEX i = 0; i < nInd - 1; i++) {
349 const INDEX last = ind[i+1];
350 for(j = ind[i]+1; j < last; j++)
355 for (j = ind[nInd - 1]+1; j <
size(); j++)
375 template<
class E,
class INDEX>
378 for (
int i = 0; i < a.size(); i++) {
379 if (i > 0) os << delim;
386 template<
class E,
class INDEX>
387 ostream &operator<<(ostream &os, const ogdf::ArrayBuffer<E,INDEX> &a)
ArrayBuffer< E, INDEX > & operator=(ArrayBuffer< E, INDEX > &&buffer)
Assignment operator (move semantics).
void init(INDEX size)
Reinitializes the array, clearing it, and allocating memory for up to size elements.
Exception thrown when preconditions are violated.
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.
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...
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...
E * rbegin()
Returns a pointer to the last element.
void permute()
Randomly permutes the array.
INDEX binarySearch(const E &e) const
Performs a binary search for element e.
void quicksort()
Sorts buffer using Quicksort.
const E * end() const
Returns a pointer to one past the last element.
Declaration and implementation of Array class and Array algorithms.
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).
datastructure is already full
E * rend()
Returns a pointer to one before the first element.
void copy(const Array< E, INDEX > &A)
Constructs a new array which is a copy of A.
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.
INDEX size() const
Returns the size (number of elements) of the array.
const E * rbegin() const
Returns a pointer to the last element.
ArrayBuffer()
Creates an empty array buffer, without initial memory allocation.
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
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.
iterator rend()
Returns an iterator to one before the first element.
#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.
E popRet()
Removes the newest element from the buffer and returns it.
const E * begin() const
Returns a pointer to the first element.
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...
const E * rend() const
Returns a pointer to one before the first element.
void compactCopy(Array< E, INDEX > &A2) const
Generates a compact copy holding the current elements.
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...
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.
E * begin()
Returns a pointer to the first element.
void print(ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
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.
E * end()
Returns a pointer to one past the last element.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
INDEX num
The number of elements in the buffer.