PSCF v1.1
|
A set of pointers to a subset of elements of an array. More...
#include <ArraySet.h>
Public Member Functions | |
ArraySet () | |
Constructor. More... | |
virtual | ~ArraySet () |
Destructor. More... | |
void | allocate (Data const *array, int capacity) |
Associate with a C array and allocate required memory. More... | |
void | allocate (Array< Data > const &array) |
Associate with an Array container and allocate required memory. More... | |
Mutators | |
void | append (Data &data) |
Append an element to the set. More... | |
void | remove (Data const &data) |
Remove an element from the set. More... | |
Data & | pop () |
Pop the topmost element from the set. More... | |
void | clear () |
Reset to empty state. More... | |
![]() | |
virtual | ~PArray () |
Destructor. More... | |
int | capacity () const |
Return allocated size. More... | |
int | size () const |
Return logical size. More... | |
void | begin (PArrayIterator< Data > &iterator) const |
Set a PArrayIterator to the beginning of this PArray. More... | |
void | begin (ConstPArrayIterator< Data > &iterator) const |
Set a ConstPArrayIterator to the beginning of this PArray. More... | |
Data & | operator[] (int i) const |
Mimic C array subscripting. More... | |
Accessors | |
int | index (Data const &data) const |
Return the current index of an element within the set, if any. More... | |
bool | isAllocated () const |
Return true if the ArraySet is initialized, false otherwise. More... | |
bool | isValid () const |
Return true if the ArraySet is valid, or throw an exception. More... | |
void | dump () const |
Write the internal state of the ArraySet to std::cout. More... | |
Additional Inherited Members | |
![]() | |
PArray () | |
Constructor (protected to prevent instantiation). More... | |
![]() | |
Data ** | ptrs_ |
PArray of of pointers to Data objects. More... | |
int | capacity_ |
Allocated size of ptrs_ array. More... | |
int | size_ |
Logical size (number of elements with initialized data). More... | |
A set of pointers to a subset of elements of an array.
An ArraySet is a PArray that stores pointers to a subset of the elements of an associated Array container or bare C array. Pointers to the elements of this set are stored in a contiguous sequence, with indices in the range 0, ..., size() - 1. The order in which these pointers are stored is mutable, and generally changes whenever an element is removed.
The append() method appends a pointer to a new element to the end of the sequence and increments the size. The remove() method removes a specified element, then moves the pointer of the last element to the space vacated by the removed element (unless the removed element was the last in the sequence), and decrements the size. The order in which the remaining elements of an ArraySet are stored thus can change whenever an element is removed.
An ArraySet provides O(N) sequential access to all elements of a set, O(1) insertion and deletion, and O(1) access to a randomly chosen element.
Definition at line 46 of file ArraySet.h.
Util::ArraySet< Data >::ArraySet |
Constructor.
Definition at line 187 of file ArraySet.h.
|
virtual |
Destructor.
Definition at line 196 of file ArraySet.h.
void Util::ArraySet< Data >::allocate | ( | Data const * | array, |
int | capacity | ||
) |
Associate with a C array and allocate required memory.
This method associates an ArraySet with a bare C array, and allocates all memory required by the ArraySet.
An ArraySet may only be allocated once. This method throws an Exception if it is called more than once.
array | associated C array of Data objects |
capacity | number of elements in the array |
Definition at line 210 of file ArraySet.h.
References UTIL_THROW.
void Util::ArraySet< Data >::allocate | ( | Array< Data > const & | array | ) |
Associate with an Array container and allocate required memory.
Invokes allocate(&array[0], array.capacity()) internally.
array | associated Array<Data> container |
Definition at line 237 of file ArraySet.h.
References Util::Array< Data >::capacity().
void Util::ArraySet< Data >::append | ( | Data & | data | ) |
Append an element to the set.
This appends a new element to the end of the sequence. This does not change the order of other elements.
data | array element to be added. |
Definition at line 244 of file ArraySet.h.
References UTIL_THROW.
void Util::ArraySet< Data >::remove | ( | Data const & | data | ) |
Remove an element from the set.
Removal of an element generally changes the order of the remaining elements.
Throws an Exception if data is not in this ArraySet.
data | array element to be added. |
Definition at line 268 of file ArraySet.h.
References UTIL_THROW.
Data & Util::ArraySet< Data >::pop |
Pop the topmost element from the set.
Popping the top element reduces the size but does not change the order of the remaining elements.
Definition at line 301 of file ArraySet.h.
References UTIL_THROW.
void Util::ArraySet< Data >::clear |
Reset to empty state.
Definition at line 319 of file ArraySet.h.
int Util::ArraySet< Data >::index | ( | Data const & | data | ) | const |
Return the current index of an element within the set, if any.
Return the current index of an element within the set, or return a negative value -1 if the element is not in the set.
This method returns the current index of the pointer to object data within this ArraySet, in the range 0 < index < size() -1. The method returns -1 if data is an element of the associated array but is not in the ArraySet.
Throws an exception if data is not in the associated array.
data | array element of interest. |
Definition at line 335 of file ArraySet.h.
References UTIL_THROW.
|
inline |
Return true if the ArraySet is initialized, false otherwise.
Definition at line 348 of file ArraySet.h.
bool Util::ArraySet< Data >::isValid |
Return true if the ArraySet is valid, or throw an exception.
Definition at line 355 of file ArraySet.h.
References UTIL_THROW.
void Util::ArraySet< Data >::dump | ( | ) | const |
Write the internal state of the ArraySet to std::cout.