Grafalgo
Library of useful data structures and algorithms
|
Data structure that represents a pair of integer sets. More...
#include <SetPair.h>
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 |
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.
grafalgo::SetPair::SetPair | ( | int | n1 | ) |
Constructor for SetPair class.
n1 | defines the set of index values 1..n1 on which the sets are defined |
Definition at line 17 of file SetPair.cpp.
void grafalgo::SetPair::clear | ( | ) | [virtual] |
Remove all elements from inSet.
Implements grafalgo::Adt.
Definition at line 83 of file SetPair.cpp.
void grafalgo::SetPair::copyFrom | ( | const SetPair & | source | ) |
Copy into this SetPair from source.
Definition at line 74 of file SetPair.cpp.
void grafalgo::SetPair::expand | ( | int | size | ) | [virtual] |
Expand the space available for this SetPair.
Rebuilds old value in new space.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 67 of file SetPair.cpp.
int grafalgo::SetPair::firstIn | ( | ) | const [inline] |
int grafalgo::SetPair::firstOut | ( | ) | const [inline] |
void grafalgo::SetPair::freeSpace | ( | ) | [private] |
Free dynamic storage used by list.
Definition at line 49 of file SetPair.cpp.
int grafalgo::SetPair::getNumIn | ( | ) | const [inline] |
int grafalgo::SetPair::getNumOut | ( | ) | const [inline] |
bool grafalgo::SetPair::isIn | ( | int | i | ) | const [inline] |
bool grafalgo::SetPair::isOut | ( | int | i | ) | const [inline] |
int grafalgo::SetPair::lastIn | ( | ) | const [inline] |
int grafalgo::SetPair::lastOut | ( | ) | const [inline] |
void grafalgo::SetPair::makeSpace | ( | int | size | ) | [private] |
Allocate and initialize space for SetPair.
size | is number of index values to provide space for |
Definition at line 25 of file SetPair.cpp.
int grafalgo::SetPair::nextIn | ( | int | i | ) | const [inline] |
int grafalgo::SetPair::nextOut | ( | int | i | ) | const [inline] |
int grafalgo::SetPair::prevIn | ( | int | i | ) | const [inline] |
int grafalgo::SetPair::prevOut | ( | int | i | ) | const [inline] |
void grafalgo::SetPair::resize | ( | int | size | ) | [virtual] |
Resize a SetPair object.
The old value is discarded.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 55 of file SetPair.cpp.
void grafalgo::SetPair::swap | ( | int | ) |
Move an index from one list to the other.
Inserts swapped index at end of the other list
i | is the index to be swapped |
Definition at line 89 of file SetPair.cpp.
string & grafalgo::SetPair::toString | ( | string & | s | ) | const [virtual] |
Create a string representation of a given string.
s | is string used to return value |
Implements grafalgo::Adt.
Definition at line 128 of file SetPair.cpp.