The parameterized class Array implements dynamic arrays of type E. More...
#include <ogdf/basic/Array.h>
Public Types | |
using | const_iterator = ArrayConstIterator< E > |
Provides a random-access iterator that can read a const element in an array. | |
using | const_reference = const E & |
Provides a reference to a const element stored in an array for reading and performing const operations. | |
using | const_reverse_iterator = ArrayConstReverseIterator< E > |
Provides a reverse random-access iterator that can read a const element in an array. | |
using | iterator = ArrayIterator< E > |
Provides a random-access iterator that can read or modify any element in an array. | |
using | reference = E & |
Provides a reference to an element stored in an array. | |
using | reverse_iterator = ArrayReverseIterator< E > |
Provides a reverse random-access iterator that can read or modify any element in an array. | |
using | value_type = E |
Represents the data type stored in an array element. | |
Public Member Functions | |
Array () | |
Creates an array with empty index set. | |
Array (Array< E, INDEX > &&A) noexcept | |
Creates an array containing the elements of A (move semantics). | |
Array (const Array< E, INDEX > &A) | |
Creates an array that is a copy of A . | |
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. | |
Array (INDEX a, INDEX b) | |
Creates an array with index set [a ..b ]. | |
Array (INDEX a, INDEX b, const E &x) | |
Creates an array with index set [a ..b ] and initializes each element with x . | |
Array (INDEX s) | |
Creates an array with index set [0..s-1 ]. | |
Array (std::initializer_list< E > initList) | |
Creates an array containing the elements in the initializer list initList . | |
~Array () | |
Destruction. | |
Access methods | |
These methods provide access to elements, size, and index range. | |
INDEX | low () const |
Returns the minimal array index. | |
INDEX | high () const |
Returns the maximal array index. | |
INDEX | size () const |
Returns the size (number of elements) of the array. | |
bool | empty () const |
Returns true iff there are no elements in the array. | |
const_reference | operator[] (INDEX i) const |
Returns a reference to the element at position i . | |
reference | operator[] (INDEX i) |
Returns a reference to the element at position i . | |
Iterators | |
These methods return random-access iterators to elements in the array. | |
iterator | begin () |
Returns an iterator to the first element. | |
const_iterator | begin () const |
Returns a const iterator to the first element. | |
const_iterator | cbegin () const |
Returns a const iterator to the first element. | |
iterator | end () |
Returns an iterator to one past the last element. | |
const_iterator | end () const |
Returns a const iterator to one past the last element. | |
const_iterator | cend () const |
Returns a const iterator to one past the last element. | |
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_reverse_iterator | crbegin () const |
Returns a const reverse iterator to the last element. | |
reverse_iterator | rend () |
Returns an reverse iterator to one before the first element. | |
const_reverse_iterator | rend () const |
Returns a const reverse iterator to one before the first element. | |
const_reverse_iterator | crend () const |
Returns a const reverse iterator to one before the first element. | |
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 to an array with empty index set. | |
void | init (INDEX s) |
Reinitializes the array to an array with index set [0..s-1 ]. | |
void | init (INDEX a, INDEX b) |
Reinitializes the array to an array with index set [a ..b ]. | |
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 . | |
void | fill (const E &x) |
Sets all elements to x . | |
void | fill (INDEX i, INDEX j, const E &x) |
Sets elements in the intervall [i ..j ] to x . | |
void | grow (INDEX add, const E &x) |
Enlarges the array by add elements and sets new elements to x . | |
void | grow (INDEX add) |
Enlarges the array by add elements. | |
void | resize (INDEX newSize, const E &x) |
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x . | |
void | resize (INDEX newSize) |
Resizes (enlarges or shrinks) the array to hold newSize elements. | |
Array< E, INDEX > & | operator= (const Array< E, INDEX > &A) |
Assignment operator. | |
Array< E, INDEX > & | operator= (Array< E, INDEX > &&A) |
Assignment operator (move semantics). | |
Comparison | |
bool | operator== (const Array< E, INDEX > &L) const |
Equality operator. | |
bool | operator!= (const Array< E, INDEX > &L) const |
Inequality operator. | |
Reordering | |
These following methods change the order of elements in the array. | |
void | swap (INDEX i, INDEX j) |
Swaps the elements at position i and j . | |
void | permute (INDEX l, INDEX r) |
Randomly permutes the subarray with index set [l ..r ]. | |
void | permute () |
Randomly permutes the array. | |
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 . | |
template<class RNG > | |
void | permute (RNG &rng) |
Randomly permutes the array using random number generator rng . | |
Searching and sorting | |
These methods provide searching for values and sorting the array. | |
int | binarySearch (const E &e) const |
Performs a binary search for element e . | |
int | binarySearch (INDEX l, INDEX r, const E &e) const |
Performs a binary search for element e within the array section [l , ..., r ] . | |
template<class COMPARER > | |
int | binarySearch (const E &e, const COMPARER &comp) const |
Performs a binary search for element e with comparer comp . | |
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 . | |
INDEX | linearSearch (const E &e) const |
Performs a linear search for element e . | |
template<class COMPARER > | |
INDEX | linearSearch (const E &e, const COMPARER &comp) const |
Performs a linear search for element e with comparer comp . | |
void | quicksort () |
Sorts array using Quicksort. | |
void | quicksort (INDEX l, INDEX r) |
Sorts subarray with index set [l , ..., r ] using Quicksort. | |
template<class COMPARER > | |
void | quicksort (const COMPARER &comp) |
Sorts array using Quicksort and a user-defined comparer comp . | |
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 . | |
void | leftShift (ArrayBuffer< INDEX, INDEX > &ind) |
Removes the components listed in ind by shifting the remaining components to the left. | |
void | leftShift (ArrayBuffer< INDEX, INDEX > &ind, const E &val) |
Removes the components listed in ind by shifting the remaining components to the left. | |
Static Public Attributes | |
static const int | maxSizeInsertionSort = 40 |
Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeInsertionSort. | |
Private Member Functions | |
void | construct (INDEX a, INDEX b) |
Allocates new array with index set [a , ..., b ]. | |
void | copy (const Array< E, INDEX > &A) |
Constructs a new array which is a copy of A . | |
void | deconstruct () |
Deallocates array. | |
void | expandArray (INDEX add) |
Used by grow() to enlarge the array. | |
template<typename EE = E, typename std::enable_if< OGDF_TRIVIALLY_COPYABLE< EE >::value, int >::type = 0> | |
void | expandArrayHelper (INDEX sOld, INDEX sNew) |
Used by expandArray() to reallocate the array elements. | |
template<typename EE = E, typename std::enable_if<!OGDF_TRIVIALLY_COPYABLE< EE >::value, int >::type = 0> | |
void | expandArrayHelper (INDEX sOld, INDEX sNew) |
Used by expandArray() to reallocate the array elements. | |
void | initialize () |
Initializes elements with default constructor. | |
void | initialize (const E &x) |
Initializes elements with x . | |
void | initialize (std::initializer_list< E > initList) |
Initializes elements from given initializer list initList . | |
Static Private Member Functions | |
template<class COMPARER > | |
static void | quicksortInt (E *pL, E *pR, const COMPARER &comp) |
Internal Quicksort implementation with comparer template. | |
Private Attributes | |
INDEX | m_high |
The highest index. | |
INDEX | m_low |
The lowest index. | |
E * | m_pStart |
The real start of the array (address of A[m_low]). | |
E * | m_pStop |
Successor of last element (address of A[m_high+1]). | |
E * | m_vpStart |
The virtual start of the array (address of A[0]). | |
Friends | |
template<class F , class I > | |
class | ArrayBuffer |
The parameterized class Array implements dynamic arrays of type E.
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::Array< E, INDEX >::const_iterator = ArrayConstIterator<E> |
using ogdf::Array< E, INDEX >::const_reference = const E& |
using ogdf::Array< E, INDEX >::const_reverse_iterator = ArrayConstReverseIterator<E> |
using ogdf::Array< E, INDEX >::iterator = ArrayIterator<E> |
using ogdf::Array< E, INDEX >::reference = E& |
using ogdf::Array< E, INDEX >::reverse_iterator = ArrayReverseIterator<E> |
using ogdf::Array< E, INDEX >::value_type = E |
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
ogdf::Array< E, INDEX >::Array | ( | const ArrayBuffer< E, INDEX > & | A | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
|
private |
|
inline |
|
inline |
|
private |
|
inline |
|
inline |
|
inline |
|
private |
|
inlineprivate |
Used by expandArray() to reallocate the array elements.
|
inlineprivate |
Used by expandArray() to reallocate the array elements.
|
inline |
|
inline |
void ogdf::Array< E, INDEX >::grow | ( | INDEX | add | ) |
void ogdf::Array< E, INDEX >::grow | ( | INDEX | add, |
const E & | x | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
|
private |
|
private |
void ogdf::Array< E, INDEX >::leftShift | ( | ArrayBuffer< INDEX, INDEX > & | ind | ) |
Removes the components listed in ind
by shifting the remaining components to the left.
shift all items up to the last element of ind
to the left
The "free" positions in the array at the end remain as they are.
This function is mainly used by Abacus. Other uses are supposed to be rare.
Memory management of the removed components must be carefully implemented by the user of this function to avoid memory leaks.
ind | The compenents being removed from the array. |
copy the rest of the buffer
|
inline |
Removes the components listed in ind
by shifting the remaining components to the left.
The "free" positions in the array at the end are filled with val
.
Memory management of the removed components must be carefully implemented by the user of this function to avoid memory leaks.
ind | specifies the components that are removed from the array. |
val | is the value used to fill the positions that become free. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void ogdf::Array< E, INDEX >::permute | ( | INDEX | l, |
INDEX | r, | ||
RNG & | rng | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Sorts the subarray with index set [l
, ..., r
] using Quicksort and a user-defined comparer comp
.
l | is the left-most position in the range to be sorted. |
r | is the right-most position in the range to be sorted. |
comp | is a user-defined comparer; it must be a class providing a less(x,y) method. |
|
inlinestaticprivate |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
|
private |
|
private |
|
private |
|
private |
|
static |
Threshold used by quicksort() such that insertion sort is called for instances smaller than maxSizeInsertionSort.