Grafalgo
Library of useful data structures and algorithms
|
Header file for data structure representing a collection of lists defined over index values 1,2,... More...
#include <ListSet.h>
Classes | |
struct | listhdr |
Public Member Functions | |
ListSet (int=26, int=5) | |
Constructor for ListSet. | |
~ListSet () | |
Destructor for ListSet class. | |
void | clear () |
Remove all items from all lists. | |
void | resize (int siz) |
void | resize (int, int) |
Resize a ListSet object. | |
void | expand (int siz) |
void | expand (int, int) |
Expand the space available for this ListSet. | |
void | copyFrom (const ListSet &) |
Copy into list from source. | |
index | next (index) const |
Get the successor of an index. | |
index | first (alist) const |
Get the first index in a list. | |
index | last (alist) const |
Get the last index in a list. | |
bool | member (index) const |
Determine if an index is on some list. | |
bool | empty (alist) const |
Determine if a list is empty. | |
void | addLast (index, alist) |
Add an index to a list. | |
void | addFirst (index, alist) |
Add an index to the front of a list. | |
index | removeFirst (alist) |
Remove the first index from a list. | |
string & | toString (string &) const |
Build a string representation of a set of lists. | |
string & | list2string (alist, string &) const |
Build a string representation of a list. | |
Private Member Functions | |
void | makeSpace (int, int) |
Allocate and initialize space for list. | |
void | freeSpace () |
Free dynamic storage used by list. | |
Private Attributes | |
int | nlst |
listhdr * | lh |
index * | nxt |
Header file for data structure representing a collection of lists defined over index values 1,2,...
Each index can be stored in at most one list. Lists are also numbered 1,2,...
grafalgo::ListSet::ListSet | ( | int | nitems = 26 , |
int | nlists = 5 |
||
) |
Constructor for ListSet.
nitems | defines the set of integers 1..nn1 on which the lists are defined; each integer can be on at most one list |
nlists | specifies the number of lists in the set |
Definition at line 18 of file ListSet.cpp.
grafalgo::ListSet::~ListSet | ( | ) |
Destructor for ListSet class.
Definition at line 23 of file ListSet.cpp.
void grafalgo::ListSet::addFirst | ( | index | i, |
alist | j | ||
) |
Add an index to the front of a list.
i | is an index, which is currently not in any list |
j | is a list number; the index i is added to the front of list j |
Definition at line 114 of file ListSet.cpp.
void grafalgo::ListSet::addLast | ( | index | i, |
alist | j | ||
) |
Add an index to a list.
i | is a list index, which is currently not in any list |
j | is a list number; the index i is added to the end of list j |
Definition at line 92 of file ListSet.cpp.
void grafalgo::ListSet::clear | ( | ) | [virtual] |
Remove all items from all lists.
Implements grafalgo::Adt.
Definition at line 48 of file ListSet.cpp.
void grafalgo::ListSet::copyFrom | ( | const ListSet & | src | ) |
Copy into list from source.
Definition at line 78 of file ListSet.cpp.
bool grafalgo::ListSet::empty | ( | alist | lst | ) | const [inline] |
void grafalgo::ListSet::expand | ( | int | nitems, |
int | nlists | ||
) |
Expand the space available for this ListSet.
Rebuilds old value in new space.
nitems | is the size of the resized object. |
Definition at line 71 of file ListSet.cpp.
index grafalgo::ListSet::first | ( | alist | lst | ) | const [inline] |
void grafalgo::ListSet::freeSpace | ( | ) | [private] |
Free dynamic storage used by list.
Definition at line 45 of file ListSet.cpp.
index grafalgo::ListSet::last | ( | alist | lst | ) | const [inline] |
string & grafalgo::ListSet::list2string | ( | alist | j, |
string & | s | ||
) | const |
Build a string representation of a list.
j | is a list number |
s | is a string in which the result is returned |
Definition at line 126 of file ListSet.cpp.
void grafalgo::ListSet::makeSpace | ( | int | nitems, |
int | nlists | ||
) | [private] |
Allocate and initialize space for list.
nitems | is number of index values to provide space for |
nlists | is the number of lists to provide space for |
Definition at line 29 of file ListSet.cpp.
bool grafalgo::ListSet::member | ( | index | i | ) | const [inline] |
index grafalgo::ListSet::next | ( | index | i | ) | const [inline] |
int grafalgo::ListSet::removeFirst | ( | alist | j | ) |
Remove the first index from a list.
j | is a list number |
Definition at line 103 of file ListSet.cpp.
void grafalgo::ListSet::resize | ( | int | nitems, |
int | nlists | ||
) |
Resize a ListSet object.
The old value is discarded.
nitems | is the number of items in the resized object. |
nlists | is the number of lists in the resized object. |
Definition at line 59 of file ListSet.cpp.
string & grafalgo::ListSet::toString | ( | string & | s | ) | const [virtual] |
Build a string representation of a set of lists.
s | is a string in which the result is returned |
Implements grafalgo::Adt.
Definition at line 142 of file ListSet.cpp.