partition  0.1.1
 All Classes Namespaces Functions Variables Pages
Classes | Public Member Functions | Friends | List of all members
partition::Domain< M, V > Class Template Reference

A resizable array of Entry objects having sequentially numbered IDs which may be partitioned across an arbitrary number of associated Groups. More...

#include <partition.hpp>

Classes

class  Entry
 A data pair consisting of an integer ID and a user-provided member of type M. More...
 

Public Member Functions

 Domain (int size=0, int min=0)
 Constructs a Domain with size Entry objects having IDs ranging from min to min + size - 1. More...
 
 Domain (const Domain< M, V > &d)
 Constructs a Domain that is a copy of d. More...
 
template<typename InputIterator >
 Domain (InputIterator first, InputIterator last, int min=0)
 Iterates from first to last and stores a copy of each element in the sequence as a member value of an Entry in this Domain. More...
 
virtual ~Domain ()
 Destructs the Domain, removing all Entry objects from all Groups, calling the destructor for each Entry member, and deallocating all memory currently allocated for internal storage. More...
 
int size () const
 Returns the number of Entry objects in this Domain. More...
 
int min () const
 Returns the lowest numbered ID of this Domain. More...
 
Group< M, V > * getGroup (int id)
 Returns a pointer to the Group to which the Entry with the given id belongs or NULL if that member belongs to no Group. More...
 
const Group< M, V > * getGroup (int id) const
 Returns a pointer to the const Group to which the Entry with the given id belongs or NULL if that member belongs to no Group. More...
 
V & getValue (int id)
 Returns a reference to the value of the Group to which the Entry with the given id belongs. More...
 
const V & getValue (int id) const
 Returns a const reference to the value of the Group to which the Entry with the given id belongs. More...
 
M & getMember (int id)
 Returns a reference to the member object associated with the given id. More...
 
const M & getMember (int id) const
 Returns a const reference to the member object associated with the given id. More...
 
void setMember (int id, const M &m)
 Finds the Entry in this Domain with the given id and sets its member field to m. More...
 
EntrygetEntry (int id)
 Returns a reference to the Entry with the given id. More...
 
const EntrygetEntry (int id) const
 Returns a const reference to the Entry with the given id. More...
 
void addEntry (int id, const M &member=M())
 Similar to setMember but will resize this Domain as neccessary to accomodate the given id. More...
 
void resize (int newSize)
 Equivalent to resize(newSize, min()) More...
 
void resize (int newSize, int newMin)
 Resizes this Domain to contain newSize Entry objects with IDs ranging from newMin to newMin + newSize - 1. More...
 
int high () const
 Returns one plus the highest numbered ID that can be added to the Domain without memory reallocation. More...
 
int low () const
 Returns the lowest numbered ID that can be added to the Domain without memory reallocation. More...
 
int capacity () const
 Returns high() - low(). More...
 
void reserve (int high)
 Equivalent to reserve(newHigh, low()). More...
 
void reserve (int high, int low)
 If either high() < newHigh or low() > newLow, then the internal array is reallocated so that high() is increased to at least newHigh and low() is reduced to at most newLow. More...
 
void compact ()
 If the capacity of the Domain exceeds its size, then compact reallocates internal storage reducing capacity to match the current size of the Domain. More...
 

Friends

class Group< M, V >
 
class Group< M, V >::Iterator
 
class Group< M, V >::ConstIterator
 

Detailed Description

template<typename M, typename V>
class partition::Domain< M, V >

A resizable array of Entry objects having sequentially numbered IDs which may be partitioned across an arbitrary number of associated Groups.

Read the package summary for introductory information about Domain and its related classes.

The ID of the first Entry object (being the Entry with the lowest numbered ID in the Domain's internal array) may have an arbitrary value and is tracked by min(). The ID of the last Entry object (being the Entry with the highest numbered ID in the Domain's internal array) is given by min() + size() - 1. This internal array may be dynamically resized in either direction (either by adding entries after the end of the array which increases the maximum ID or by adding entries before the beginning of the array which decreases the minimum ID).

The methods addEntry(), compact(), reserve(), and resize() (and their overloaded variants) are the operations that can result in memory reallocation. Memory reallocation does not disturb Group membership, but does invalidate all Iterators on all Groups.

Parameters
MThe Entry member type.
VThe Group value type.

Constructor & Destructor Documentation

template<typename M , typename V >
partition::Domain< M, V >::Domain ( int  size = 0,
int  min = 0 
)
inline

Constructs a Domain with size Entry objects having IDs ranging from min to min + size - 1.

All Entry member fields are assigned default values.

Exceptions
PartitionExceptionif size is negative.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_CONSTRUCTOR

If size is zero, the value of min does not affect subsequent behavior of addEntry: min always matches the id of the lowest numbered field in the Domain, so a subsequent call to addEntry with an id of any value N will always reset the min to N. The min value is set however, so a subsequent call to resize(int size) will function with the previously set min value.

template<typename M , typename V >
partition::Domain< M, V >::Domain ( const Domain< M, V > &  d)
inline

Constructs a Domain that is a copy of d.

The capacity of the new Domain matches the size of the original (minimizing storage requirements for the copy).

