An array that keeps track of the number of inserted elements; also usable as an efficient stack. More...
#include <ogdf/basic/Array.h>
Inheritance diagram for ogdf::ArrayBuffer< E, INDEX >:Public Member Functions | |
| ArrayBuffer () | |
| Creates an empty array buffer, without initial memory allocation. More... | |
| ArrayBuffer (INDEX size, bool autogrow=true) | |
Creates an empty array buffer, allocating memory for up to size elements; you may specify that the array should not grow automatically. More... | |
| 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 grow. More... | |
| ArrayBuffer (const ArrayBuffer< E, INDEX > &buffer) | |
Creates an array buffer that is a copy of buffer. More... | |
| ArrayBuffer (ArrayBuffer< E, INDEX > &&buffer) | |
Creates an array buffer containing the elements of buffer (move semantics). More... | |
| E * | begin () |
| Returns a pointer to the first element. More... | |
| const E * | begin () const |
| Returns a pointer to the first element. More... | |
| INDEX | binarySearch (const E &e) const |
Performs a binary search for element e. More... | |
| template<class COMPARER > | |
| INDEX | binarySearch (const E &e, const COMPARER &comp) const |
Performs a binary search for element e with comparer comp. More... | |
| INDEX | capacity () const |
| Returns the current capacity of the datastructure. Note that this value is rather irrelevant if the array is growable. More... | |
| void | clear () |
| Clears the buffer. More... | |
| void | compactCopy (Array< E, INDEX > &A2) const |
| Generates a compact copy holding the current elements. More... | |
| void | compactCpycon (Array< E, INDEX > &A2) const |
| Generates a compact copy holding the current elements. More... | |
| void | compactMemcpy (Array< E, INDEX > &A2) const |
| Generates a compact copy holding the current elements. More... | |
| bool | empty () const |
| Returns true if the buffer is empty, false otherwise. More... | |
| E * | end () |
| Returns a pointer to one past the last element. More... | |
| const E * | end () const |
| Returns a pointer to one past the last element. More... | |
| bool | full () const |
| Returns true iff the buffer is non-growable and filled. More... | |
| void | init () |
| Reinitializes the array, clearing it, and without initial memory allocation. More... | |
| void | init (INDEX size) |
Reinitializes the array, clearing it, and allocating memory for up to size elements. More... | |
| bool | isGrowable () const |
| Returns whether the buffer will automatically expand if the initial size is insufficient. More... | |
| void | leftShift (ArrayBuffer< INDEX, INDEX > &ind) |
Removes the components listed in the buffer ind by shifting the remaining components to the left. More... | |
| INDEX | linearSearch (const E &x) const |
Performs a linear search for element x. More... | |
| template<class COMPARER > | |
| INDEX | linearSearch (const E &x, const COMPARER &comp) const |
Performs a linear search for element x with comparer comp. More... | |
| ArrayBuffer< E, INDEX > & | operator= (const ArrayBuffer< E, INDEX > &buffer) |
| Assignment operator. More... | |
| ArrayBuffer< E, INDEX > & | operator= (ArrayBuffer< E, INDEX > &&buffer) |
| Assignment operator (move semantics). More... | |
| const E & | operator[] (INDEX i) const |
Returns a reference to the element at position i. More... | |
| E & | operator[] (INDEX i) |
Returns a reference to the element at position i. More... | |
| void | permute () |
| Randomly permutes the array. More... | |
| void | pop () |
| Removes the newest element from the buffer. More... | |
| E | popRet () |
| Removes the newest element from the buffer and returns it. More... | |
| void | push (E e) |
| Puts a new element in the buffer. More... | |
| void | quicksort () |
| Sorts buffer using Quicksort. More... | |
| template<class COMPARER > | |
| void | quicksort (const COMPARER &comp) |
Sorts buffer using Quicksort and a user-defined comparer comp. More... | |
| E * | rbegin () |
| Returns a pointer to the last element. More... | |
| const E * | rbegin () const |
| Returns a pointer to the last element. More... | |
| E * | rend () |
| Returns a pointer to one before the first element. More... | |
| const E * | rend () const |
| Returns a pointer to one before the first element. More... | |
| void | setCapacity (INDEX newCapacity) |
| Changes the capacity of the buffer (independent whether the buffer is growable of not). More... | |
| void | setGrowable (bool _growable) |
| Sets the flag whether the buffer will automatically expand if the initial size is insufficient. More... | |
| INDEX | size () const |
| Returns number of elements in the buffer. More... | |
| const E & | top () const |
| Returns the newest element of the buffer. More... | |
| E & | top () |
| Returns the newest element of the buffer. More... | |
Private Attributes | |
| bool | growable |
| INDEX | num |
| The number of elements in the buffer. More... | |
Additional Inherited Members | |
Private Types inherited from ogdf::Array< E, INDEX > | |
| using | const_iterator = const E * |
| Provides a random-access iterator that can read a const element in an array. More... | |
| using | const_reference = const E & |
| Provides a reference to a const element stored in an array for reading and performing const operations. More... | |
| using | iterator = E * |
| Provides a random-access iterator that can read or modify any element in an array. More... | |
| using | reference = E & |
| Provides a reference to an element stored in an array. More... | |
| using | value_type = E |
| Represents the data type stored in an array element. More... | |
Private Member Functions inherited from ogdf::Array< E, INDEX > | |
| Array () | |
| Creates an array with empty index set. More... | |
| Array (INDEX s) | |
Creates an array with index set [0..s-1]. More... | |
| Array (INDEX a, INDEX b) | |
Creates an array with index set [a..b]. More... | |
| Array (INDEX a, INDEX b, const E &x) | |
Creates an array with index set [a..b] and initializes each element with x. More... | |
| Array (std::initializer_list< E > initList) | |
Creates an array containing the elements in the initializer list initList. More... | |
| Array (const Array< E, INDEX > &A) | |
Creates an array that is a copy of A. More... | |
| Array (Array< E, INDEX > &&A) | |
Creates an array containing the elements of A (move semantics). More... | |
| 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 capacity) of the buffer. More... | |
| ~Array () | |
| Destruction. More... | |
| INDEX | low () const |
| Returns the minimal array index. More... | |
| INDEX | high () const |
| Returns the maximal array index. More... | |
| INDEX | size () const |
| Returns the size (number of elements) of the array. More... | |
| bool | empty () const |
Returns true iff there are no elements in the array. More... | |
| const_reference | operator[] (INDEX i) const |
Returns a reference to the element at position i. More... | |
| reference | operator[] (INDEX i) |
Returns a reference to the element at position i. More... | |
| iterator | begin () |
| Returns an iterator to the first element. More... | |
| const_iterator | begin () const |
| Returns a const iterator to the first element. More... | |
| const_iterator | cbegin () const |
| Returns a const iterator to the first element. More... | |
| iterator | end () |
| Returns an iterator to one past the last element. More... | |
| const_iterator | end () const |
| Returns a const iterator to one past the last element. More... | |
| const_iterator | cend () const |
| Returns a const iterator to one past the last element. More... | |
| iterator | rbegin () |
| Returns an iterator to the last element. More... | |
| const_iterator | rbegin () const |
| Returns a const iterator to the last element. More... | |
| const_iterator | crbegin () const |
| Returns a const iterator to the last element. More... | |
| iterator | rend () |
| Returns an iterator to one before the first element. More... | |
| const_iterator | rend () const |
| Returns a const iterator to one before the first element. More... | |
| const_iterator | crend () const |
| Returns a const iterator to one before the first element. More... | |
| void | init () |
| Reinitializes the array to an array with empty index set. More... | |
| void | init (INDEX s) |
Reinitializes the array to an array with index set [0..s-1]. More... | |
| void | init (INDEX a, INDEX b) |
Reinitializes the array to an array with index set [a..b]. More... | |
| 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. More... | |
| void | fill (const E &x) |
Sets all elements to x. More... | |
| void | fill (INDEX i, INDEX j, const E &x) |
Sets elements in the intervall [i..j] to x. More... | |
| void | grow (INDEX add, const E &x) |
Enlarges the array by add elements and sets new elements to x. More... | |
| void | grow (INDEX add) |
Enlarges the array by add elements. More... | |
| void | resize (INDEX newSize, const E &x) |
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x. More... | |
| void | resize (INDEX newSize) |
Resizes (enlarges or shrinks) the array to hold newSize elements. More... | |
| Array< E, INDEX > & | operator= (const Array< E, INDEX > &A) |
| Assignment operator. More... | |
| Array< E, INDEX > & | operator= (Array< E, INDEX > &&A) |
| Assignment operator (move semantics). More... | |
| void | swap (INDEX i, INDEX j) |
Swaps the elements at position i and j. More... | |
| void | permute (INDEX l, INDEX r) |
Randomly permutes the subarray with index set [l..r]. More... | |
| void | permute () |
| Randomly permutes the array. More... | |
| template<class RNG > | |
| void | permute (INDEX l, INDEX r, RNG &rng) |
Randomly permutes the subarray with index set [l..r] using random number generator rng. More... | |
| template<class RNG > | |
| void | permute (RNG &rng) |
Randomly permutes the array using random number generator rng. More... | |
| int | binarySearch (const E &e) const |
Performs a binary search for element e. More... | |
| int | binarySearch (INDEX l, INDEX r, const E &e) const |
Performs a binary search for element e within the array section [l, ..., r] . More... | |
| template<class COMPARER > | |
| int | binarySearch (const E &e, const COMPARER &comp) const |
Performs a binary search for element e with comparer comp. More... | |
| template<class COMPARER > | |
| 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. More... | |
| INDEX | linearSearch (const E &e) const |
Performs a linear search for element e. More... | |
| template<class COMPARER > | |
| INDEX | linearSearch (const E &e, const COMPARER &comp) const |
Performs a linear search for element e with comparer comp. More... | |
| void | quicksort () |
| Sorts array using Quicksort. More... | |
| void | quicksort (INDEX l, INDEX r) |
Sorts subarray with index set [l, ..., r] using Quicksort. More... | |
| template<class COMPARER > | |
| void | quicksort (const COMPARER &comp) |
Sorts array using Quicksort and a user-defined comparer comp. More... | |
| template<class COMPARER > | |
| 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. More... | |
| void | leftShift (ArrayBuffer< INDEX, INDEX > &ind) |
Removes the components listed in ind by shifting the remaining components to the left. More... | |
| void | leftShift (ArrayBuffer< INDEX, INDEX > &ind, const E &val) |
Removes the components listed in ind by shifting the remaining components to the left. More... | |
Static Private Attributes inherited from ogdf::Array< E, INDEX > | |
| static const int | maxSizeInsertionSort = 40 |
| Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeInsertionSort. More... | |
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
This is a (by default automatically growable) array (with some initial size s) which starts out being empty. Using stack functions you can put elements into and out of it. The initial array size is automatically expanded if neccessary (unless growing is forbidden), but never automatically shrunken. You may also access the elements it contains using the []-operator. The valid indices are 0..(s - 1).
| E | denotes the element type. |
| INDEX | denotes the index type. The index type must be chosen such that it can express the whole index range of the array instance, as well as its size. The default index type is int, other possible types are short and long long (on 64-bit systems). |
|
inline |
Creates an empty array buffer, without initial memory allocation.
Definition at line 61 of file ArrayBuffer.h.
|
inlineexplicit |
Creates an empty array buffer, allocating memory for up to size elements; you may specify that the array should not grow automatically.
Definition at line 64 of file ArrayBuffer.h.
|
inlineexplicit |
Creates an array buffer, initialized by the given array; you may specify that the array should not grow.
Definition at line 67 of file ArrayBuffer.h.
|
inline |
Creates an array buffer that is a copy of buffer.
Definition at line 70 of file ArrayBuffer.h.
|
inline |
Creates an array buffer containing the elements of buffer (move semantics).
The array buffer buffer is empty (and growable) afterwards.
Definition at line 76 of file ArrayBuffer.h.
|
inline |
Returns a pointer to the first element.
Definition at line 129 of file ArrayBuffer.h.
|
inline |
Returns a pointer to the first element.
Definition at line 132 of file ArrayBuffer.h.
|
inline |
Performs a binary search for element e.
Definition at line 305 of file ArrayBuffer.h.
|
inline |
Performs a binary search for element e with comparer comp.
comp! Definition at line 315 of file ArrayBuffer.h.
|
inline |
Returns the current capacity of the datastructure. Note that this value is rather irrelevant if the array is growable.
Definition at line 120 of file ArrayBuffer.h.
|
inline |
Clears the buffer.
Definition at line 87 of file ArrayBuffer.h.
|
inline |
Generates a compact copy holding the current elements.
Creates a copy of the ArrayBuffer and stores it into the given Array A2. A2 has exactly the neccessary size to hold all elements in the buffer.
This method uses an elementwise operator=. If you need a bitcopy of the buffer, use compactMemcpy() instead; if you need a traditional array copy (using the Array's copy-constructor) use compactCpycon() instead.
Definition at line 199 of file ArrayBuffer.h.
|
inline |
Generates a compact copy holding the current elements.
Creates a copy of the ArrayBuffer and stores it into the given Array A2. A2 has exactly the neccessary size to hold all elements in the buffer
This method uses the Array's copy constructur. If you need a bitcopy of the buffer, use compactMemcpy() instead; if you need a elementwise operator=-copy, use compactCopy() instead.
Definition at line 221 of file ArrayBuffer.h.
|
inline |
Generates a compact copy holding the current elements.
Creates a copy of the ArrayBuffer and stores it into the given Array A2. A2 has exactly the neccessary size to hold all elements in the buffer.
This method uses memcpy. If you need a traditional arraycopy using a copy constructur, use compactCoycon() instead; if you neeed a elementwise operator=-copy, use compactCopy() instead.
Definition at line 244 of file ArrayBuffer.h.
|
inline |
Returns true if the buffer is empty, false otherwise.
Definition at line 111 of file ArrayBuffer.h.
|
inline |
Returns a pointer to one past the last element.
Definition at line 135 of file ArrayBuffer.h.
|
inline |
Returns a pointer to one past the last element.
Definition at line 138 of file ArrayBuffer.h.
|
inline |
Returns true iff the buffer is non-growable and filled.
Definition at line 114 of file ArrayBuffer.h.
|
inline |
Reinitializes the array, clearing it, and without initial memory allocation.
Definition at line 82 of file ArrayBuffer.h.
|
inline |
Reinitializes the array, clearing it, and allocating memory for up to size elements.
Definition at line 84 of file ArrayBuffer.h.
|
inline |
Returns whether the buffer will automatically expand if the initial size is insufficient.
Definition at line 123 of file ArrayBuffer.h.
|
inline |
Removes the components listed in the buffer ind by shifting the remaining components to the left.
The values stored in ind have to be upward sorted. Memory management of the removed components must be carefully implemented by the user of this function to avoid memory leaks.
If this function is compiled with OGDF_DEBUG then it is checked if each value of ind is in the range 0,..., size() -1.
| ind | The numbers of the components being removed. |
copy the rest of the buffer
Definition at line 337 of file ArrayBuffer.h.
|
inline |
Performs a linear search for element x.
Warning: linear running time! Note that the linear search runs from back to front.
Definition at line 259 of file ArrayBuffer.h.
|
inline |
Performs a linear search for element x with comparer comp.
Warning: linear running time! Note that the linear search runs from back to front.
Definition at line 273 of file ArrayBuffer.h.
|
inline |
Assignment operator.
Definition at line 166 of file ArrayBuffer.h.
|
inline |
Assignment operator (move semantics).
The array buffer buffer is empty (and growable) afterwards.
Definition at line 177 of file ArrayBuffer.h.
|
inline |
Returns a reference to the element at position i.
Definition at line 153 of file ArrayBuffer.h.
|
inline |
Returns a reference to the element at position i.
Definition at line 159 of file ArrayBuffer.h.
|
inline |
Randomly permutes the array.
Definition at line 320 of file ArrayBuffer.h.
|
inline |
Removes the newest element from the buffer.
Definition at line 106 of file ArrayBuffer.h.
|
inline |
Removes the newest element from the buffer and returns it.
Definition at line 108 of file ArrayBuffer.h.
|
inline |
Puts a new element in the buffer.
Definition at line 95 of file ArrayBuffer.h.
|
inline |
Sorts buffer using Quicksort.
Definition at line 281 of file ArrayBuffer.h.
|
inline |
Sorts buffer using Quicksort and a user-defined comparer comp.
| comp | is a user-defined comparer; it must provide a less(x,y) method. |
Definition at line 293 of file ArrayBuffer.h.
|
inline |
Returns a pointer to the last element.
Definition at line 141 of file ArrayBuffer.h.
|
inline |
Returns a pointer to the last element.
Definition at line 144 of file ArrayBuffer.h.
|
inline |
Returns a pointer to one before the first element.
Definition at line 147 of file ArrayBuffer.h.
|
inline |
Returns a pointer to one before the first element.
Definition at line 150 of file ArrayBuffer.h.
|
inline |
Changes the capacity of the buffer (independent whether the buffer is growable of not).
If the new capacity if smaller that the currently stored elements, only the first elements (as many as fit) are retained in the buffer. The user is responsible that no memory leaks occur.
Definition at line 366 of file ArrayBuffer.h.
|
inline |
Sets the flag whether the buffer will automatically expand if the initial size is insufficient.
Definition at line 126 of file ArrayBuffer.h.
|
inline |
Returns number of elements in the buffer.
Definition at line 117 of file ArrayBuffer.h.
|
inline |
Returns the newest element of the buffer.
Definition at line 90 of file ArrayBuffer.h.
|
inline |
Returns the newest element of the buffer.
Definition at line 92 of file ArrayBuffer.h.
|
private |
Definition at line 58 of file ArrayBuffer.h.
|
private |
The number of elements in the buffer.
Definition at line 57 of file ArrayBuffer.h.