Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

List Class Template Reference

The following class defines a "list" -- a singly linked list of list elements, each of which points to a single item on the list. The class has been tested only for primitive types (ints, pointers); no guarantees it will work in general. For instance, all types to be inserted into a list must have a "==" operator defined. More...

#include <list.h>

Inheritance diagram for List::

SortedList List of all members.

Public Methods

 List ()
 initialize the list. More...

virtual ~List ()
 de-allocate the list. More...

virtual void Prepend (T item)
 Put item at the beginning of the list. More...

virtual void Append (T item)
 Put item at the end of the list. More...

Front ()
 Return first item on list without removing it. More...

RemoveFront ()
 Take item off the front of the list. More...

void Remove (T item)
 Remove specific item from list. More...

bool IsInList (T item) const
 is the item in the list? More...

unsigned int NumInList ()
bool IsEmpty ()
void Apply (void(*f)(T)) const
 apply function to all elements in list. More...

virtual void SanityCheck () const
 has this list been corrupted? More...

void SelfTest (T *p, int numEntries)
 verify module is working. More...


Protected Attributes

ListElement<T>* first
 Head of the list, NULL if list is empty. More...

ListElement<T>* last
 Last element of list. More...

int numInList
 number of elements in list. More...

friend ListIterator<T>

Detailed Description

template<class T> class List

The following class defines a "list" -- a singly linked list of list elements, each of which points to a single item on the list. The class has been tested only for primitive types (ints, pointers); no guarantees it will work in general. For instance, all types to be inserted into a list must have a "==" operator defined.

Definition at line 42 of file list.h.


Constructor & Destructor Documentation

template<class T>
List<T>::List<T> ( )
 

initialize the list.

List<T>::List Initialize a list, empty to start with. Elements can now be added to the list.

Definition at line 43 of file list.cc.

template<class T>
List<T>::~List<T> ( ) [virtual]
 

de-allocate the list.

List<T>~List Prepare a list for deallocation.

Definition at line 55 of file list.cc.


Member Function Documentation

template<class T>
void List<T>::Append ( T item ) [virtual]
 

Put item at the end of the list.

List<T>::Append Append an "item" to the end of the list.

Allocate a ListElement to keep track of the item. If the list is empty, then this will be the only element. Otherwise, put it at the end.

"item" is the thing to put on the list.

Reimplemented in SortedList.

Definition at line 73 of file list.cc.

Referenced by SynchList::Append(), ElevatorInfo::Enter(), HashTable::Insert(), Semaphore::P(), ElevatorBank::PostEvent(), HashTable::ReHash(), Scheduler::ReadyToRun(), SelfTest(), and Condition::Wait().

template<class T>
void List<T>::Apply ( void(* f)(T) ) const
 

apply function to all elements in list.

List<T>::Apply Apply function to every item on a list.

"func" -- the function to apply

Definition at line 207 of file list.cc.

template<class T>
T List<T>::Front ( ) [inline]
 

Return first item on list without removing it.

Definition at line 50 of file list.h.

template<class T>
bool List<T>::IsEmpty ( ) [inline]
 

Definition at line 60 of file list.h.

Referenced by Interrupt::AnyFutureInterrupts(), Append(), Condition::Broadcast(), ElevatorBank::CallBack(), HashTable::FindNextFullBucket(), Scheduler::FindNextToRun(), SortedList::Insert(), Prepend(), HashTable::ReHash(), SynchList::RemoveFront(), RemoveFront(), SynchList::SelfTest(), SortedList::SelfTest(), SelfTest(), Condition::Signal(), Semaphore::V(), ElevatorBank::getNextEvent(), and ~List().

template<class T>
bool List<T>::IsInList<T> ( T item ) const
 

is the item in the list?

List<T>::IsInList Return TRUE if the item is in the list.

Definition at line 185 of file list.cc.

Referenced by Append(), SortedList::Insert(), Prepend(), ElevatorBank::PressFloor(), Remove(), SortedList::SelfTest(), and SelfTest().

template<class T>
unsigned int List<T>::NumInList<T> ( ) [inline]
 

Definition at line 58 of file list.h.

Referenced by ElevatorInfo::Enter(), and HashTable::SanityCheck().

template<class T>
void List<T>::Prepend ( T item ) [virtual]
 

Put item at the beginning of the list.

List<T>::Prepend Same as Append, only put "item" on the front.

Reimplemented in SortedList.

Definition at line 96 of file list.cc.

template<class T>
void List<T>::Remove ( T item )
 

Remove specific item from list.

List<T>::Remove Remove a specific item from the list. Must be in the list!

Definition at line 149 of file list.cc.

Referenced by ElevatorInfo::Exit(), HashTable::Remove(), and SelfTest().

template<class T>
T List<T>::RemoveFront ( )
 

Take item off the front of the list.

List<T>::RemoveFront Remove the first "item" from the front of the list. List must not be empty.

Returns: The removed item.

Definition at line 123 of file list.cc.

Referenced by Scheduler::FindNextToRun(), HashTable::ReHash(), Remove(), SynchList::RemoveFront(), SortedList::SelfTest(), Condition::Signal(), Semaphore::V(), and ElevatorBank::getNextEvent().

template<class T>
void List<T>::SanityCheck ( ) const [virtual]
 

has this list been corrupted?

List::SanityCheck Test whether this is still a legal list.

Tests: do I get to last starting from first? does the list have the right # of elements?

Reimplemented in SortedList.

Definition at line 270 of file list.cc.

Referenced by SortedList::SanityCheck(), HashTable::SanityCheck(), and SelfTest().

template<class T>
void List<T>::SelfTest ( T * p,
int numEntries )
 

verify module is working.

List::SelfTest Test whether this module is working.

Reimplemented in SortedList.

Definition at line 296 of file list.cc.

Referenced by LibSelfTest(), and SortedList::SelfTest().


Member Data Documentation

template<class T>
friend List<T>::ListIterator<T> [protected]
 

Definition at line 76 of file list.h.

template<class T>
ListElement< T > * List<T>::first<T> [protected]
 

Head of the list, NULL if list is empty.

Definition at line 72 of file list.h.

template<class T>
ListElement< T > * List<T>::last<T> [protected]
 

Last element of list.

Definition at line 73 of file list.h.

template<class T>
int List<T>::numInList<T> [protected]
 

number of elements in list.

Definition at line 74 of file list.h.


The documentation for this class was generated from the following files:
Generated at Wed Jul 4 11:32:23 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001