Grafalgo
Library of useful data structures and algorithms
grafalgo::SetPair Class Reference

Data structure that represents a pair of integer sets. More...

#include <SetPair.h>

Inheritance diagram for grafalgo::SetPair:
Collaboration diagram for grafalgo::SetPair:

List of all members.

Public Member Functions

 SetPair (int)
 Constructor for SetPair class.
 ~SetPair ()
 Destructor for SetPair class.
void clear ()
 Remove all elements from inSet.
void resize (int)
 Resize a SetPair object.
void expand (int)
 Expand the space available for this SetPair.
void copyFrom (const SetPair &)
 Copy into this SetPair from source.
bool isIn (int) const
 Determine if an integer belongs to the "in-set".
bool isOut (int) const
 Determine if an integer belongs to the "out-set".
int firstIn () const
 Get the first int in the in-set.
int firstOut () const
 Get the first int in the out-set.
int lastIn () const
 Get the last int in the in-set.
int lastOut () const
 Get the first int in the out-set.
int nextIn (int) const
 Get the next value in the inlist.
int nextOut (int) const
 Get the next value in the outlist.
int prevIn (int) const
 Get the previous value in the inlist.
int prevOut (int) const
 Get the previous value in the outlist.
int getNumIn () const
 Get the number of elements in the "in-set".
int getNumOut () const
 Get the number of elements in the "in-set".
void swap (int)
 Move an index from one list to the other.
string & toString (string &) const
 Create a string representation of a given string.

Private Member Functions

void makeSpace (int)
 Allocate and initialize space for SetPair.
void freeSpace ()
 Free dynamic storage used by list.

Private Attributes

int numIn
 number of elements in in-set
int numOut
 number of elements in out-set
int inHead
 first value in the in-set
int inTail
 last value in the in-set
int outHead
 first value in the out-set
int outTail
 last value in the out-set
int * nxt
 nxt[i] defines next value after i
int * prv
 prv[i] defines value preceding i

Detailed Description

Data structure that represents a pair of integer sets.

The integer values are stored in a limited range 1..n and each integer is always in one of the two sets. The sets are referred to as "in" and "out" can can be accessed using the provided methods. The only way to modify the data structure is to move an item from one set to the other.

Definition at line 27 of file SetPair.h.


Constructor & Destructor Documentation

grafalgo::SetPair::SetPair ( int  n1)

Constructor for SetPair class.

Parameters:
n1defines the set of index values 1..n1 on which the sets are defined

Definition at line 17 of file SetPair.cpp.

Here is the call graph for this function:


Member Function Documentation

void grafalgo::SetPair::clear ( ) [virtual]

Remove all elements from inSet.

Implements grafalgo::Adt.

Definition at line 83 of file SetPair.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void grafalgo::SetPair::copyFrom ( const SetPair source)

Copy into this SetPair from source.

Definition at line 74 of file SetPair.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void grafalgo::SetPair::expand ( int  size) [virtual]

Expand the space available for this SetPair.

Rebuilds old value in new space.

Parameters:
sizeis the size of the resized object.

Implements grafalgo::Adt.

Definition at line 67 of file SetPair.cpp.

Here is the call graph for this function:

int grafalgo::SetPair::firstIn ( ) const [inline]

Get the first int in the in-set.

Returns:
the first value on the in-set or 0 if the list is empty.

Definition at line 105 of file SetPair.h.

Here is the caller graph for this function:

int grafalgo::SetPair::firstOut ( ) const [inline]

Get the first int in the out-set.

Returns:
the first value on the out-set or 0 if the list is empty.

Definition at line 110 of file SetPair.h.

Here is the caller graph for this function:

void grafalgo::SetPair::freeSpace ( ) [private]

Free dynamic storage used by list.

Definition at line 49 of file SetPair.cpp.

Here is the caller graph for this function:

int grafalgo::SetPair::getNumIn ( ) const [inline]

Get the number of elements in the "in-set".

Returns:
the number of elements in the in-set

Definition at line 95 of file SetPair.h.

Here is the caller graph for this function:

int grafalgo::SetPair::getNumOut ( ) const [inline]

Get the number of elements in the "in-set".

Returns:
the number of elements in the in-set

Definition at line 100 of file SetPair.h.

bool grafalgo::SetPair::isIn ( int  i) const [inline]

Determine if an integer belongs to the "in-set".

Parameters:
isis an integer in the range of values supported by the object
returntrue if i is a member of the "in-set", else false.

Definition at line 80 of file SetPair.h.

Here is the caller graph for this function:

bool grafalgo::SetPair::isOut ( int  i) const [inline]

Determine if an integer belongs to the "out-set".

Parameters:
isis an integer in the range of values supported by the object
returntrue if i is a member of the "out-set", else false.

Definition at line 88 of file SetPair.h.

Here is the caller graph for this function:

int grafalgo::SetPair::lastIn ( ) const [inline]

Get the last int in the in-set.

Returns:
the last value on the in-set or 0 if the list is empty.

Definition at line 115 of file SetPair.h.

Here is the caller graph for this function:

int grafalgo::SetPair::lastOut ( ) const [inline]

Get the first int in the out-set.

Returns:
the last value on the out-set or 0 if the list is empty.

Definition at line 120 of file SetPair.h.

Here is the caller graph for this function:

void grafalgo::SetPair::makeSpace ( int  size) [private]

Allocate and initialize space for SetPair.

Parameters:
sizeis number of index values to provide space for

Definition at line 25 of file SetPair.cpp.

Here is the caller graph for this function:

int grafalgo::SetPair::nextIn ( int  i) const [inline]

Get the next value in the inlist.

Parameters:
iis the "current" value
Returns:
the next value on the in-set or 0 if no more values

Definition at line 126 of file SetPair.h.

Here is the caller graph for this function:

int grafalgo::SetPair::nextOut ( int  i) const [inline]

Get the next value in the outlist.

Parameters:
iis the "current" value
Returns:
the next value on the out-set or 0 if no more values

Definition at line 134 of file SetPair.h.

Here is the caller graph for this function:

int grafalgo::SetPair::prevIn ( int  i) const [inline]

Get the previous value in the inlist.

Parameters:
iis the "current" value
Returns:
the previous value on the in-set or 0 if no more values

Definition at line 142 of file SetPair.h.

int grafalgo::SetPair::prevOut ( int  i) const [inline]

Get the previous value in the outlist.

Parameters:
iis the "current" value
Returns:
the previous value on the out-set or 0 if no more values

Definition at line 150 of file SetPair.h.

void grafalgo::SetPair::resize ( int  size) [virtual]

Resize a SetPair object.

The old value is discarded.

Parameters:
sizeis the size of the resized object.

Implements grafalgo::Adt.

Definition at line 55 of file SetPair.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void grafalgo::SetPair::swap ( int  )

Move an index from one list to the other.

Inserts swapped index at end of the other list

Parameters:
iis the index to be swapped

Definition at line 89 of file SetPair.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

string & grafalgo::SetPair::toString ( string &  s) const [virtual]

Create a string representation of a given string.

Parameters:
sis string used to return value
Returns:
a reference to s

Implements grafalgo::Adt.

Definition at line 128 of file SetPair.cpp.

Here is the call graph for this function:


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Friends