Main Page   Compound List   File List   Compound Members   File Members  

List Class Reference

#include <list.h>

List of all members.

Public Methods

 List ()
 ~List ()
void Prepend (void *item)
void Append (void *item)
void * Remove ()
void Mapcar (VoidFunctionPtr func)
bool IsEmpty ()
void SortedInsert (void *item, int sortKey)
void * SortedRemove (int *keyPtr)

Private Attributes

ListElementfirst
ListElementlast


Constructor & Destructor Documentation

List::List  
 

Definition at line 43 of file list.cc.

References first, last, and NULL.

00044 { 
00045     first = last = NULL; 
00046 }

List::~List  
 

Definition at line 58 of file list.cc.

References NULL, and Remove.

00059 { 
00060     while (Remove() != NULL)
00061         ;        // delete all the list elements
00062 }


Member Function Documentation

void List::Append void *    item
 

Definition at line 77 of file list.cc.

References first, IsEmpty, last, and ListElement::next.

Referenced by SynchList::Append, Semaphore::P, and Scheduler::ReadyToRun.

00078 {
00079     ListElement *element = new ListElement(item, 0);
00080 
00081     if (IsEmpty()) {            // list is empty
00082         first = element;
00083         last = element;
00084     } else {                    // else put it after last
00085         last->next = element;
00086         last = element;
00087     }
00088 }

bool List::IsEmpty  
 

Definition at line 155 of file list.cc.

References FALSE, first, NULL, and TRUE.

Referenced by Append, Interrupt::CheckIfDue, Prepend, SynchList::Remove, SortedInsert, SortedRemove, and Interrupt::~Interrupt.

00156 { 
00157     if (first == NULL)
00158         return TRUE;
00159     else
00160         return FALSE; 
00161 }

void List::Mapcar VoidFunctionPtr    func
 

Definition at line 141 of file list.cc.

References DEBUG, first, ListElement::item, ListElement::next, NULL, and VoidFunctionPtr.

Referenced by Interrupt::DumpState, SynchList::Mapcar, and Scheduler::Print.

00142 {
00143     for (ListElement *ptr = first; ptr != NULL; ptr = ptr->next) {
00144        DEBUG('l', "In mapcar, about to invoke %x(%x)\n", func, ptr->item);
00145        (*func)((int)ptr->item);
00146     }
00147 }

void List::Prepend void *    item
 

Definition at line 103 of file list.cc.

References first, IsEmpty, last, and ListElement::next.

00104 {
00105     ListElement *element = new ListElement(item, 0);
00106 
00107     if (IsEmpty()) {            // list is empty
00108         first = element;
00109         last = element;
00110     } else {                    // else put it before first
00111         element->next = first;
00112         first = element;
00113     }
00114 }

void * List::Remove  
 

Definition at line 125 of file list.cc.

References NULL, and SortedRemove.

Referenced by Scheduler::FindNextToRun, SynchList::Remove, Semaphore::V, Interrupt::~Interrupt, and ~List.

00126 {
00127     return SortedRemove(NULL);  // Same as SortedRemove, but ignore the key
00128 }

void List::SortedInsert void *    item,
int    sortKey
 

Definition at line 179 of file list.cc.

References first, IsEmpty, ListElement::key, last, ListElement::next, and NULL.

Referenced by Interrupt::CheckIfDue, and Interrupt::Schedule.

00180 {
00181     ListElement *element = new ListElement(item, sortKey);
00182     ListElement *ptr;           // keep track
00183 
00184     if (IsEmpty()) {    // if list is empty, put
00185         first = element;
00186         last = element;
00187     } else if (sortKey < first->key) {  
00188                 // item goes on front of list
00189         element->next = first;
00190         first = element;
00191     } else {            // look for first elt in list bigger than item
00192         for (ptr = first; ptr->next != NULL; ptr = ptr->next) {
00193             if (sortKey < ptr->next->key) {
00194                 element->next = ptr->next;
00195                 ptr->next = element;
00196                 return;
00197             }
00198         }
00199         last->next = element;           // item goes at end of list
00200         last = element;
00201     }
00202 }

void * List::SortedRemove int *    keyPtr
 

Definition at line 218 of file list.cc.

References first, IsEmpty, ListElement::item, ListElement::key, last, ListElement::next, and NULL.

Referenced by Interrupt::CheckIfDue, and Remove.

00219 {
00220     ListElement *element = first;
00221     void *thing;
00222 
00223     if (IsEmpty()) 
00224         return NULL;
00225 
00226     thing = first->item;
00227     if (first == last) {        // list had one item, now has none 
00228         first = NULL;
00229         last = NULL;
00230     } else {
00231         first = element->next;
00232     }
00233     if (keyPtr != NULL)
00234         *keyPtr = element->key;
00235     delete element;
00236     return thing;
00237 }


Member Data Documentation

ListElement* List::first [private]
 

Definition at line 62 of file list.h.

Referenced by Append, IsEmpty, List, Mapcar, Prepend, SortedInsert, and SortedRemove.

ListElement* List::last [private]
 

Definition at line 63 of file list.h.

Referenced by Append, List, Prepend, SortedInsert, and SortedRemove.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:56 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees