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

Data structure representing a list of indexes. More...

#include <List.h>

Inheritance diagram for grafalgo::List:
Collaboration diagram for grafalgo::List:

List of all members.

Public Member Functions

 List (int=26)
 Create a list with space for index values in 1..nn1.
 ~List ()
 Destructor for List.
void clear ()
 Remove all elements from list.
void resize (int)
 Resize a List object.
void expand (int)
 Expand the space available for this List.
void copyFrom (const List &)
 Copy into list from source.
index get (position) const
 Get an index based on its position in the list.
index next (index) const
 Get the next index in a list.
index first () const
 Get first index on list.
index last () const
 Get the last index on list.
int length () const
 Determine the length of the list.
bool valid (index) const
 Test if a given index is valid for this List.
bool empty () const
 Test if list is empty.
bool member (index) const
 Test if an index is in the list.
bool equals (List &) const
 Compare two lists for equality.
bool isConsistent () const
 Check the data structure for consistency.
virtual bool insert (index, index)
 Insert an index into the list, relative to another.
virtual bool removeNext (index)
 Remove the index following a specified index.
bool addFirst (index)
 Add index to the front of the list.
bool addLast (index)
 Add index to the end of the list.
bool removeFirst ()
 Remove the first index in the list.
string & toString (string &) const
 Create a string representation of a given string.

Protected Member Functions

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

Private Attributes

int len
 number of elements in list
index head
 first index in list
index tail
 last index in list
index * nxt
 nxt[i] is successor of i in list

Friends

istream & operator>> (istream &, List &)

Detailed Description

Data structure representing a list of indexes.

An index is a postive integer in 1..n where n is an upper bound on the size of the list. An index can appear on a list at most once. Index-based lists are handy in contexts where we need a common "handle" for a piece of data in several different data structures. They are also compact, efficient and support constant-time membership tests (based on the index).

Note: List has several virtual members, insert() and removeNext() to allow facilitate extension by other classes.

Definition at line 29 of file List.h.


Constructor & Destructor Documentation

grafalgo::List::~List ( )

Destructor for List.

Definition at line 22 of file List.cpp.

Here is the call graph for this function:


Member Function Documentation

bool grafalgo::List::addFirst ( index  i) [inline]

Add index to the front of the list.

Parameters:
indexto be added.
Returns:
true if the list was modified, else false

Definition at line 125 of file List.h.

Here is the call graph for this function:

bool grafalgo::List::addLast ( index  i) [inline]

Add index to the end of the list.

Parameters:
indexto be added.
Returns:
true if the list was modified, else false

Definition at line 131 of file List.h.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Remove all elements from list.

Implements grafalgo::Adt.

Definition at line 75 of file List.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Copy into list from source.

Definition at line 44 of file List.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool grafalgo::List::empty ( ) const [inline]

Test if list is empty.

Returns:
true if list is empty, else false.

Definition at line 101 of file List.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool grafalgo::List::equals ( List other) const

Compare two lists for equality.

Parameters:
otheris the list to be compared to this one
Returns:
true if they are the same list or have the same contents (in the same order); they need not have the same storage capacity to be equal

Definition at line 146 of file List.cpp.

Here is the call graph for this function:

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

Expand the space available for this List.

Rebuilds old value in new space.

Parameters:
sizeis the size of the resized object.

Implements grafalgo::Adt.

Reimplemented in grafalgo::Dlist.

Definition at line 68 of file List.cpp.

Here is the call graph for this function:

index grafalgo::List::first ( ) const [inline]

Get first index on list.

Returns:
the first index on the list or 0 if the list is empty

Definition at line 85 of file List.h.

Here is the caller graph for this function:

void grafalgo::List::freeSpace ( ) [protected]

Free dynamic storage used by list.

Reimplemented in grafalgo::Dlist.

Definition at line 41 of file List.cpp.

Here is the caller graph for this function:

index grafalgo::List::get ( position  i) const

Get an index based on its position in the list.

Parameters:
iis position of index to be returned; must be between 1 and n()
Returns:
index at position i, or 0 if no such index

Reimplemented in grafalgo::Dlist.

Definition at line 82 of file List.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool grafalgo::List::insert ( index  i,
index  j 
) [virtual]

Insert an index into the list, relative to another.

Parameters:
iis index to insert; if i is 0 or already in the list, no change is made
jis index after which i is to be inserted; if zero, i is inserted at the front of the list
Returns:
true if list was modified, else false

Reimplemented in grafalgo::Dlist.

Definition at line 97 of file List.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool grafalgo::List::isConsistent ( ) const

Check the data structure for consistency.

Returns:
true if the data structure is consistent, else false

Definition at line 160 of file List.cpp.

Here is the call graph for this function:

index grafalgo::List::last ( ) const [inline]

Get the last index on list.

Returns:
the last index on the list or 0 if the list is empty

Definition at line 90 of file List.h.

Here is the caller graph for this function:

int grafalgo::List::length ( ) const [inline]

Determine the length of the list.

Returns:
the number of items in the list.

Definition at line 106 of file List.h.

Here is the caller graph for this function:

void grafalgo::List::makeSpace ( int  size) [protected]

Allocate and initialize space for list.

Parameters:
sizeis number of index values to provide space for

Reimplemented in grafalgo::Dlist.

Definition at line 27 of file List.cpp.

Here is the caller graph for this function:

bool grafalgo::List::member ( index  i) const [inline]

Test if an index is in the list.

Parameters:
iis an index
Returns:
true if i is in the list, else false

Definition at line 112 of file List.h.

Here is the call graph for this function:

Here is the caller graph for this function:

index grafalgo::List::next ( index  i) const [inline]

Get the next index in a list.

Parameters:
iis an index on the list
Returns:
the index that follows i, or 0 if there is no next index

Definition at line 80 of file List.h.

Here is the caller graph for this function:

bool grafalgo::List::removeFirst ( ) [inline]

Remove the first index in the list.

Returns:
true if the list was modified, else false

Definition at line 136 of file List.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool grafalgo::List::removeNext ( index  i) [virtual]

Remove the index following a specified index.

Parameters:
iis index whose successor is to be removed; if zero, the first index is removed
Returns:
true if the list was modified, else false

Reimplemented in grafalgo::Dlist.

Definition at line 121 of file List.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Resize a List object.

The old value is discarded.

Parameters:
sizeis the size of the resized object.

Implements grafalgo::Adt.

Reimplemented in grafalgo::Dlist.

Definition at line 56 of file List.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Create a string representation of a given string.

Parameters:
sis string used to return value

Implements grafalgo::Adt.

Definition at line 181 of file List.cpp.

Here is the call graph for this function:

bool grafalgo::List::valid ( index  i) const [inline]

Test if a given index is valid for this List.

Parameters:
iis an integer
Returns:
true if i is in range for this List.

Definition at line 96 of file List.h.

Here is the caller graph for this function:


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