Grafalgo
Library of useful data structures and algorithms
|
This class represents a collection of lists defined on a set of unique integers 1..n. More...
#include <ClistSet.h>
Classes | |
struct | lnode |
Public Member Functions | |
ClistSet (int) | |
Constructor for ClistSet. | |
~ClistSet () | |
Destructor for ClistSet. | |
void | clear () |
Clear the data structure, moving all index values into single node lists. | |
void | resize (int) |
Resize a ClistSet object. | |
void | expand (int) |
Expand the space available for this ClistSet. | |
void | copyFrom (const ClistSet &) |
Copy into ClistSet from source. | |
int | suc (index) const |
Get the successor of a list item. | |
int | pred (index) const |
Get the predecessor of a list item. | |
void | join (index, index) |
Join two lists together. | |
void | remove (index) |
Remove an index from its list. | |
string & | toString (string &) const |
Produce a string representation of the object. | |
Private Member Functions | |
void | makeSpace (int) |
Allocate and initialize space for ClistSet. | |
void | freeSpace () |
Free dynamic storage used by ClistSet. | |
Private Attributes | |
struct grafalgo::ClistSet::lnode * | node |
This class represents a collection of lists defined on a set of unique integers 1..n.
Each integer appears in exactly one set at all times. The lists are doubly linked, enabling fast traversal in either direction.
Definition at line 22 of file ClistSet.h.
grafalgo::ClistSet::ClistSet | ( | int | n1 | ) |
Constructor for ClistSet.
n1 | defines the set of integers 1..n on which this object is defined |
Definition at line 15 of file ClistSet.cpp.
void grafalgo::ClistSet::copyFrom | ( | const ClistSet & | source | ) |
Copy into ClistSet from source.
Definition at line 68 of file ClistSet.cpp.
void grafalgo::ClistSet::expand | ( | int | size | ) | [virtual] |
Expand the space available for this ClistSet.
Rebuilds old value in new space.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 53 of file ClistSet.cpp.
void grafalgo::ClistSet::freeSpace | ( | ) | [private] |
Free dynamic storage used by ClistSet.
Definition at line 35 of file ClistSet.cpp.
void grafalgo::ClistSet::join | ( | index | i, |
index | j | ||
) |
Join two lists together.
i | is an index on some list |
j | is an index on some other list Note: the method will corrupt the data structure if i and j already belong to the same list; it's the caller's responsiblity to ensure this doesn't happen |
Definition at line 97 of file ClistSet.cpp.
void grafalgo::ClistSet::makeSpace | ( | int | size | ) | [private] |
Allocate and initialize space for ClistSet.
size | is number of index values to provide space for |
Definition at line 23 of file ClistSet.cpp.
index grafalgo::ClistSet::pred | ( | index | i | ) | const [inline] |
Get the predecessor of a list item.
i | is an index |
Definition at line 63 of file ClistSet.h.
void grafalgo::ClistSet::remove | ( | index | i | ) |
Remove an index from its list.
This method turns the index into a singleton list.
i | is an index |
Definition at line 82 of file ClistSet.cpp.
void grafalgo::ClistSet::resize | ( | int | size | ) | [virtual] |
Resize a ClistSet object.
The old value is discarded.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 41 of file ClistSet.cpp.
index grafalgo::ClistSet::suc | ( | index | i | ) | const [inline] |
Get the successor of a list item.
i | is an index |
Definition at line 55 of file ClistSet.h.
string & grafalgo::ClistSet::toString | ( | string & | s | ) | const [virtual] |
Produce a string representation of the object.
s | is a string in which the result will be returned |
Implements grafalgo::Adt.
Definition at line 109 of file ClistSet.cpp.