PSCF v1.1
Public Member Functions | List of all members
Util::ArraySet< Data > Class Template Reference

A set of pointers to a subset of elements of an array. More...

#include <ArraySet.h>

Inheritance diagram for Util::ArraySet< Data >:
Util::PArray< Data >

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...
 
- Public Member Functions inherited from Util::PArray< Data >
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

- Protected Member Functions inherited from Util::PArray< Data >
 PArray ()
 Constructor (protected to prevent instantiation). More...
 
- Protected Attributes inherited from Util::PArray< Data >
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...
 

Detailed Description

template<typename Data>
class Util::ArraySet< Data >

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.

Constructor & Destructor Documentation

◆ ArraySet()

template<typename Data >
Util::ArraySet< Data >::ArraySet

Constructor.

Definition at line 187 of file ArraySet.h.

◆ ~ArraySet()

template<typename Data >
Util::ArraySet< Data >::~ArraySet
virtual

Destructor.

Definition at line 196 of file ArraySet.h.

Member Function Documentation

◆ allocate() [1/2]

template<typename Data >
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.

Parameters
arrayassociated C array of Data objects
capacitynumber of elements in the array

Definition at line 210 of file ArraySet.h.

References UTIL_THROW.

◆ allocate() [2/2]

template<typename Data >
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.

Parameters
arrayassociated Array<Data> container

Definition at line 237 of file ArraySet.h.

References Util::Array< Data >::capacity().

◆ append()

template<typename Data >
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.

Parameters
dataarray element to be added.

Definition at line 244 of file ArraySet.h.

References UTIL_THROW.

◆ remove()

template<typename Data >
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.

Parameters
dataarray element to be added.

Definition at line 268 of file ArraySet.h.

References UTIL_THROW.

◆ pop()

template<typename Data >
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.

◆ clear()

template<typename Data >
void Util::ArraySet< Data >::clear

Reset to empty state.

Definition at line 319 of file ArraySet.h.

◆ index()

template<typename Data >
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.

Parameters
dataarray element of interest.
Returns
current index of pointer to element within this ArraySet.

Definition at line 335 of file ArraySet.h.

References UTIL_THROW.

◆ isAllocated()

template<typename Data >
bool Util::ArraySet< Data >::isAllocated
inline

Return true if the ArraySet is initialized, false otherwise.

Definition at line 348 of file ArraySet.h.

◆ isValid()

template<typename Data >
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.

◆ dump()

template<typename Data >
void Util::ArraySet< Data >::dump ( ) const

Write the internal state of the ArraySet to std::cout.


The documentation for this class was generated from the following file: