An array that keeps track of the number of inserted elements; also usable as an efficient stack. More...
#include <ogdf/basic/Array.h>
Public Types | |
using | const_iterator = typename Array< E, INDEX >::const_iterator |
using | const_reverse_iterator = typename Array< E, INDEX >::const_reverse_iterator |
using | iterator = typename Array< E, INDEX >::iterator |
using | key_type = INDEX |
using | reverse_iterator = typename Array< E, INDEX >::reverse_iterator |
using | value_type = E |
Public Member Functions | |
ArrayBuffer () | |
Creates an empty array buffer, without initial memory allocation. More... | |
ArrayBuffer (ArrayBuffer< E, INDEX > &&buffer) | |
Creates an array buffer containing the elements of buffer (move semantics). 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 (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... | |
void | clear () |
Clears the buffer. 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... | |
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... | |
Iterators | |
These methods return random-access iterators to elements in the array. | |
iterator | begin () |
Returns an iterator to the first element. More... | |
const_iterator | begin () 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... | |
reverse_iterator | rbegin () |
Returns a reverse iterator to the last element. More... | |
const_reverse_iterator | rbegin () const |
Returns a const reverse iterator to the last element. More... | |
reverse_iterator | rend () |
Returns a reverse iterator to one before the first element. More... | |
const_reverse_iterator | rend () const |
Returns a const reverse iterator to one before the first element. More... | |
Access methods | |
These methods provide access to elements, size, and index range. | |
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... | |
const E & | top () const |
Returns the newest element of the buffer. More... | |
E & | top () |
Returns the newest element of the buffer. More... | |
void | push (E e) |
Puts a new element in the buffer. More... | |
void | pop () |
Removes the newest element from the buffer. More... | |
E | popRet () |
Removes the newest element from the buffer and returns it. More... | |
bool | empty () const |
Returns true if the buffer is empty, false otherwise. More... | |
bool | full () const |
Returns true iff the buffer is non-growable and filled. More... | |
INDEX | size () const |
Returns number of elements in the buffer. More... | |
INDEX | capacity () const |
Returns the current capacity of the datastructure. Note that this value is rather irrelevant if the array is growable. More... | |
Initialization and assignment | |
These methods can be used to reinitialize or resize the array, or to initialize all elements with a given value. | |
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... | |
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... | |
void | compactCpycon (Array< E, INDEX > &A2) const |
Generates a compact copy holding the current elements. More... | |
template<typename EE = E, typename std::enable_if<!OGDF_TRIVIALLY_COPYABLE< EE >::value, int >::type = 0> | |
void | compactCopy (Array< E, INDEX > &A2) const |
Generates a compact copy holding the current elements. More... | |
template<typename EE = E, typename std::enable_if< OGDF_TRIVIALLY_COPYABLE< EE >::value, int >::type = 0> | |
void | compactCopy (Array< E, INDEX > &A2) const |
Generates a compact copy holding the current elements. More... | |
Comparison | |
bool | operator== (const ArrayBuffer< E, INDEX > &L) const |
Equality operator. More... | |
bool | operator!= (const ArrayBuffer< E, INDEX > &L) const |
Inequality operator. More... | |
Searching and sorting | |
These methods provide searching for values and sorting the array. | |
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... | |
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... | |
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... | |
Reordering | |
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... | |
void | permute (INDEX l, INDEX r) |
Randomly permutes the subarray with index set [l ..r ]. More... | |
void | permute () |
Randomly permutes the array. More... | |
Private Attributes | |
bool | growable |
INDEX | num |
The number of elements in the buffer. 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). |
using ogdf::ArrayBuffer< E, INDEX >::const_iterator = typename Array<E, INDEX>::const_iterator |
Definition at line 71 of file ArrayBuffer.h.
using ogdf::ArrayBuffer< E, INDEX >::const_reverse_iterator = typename Array<E, INDEX>::const_reverse_iterator |
Definition at line 73 of file ArrayBuffer.h.
using ogdf::ArrayBuffer< E, INDEX >::iterator = typename Array<E, INDEX>::iterator |
Definition at line 72 of file ArrayBuffer.h.
using ogdf::ArrayBuffer< E, INDEX >::key_type = INDEX |
Definition at line 69 of file ArrayBuffer.h.
using ogdf::ArrayBuffer< E, INDEX >::reverse_iterator = typename Array<E, INDEX>::reverse_iterator |
Definition at line 74 of file ArrayBuffer.h.
using ogdf::ArrayBuffer< E, INDEX >::value_type = E |
Definition at line 70 of file ArrayBuffer.h.
|
inline |
Creates an empty array buffer, without initial memory allocation.
Definition at line 77 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 81 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 85 of file ArrayBuffer.h.
|
inline |
Creates an array buffer that is a copy of buffer
.
Definition at line 89 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 96 of file ArrayBuffer.h.
|
inline |
Returns an iterator to the first element.
Definition at line 159 of file ArrayBuffer.h.
|
inline |
Returns a const iterator to the first element.
Definition at line 162 of file ArrayBuffer.h.
|
inline |
Performs a binary search for element e
.
Definition at line 452 of file ArrayBuffer.h.
|
inline |
Performs a binary search for element e
with comparer comp
.
comp!
Definition at line 462 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 247 of file ArrayBuffer.h.
|
inline |
Clears the buffer.
Definition at line 103 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 traditional array copy (using the Array's copy-constructor), use compactCpycon() instead.
Definition at line 319 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 array copy (using the Array's copy-constructor), use compactCpycon() instead.
Definition at line 343 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 constructor. If you need an elementwise operator=-copy or a bitcopy, use compactCopy() instead.
Definition at line 295 of file ArrayBuffer.h.
|
inline |
Returns true if the buffer is empty, false otherwise.
Definition at line 238 of file ArrayBuffer.h.
|
inline |
Returns an iterator to one past the last element.
Definition at line 165 of file ArrayBuffer.h.
|
inline |
Returns a const iterator to one past the last element.
Definition at line 168 of file ArrayBuffer.h.
|
inline |
Returns true iff the buffer is non-growable and filled.
Definition at line 241 of file ArrayBuffer.h.
|
inline |
Reinitializes the array, clearing it, and without initial memory allocation.
Definition at line 258 of file ArrayBuffer.h.
|
inline |
Reinitializes the array, clearing it, and allocating memory for up to size
elements.
Definition at line 261 of file ArrayBuffer.h.
|
inline |
Returns whether the buffer will automatically expand if the initial size is insufficient.
Definition at line 147 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 118 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 400 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 417 of file ArrayBuffer.h.
|
inline |
Inequality operator.
Definition at line 384 of file ArrayBuffer.h.
|
inline |
Assignment operator (move semantics).
The array buffer buffer
is empty (and growable) afterwards.
Definition at line 275 of file ArrayBuffer.h.
|
inline |
Assignment operator.
Definition at line 264 of file ArrayBuffer.h.
|
inline |
Equality operator.
Definition at line 363 of file ArrayBuffer.h.
|
inline |
Returns a reference to the element at position i
.
Definition at line 198 of file ArrayBuffer.h.
|
inline |
Returns a reference to the element at position i
.
Definition at line 191 of file ArrayBuffer.h.
|
inline |
Randomly permutes the array.
Definition at line 492 of file ArrayBuffer.h.
|
inline |
Randomly permutes the subarray with index set [l
..r
].
Definition at line 486 of file ArrayBuffer.h.
|
inline |
Randomly permutes the subarray with index set [l
..r
] using random number generator rng
.
l | left border |
r | right border |
rng | random number generator |
Definition at line 475 of file ArrayBuffer.h.
|
inline |
Randomly permutes the array using random number generator rng
.
rng | random number generator |
Definition at line 481 of file ArrayBuffer.h.
|
inline |
Removes the newest element from the buffer.
Definition at line 226 of file ArrayBuffer.h.
|
inline |
Removes the newest element from the buffer and returns it.
Definition at line 232 of file ArrayBuffer.h.
|
inline |
Puts a new element in the buffer.
Definition at line 217 of file ArrayBuffer.h.
|
inline |
Sorts buffer using Quicksort.
Definition at line 428 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 440 of file ArrayBuffer.h.
|
inline |
Returns a reverse iterator to the last element.
Definition at line 171 of file ArrayBuffer.h.
|
inline |
Returns a const reverse iterator to the last element.
Definition at line 174 of file ArrayBuffer.h.
|
inline |
Returns a reverse iterator to one before the first element.
Definition at line 177 of file ArrayBuffer.h.
|
inline |
Returns a const reverse iterator to one before the first element.
Definition at line 180 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 501 of file ArrayBuffer.h.
|
inline |
Sets the flag whether the buffer will automatically expand if the initial size is insufficient.
Definition at line 150 of file ArrayBuffer.h.
|
inline |
Returns number of elements in the buffer.
Definition at line 244 of file ArrayBuffer.h.
|
inline |
Returns the newest element of the buffer.
Definition at line 211 of file ArrayBuffer.h.
|
inline |
Returns the newest element of the buffer.
Definition at line 205 of file ArrayBuffer.h.
|
private |
Definition at line 66 of file ArrayBuffer.h.
|
private |
The number of elements in the buffer.
Definition at line 65 of file ArrayBuffer.h.