Simpatico
v1.10
|
Statically allocated array of pointers to an unordered set.
An SSet is a statically allocated array that holds pointers to a set of objects. It implements the same interface as PArray and FPArray, plus additional remove() and index() methods. As for any pointer array container, the [] operator returns an associated object by reference .
An SSet holds a set of pointers in a contiguous array. The size is the number of pointers now in the container, and the Capacity is the maximum number it can hold. The class is implemented as a wrapper for a statically allocated C array of Capacity elements.
The append method adds a pointer to the end of the sequence. The remove method removes an object from the set, or throws an exception if the object is not found in the set. As for an ArraySet, the remove method repacks the sequence of pointers by moving the last element to the position of the element that is being removed. Removal of an element thus generally changes the order in which the remaining elements are stored.
#include <SSet.h>
Public Member Functions | |
SSet () | |
Default constructor. More... | |
SSet (const SSet< Data, Capacity > &other) | |
Copy constructor. More... | |
SSet< Data, Capacity > & | operator= (const SSet< Data, Capacity > &other) |
Assignment, element by element. More... | |
~SSet () | |
Destructor. More... | |
void | append (Data &data) |
Add an object to the set. More... | |
void | remove (const Data &data) |
Remove an object from the set. More... | |
void | clear () |
Set logical size to zero and nullify all elements. More... | |
int | capacity () const |
Return physical capacity of array. More... | |
int | size () const |
Return logical size of this array. More... | |
bool | isElement (const Data &data) const |
Is an object an element of the set? More... | |
int | index (const Data &data) const |
Return the current index of an object within the set, if any. More... | |
void | begin (PArrayIterator< Data > &iterator) |
Set a PArrayIterator to the beginning of this Array. More... | |
void | begin (ConstPArrayIterator< Data > &iterator) const |
Set a ConstPArrayIterator to the beginning of this Array. More... | |
Data & | operator[] (int i) |
Mimic C array subscripting. More... | |
const Data & | operator[] (int i) const |
Mimic C array subscripting. More... | |
Protected Attributes | |
Data * | ptrs_ [Capacity] |
Array of pointers to Data objects. More... | |
int | size_ |
Logical size of array (number of elements in array). More... | |
|
inline |
Util::SSet< Data, Capacity >::SSet | ( | const SSet< Data, Capacity > & | other | ) |
Copy constructor.
Copies all pointers.
other | the SSet to be copied. |
Definition at line 185 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
Util::SSet< Data, Capacity >::~SSet | ( | ) |
SSet< Data, Capacity > & Util::SSet< Data, Capacity >::operator= | ( | const SSet< Data, Capacity > & | other | ) |
Assignment, element by element.
other | the rhs SSet |
Definition at line 209 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, Util::SSet< Data, Capacity >::size_, and UTIL_THROW.
|
inline |
Add an object to the set.
Appends a pointer to the object to the end of the sequence.
data | Data to add to end of array. |
Definition at line 307 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, Util::SSet< Data, Capacity >::size_, and UTIL_THROW.
void Util::SSet< Data, Capacity >::remove | ( | const Data & | data | ) |
Remove an object from the set.
Removal of an object generally changes the storage order of the remaining objects.
Exception | if object data is not in the Set. |
data | object to be removed. |
Definition at line 332 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, Util::SSet< Data, Capacity >::size_, and UTIL_THROW.
|
inline |
Set logical size to zero and nullify all elements.
Definition at line 320 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
|
inline |
|
inline |
Return logical size of this array.
Definition at line 254 of file SSet.h.
References Util::SSet< Data, Capacity >::size_.
Referenced by McMd::LinkPotentialImpl< Interaction >::atomEnergy().
bool Util::SSet< Data, Capacity >::isElement | ( | const Data & | data | ) | const |
Is an object an element of the set?
data | object of interest. |
Definition at line 364 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
int Util::SSet< Data, Capacity >::index | ( | const Data & | data | ) | const |
Return the current index of an object within the set, if any.
Return the current index of an element within the set, or return -1 if the element is not in the set.
This method returns the current index of the pointer to object data within this SSet, in the range 0 < index < size() - 1. The method returns -1 if data is the object is not in the set.
Throws an exception if data is not in the associated array.
data | object of interest. |
Definition at line 385 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
|
inline |
Set a PArrayIterator to the beginning of this Array.
iterator | PArrayIterator, initialized on output. |
Definition at line 263 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, Util::PArrayIterator< Data >::setCurrent(), Util::PArrayIterator< Data >::setEnd(), and Util::SSet< Data, Capacity >::size_.
Referenced by McMd::LinkMaster::begin().
|
inline |
Set a ConstPArrayIterator to the beginning of this Array.
iterator | ConstPArrayIterator, initialized on output. |
Definition at line 273 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, Util::ConstPArrayIterator< Data >::setCurrent(), Util::ConstPArrayIterator< Data >::setEnd(), and Util::SSet< Data, Capacity >::size_.
|
inline |
Mimic C array subscripting.
i | array index |
Definition at line 283 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
|
inline |
Mimic C array subscripting.
i | array index |
Definition at line 294 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
|
protected |
Array of pointers to Data objects.
Definition at line 164 of file SSet.h.
Referenced by Util::SSet< Data, Capacity >::append(), Util::SSet< Data, Capacity >::begin(), Util::SSet< Data, Capacity >::clear(), Util::SSet< Data, Capacity >::index(), Util::SSet< Data, Capacity >::isElement(), Util::SSet< Data, Capacity >::operator=(), Util::SSet< Data, Capacity >::operator[](), Util::SSet< Data, Capacity >::remove(), and Util::SSet< Data, Capacity >::SSet().
|
protected |
Logical size of array (number of elements in array).
Definition at line 167 of file SSet.h.
Referenced by Util::SSet< Data, Capacity >::append(), Util::SSet< Data, Capacity >::begin(), Util::SSet< Data, Capacity >::clear(), Util::SSet< Data, Capacity >::index(), Util::SSet< Data, Capacity >::isElement(), Util::SSet< Data, Capacity >::operator=(), Util::SSet< Data, Capacity >::operator[](), Util::SSet< Data, Capacity >::remove(), Util::SSet< Data, Capacity >::size(), and Util::SSet< Data, Capacity >::SSet().