template<typename M , typename V >
template<typename InputIterator >
partition::Domain< M, V >::Domain ( InputIterator  first,
InputIterator  last,
int  min = 0 
)
inline

Iterates from first to last and stores a copy of each element in the sequence as a member value of an Entry in this Domain.

The first entry is given an ID of min and each subsequent entry is given a sequentially increasing integer id.

template<typename M , typename V >
partition::Domain< M, V >::~Domain ( )
inlinevirtual

Destructs the Domain, removing all Entry objects from all Groups, calling the destructor for each Entry member, and deallocating all memory currently allocated for internal storage.

Member Function Documentation

template<typename M , typename V >
int partition::Domain< M, V >::size ( ) const
inline

Returns the number of Entry objects in this Domain.

template<typename M , typename V >
int partition::Domain< M, V >::min ( ) const
inline

Returns the lowest numbered ID of this Domain.

template<typename M , typename V >
Group< M, V > * partition::Domain< M, V >::getGroup ( int  id)
inline

Returns a pointer to the Group to which the Entry with the given id belongs or NULL if that member belongs to no Group.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
const Group< M, V > * partition::Domain< M, V >::getGroup ( int  id) const
inline

Returns a pointer to the const Group to which the Entry with the given id belongs or NULL if that member belongs to no Group.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
V & partition::Domain< M, V >::getValue ( int  id)
inline

Returns a reference to the value of the Group to which the Entry with the given id belongs.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1; or
if the Entry with the given id belongs to no Group.

These validations are only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
const V & partition::Domain< M, V >::getValue ( int  id) const
inline

Returns a const reference to the value of the Group to which the Entry with the given id belongs.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1; or
if the Entry with the given id belongs to no Group.

These validations are only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
M & partition::Domain< M, V >::getMember ( int  id)
inline

Returns a reference to the member object associated with the given id.

Computational Complexity: Constant.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
const M & partition::Domain< M, V >::getMember ( int  id) const
inline

Returns a const reference to the member object associated with the given id.

Computational Complexity: Constant.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
void partition::Domain< M, V >::setMember ( int  id,
const M &  m 
)
inline

Finds the Entry in this Domain with the given id and sets its member field to m.

Computational Complexity: Constant.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
Domain< M, V >::Entry & partition::Domain< M, V >::getEntry ( int  id)
inline

Returns a reference to the Entry with the given id.

Computational Complexity: Constant.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
const Domain< M, V >::Entry & partition::Domain< M, V >::getEntry ( int  id) const
inline

Returns a const reference to the Entry with the given id.

Computational Complexity: Constant.

Exceptions
PartitionExceptionif id is less than min() or greater than min() + size() - 1.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_ACCESSOR
template<typename M , typename V >
void partition::Domain< M, V >::addEntry ( int  id,
const M &  member = M() 
)
inline

Similar to setMember but will resize this Domain as neccessary to accomodate the given id.

If the Domain has size zero or if id is less than the current min, then min is set to id. If the Domain has capacity zero, then both min and low are set to id.

template<typename M , typename V >
void partition::Domain< M, V >::resize ( int  newSize)
inline

Equivalent to resize(newSize, min())

template<typename M , typename V >
void partition::Domain< M, V >::resize ( int  newSize,
int  newMin 
)
inline

Resizes this Domain to contain newSize Entry objects with IDs ranging from newMin to newMin + newSize - 1.

Previously existing Entry objects having IDs that fall in this newly defined range have both their member fields as well as their group memberships preserved.

Previously existing Entry objects having IDs that fall outside this newly defined range are removed from their Groups, and each such Entry member's destructor is invoked.

If newMin < low() or newMin + newSize > high() then resize also causes a memory reallocation to accomodate the requested Entry range.

Exceptions
PartitionExceptionif newSize is negative.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_MEMORY
template<typename M , typename V >
int partition::Domain< M, V >::high ( ) const
inline

Returns one plus the highest numbered ID that can be added to the Domain without memory reallocation.

template<typename M , typename V >
int partition::Domain< M, V >::low ( ) const
inline

Returns the lowest numbered ID that can be added to the Domain without memory reallocation.

template<typename M , typename V >
int partition::Domain< M, V >::capacity ( ) const
inline

Returns high() - low().

template<typename M , typename V >
void partition::Domain< M, V >::reserve ( int  high)
inline

Equivalent to reserve(newHigh, low()).

template<typename M , typename V >
void partition::Domain< M, V >::reserve ( int  newHigh,
int  newLow 
)
inline

If either high() < newHigh or low() > newLow, then the internal array is reallocated so that high() is increased to at least newHigh and low() is reduced to at most newLow.

After the call, IDs from newLow to newHigh - 1 may subsequently added to the Domain without additional reallocations.

Exceptions
PartitionExceptionif newHigh < newLow.

This validation is only included if the following preprocessor directive evaluates to true during compilation:
#if PARTITION_SL >= PARTITION_ST_DOMAIN_MEMORY
template<typename M , typename V >
void partition::Domain< M, V >::compact ( )
inline

If the capacity of the Domain exceeds its size, then compact reallocates internal storage reducing capacity to match the current size of the Domain.


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