Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

List Class Reference

#include <raplist.h>

Collaboration diagram for List:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 List ()
 ~List ()
void Prepend (void *item)
void Append (void *item)
void * Remove ()
void Mapcar (VoidFunctionPtr func)
int IsEmpty ()
int Size ()
void SortedInsert (void *item, float sortKey)
void * SortedRemove (float *keyPtr)
float MinKey ()
int SetInsert (void *key, CompareFunction eq)
void * SetRemove (void *key, CompareFunction eq)
void * IsPresent (void *key, CompareFunction eq)
void Purge (void *key, CompareFunction eq, VoidFunctionPtr destroy)

Private Attributes

ListElementfirst
ListElementlast
int size

Constructor & Destructor Documentation

List::List  ) 
 

Definition at line 76 of file raplist.cc.

References first, last, and size.

00077 {
00078   size  = 0;
00079   first = last = NULL; 
00080 }

List::~List  ) 
 

Definition at line 92 of file raplist.cc.

References Remove().

00093 { 
00094   while (Remove() != NULL)
00095     ;    // delete all the List elements
00096 }

Here is the call graph for this function:


Member Function Documentation

void List::Append void *  item  ) 
 

Definition at line 110 of file raplist.cc.

References first, IsEmpty(), last, ListElement::next, and size.

00111 {
00112   ListElement *element = new ListElement(item, 0);
00113   if (IsEmpty()) 
00114     {                           // List is empty
00115       first = element;
00116       last = element;
00117     } 
00118   else 
00119     {                           // else put it after last
00120       last->next = element;
00121       last = element;
00122     }
00123   
00124   size++;
00125 }

Here is the call graph for this function:

int List::IsEmpty  ) 
 

Definition at line 191 of file raplist.cc.

References FALSE, first, and TRUE.

Referenced by Append(), MinKey(), Prepend(), SortedInsert(), and SortedRemove().

00192 {
00193   if (first == NULL)
00194     return TRUE;
00195   else
00196     return FALSE;
00197 }

void * List::IsPresent void *  key,
CompareFunction  eq
 

Definition at line 380 of file raplist.cc.

References first, ListElement::item, and ListElement::next.

Referenced by SetInsert(), and SetRemove().

00381 {
00382   ListElement *ptr;
00383 
00384   for (ptr = first; ptr != NULL; ptr = ptr->next) // Check all items
00385     if ((*eq)(key, ptr->item))
00386       return ptr->item;
00387 
00388   return NULL;
00389 }

void List::Mapcar VoidFunctionPtr  func  ) 
 

Definition at line 180 of file raplist.cc.

References first, ListElement::item, and ListElement::next.

Referenced by RapAgent::LossDetection(), and RapAgent::LossHandler().

00181 {
00182   for (ListElement *ptr = first; ptr != NULL; ptr = ptr->next)
00183     (*func)((int)ptr->item);
00184 }

float List::MinKey  ) 
 

Definition at line 292 of file raplist.cc.

References first, IsEmpty(), and ListElement::key.

00293 {
00294   if (IsEmpty())
00295     return -1;
00296   else
00297     return first->key;
00298 }

Here is the call graph for this function:

void List::Prepend void *  item  ) 
 

Definition at line 139 of file raplist.cc.

References first, IsEmpty(), last, ListElement::next, and size.

Referenced by SetInsert().

00140 {
00141   ListElement *element = new ListElement(item, 0);
00142   
00143   if (IsEmpty()) 
00144     {                           // List is empty
00145       first = element;
00146       last = element;
00147     } 
00148   else 
00149     {                           // else put it before first
00150       element->next = first;
00151       first = element;
00152     }
00153 
00154   size++;
00155 }

Here is the call graph for this function:

void List::Purge void *  key,
CompareFunction  eq,
VoidFunctionPtr  destroy
 

Definition at line 400 of file raplist.cc.

References first, ListElement::item, last, ListElement::next, and size.

Referenced by RapAgent::LossDetection().

00401 {
00402   ListElement *prev, *curr, *temp;
00403   void *thing;
00404 
00405   for (prev = NULL, curr = first; curr != NULL; ) // Check all items
00406     if ((*eq)(key, curr->item))
00407       {
00408         if (curr == first)
00409           first = curr->next;
00410         else
00411           prev->next = curr->next;
00412 
00413         if (curr == last)
00414           last = prev;
00415 
00416         thing = curr->item;
00417         temp = curr;
00418 
00419         curr = curr->next;
00420 
00421         (* destroy)((int) thing);
00422         delete temp;
00423         size--;
00424       }
00425   else
00426     {
00427       prev = curr;
00428       curr = curr->next;
00429     }
00430 }

void * List::Remove  ) 
 

Definition at line 165 of file raplist.cc.

References SortedRemove().

Referenced by ~List().

00166 {
00167   return SortedRemove(NULL);  // Same as SortedRemove, but ignore the key
00168 }

Here is the call graph for this function:

int List::SetInsert void *  key,
CompareFunction  eq
 

Definition at line 315 of file raplist.cc.

References FALSE, IsPresent(), Prepend(), and TRUE.

Referenced by RapAgent::SendPacket().

00316 {
00317   if (IsPresent(key, eq))
00318     return FALSE;
00319 
00320   Prepend(key);
00321   return TRUE;
00322 }

Here is the call graph for this function:

void * List::SetRemove void *  key,
CompareFunction  eq
 

Definition at line 338 of file raplist.cc.

References first, IsPresent(), ListElement::item, last, ListElement::next, and size.

Referenced by RapAgent::RecvAck().

00339 {
00340   ListElement *prev, *curr;
00341   void *thing;
00342 
00343   if (!IsPresent(key, eq))
00344     return NULL;
00345  
00346   for (prev = NULL, curr = first; 
00347        curr != NULL; 
00348        prev = curr, curr = curr->next)
00349     if ((*eq)(key, curr->item))
00350       break;
00351 
00352   assert(curr != NULL);         // Since its present we'd better find it
00353 
00354   if (curr == first)
00355     first = curr->next;
00356   else
00357     prev->next = curr->next;
00358   
00359   if (curr == last)
00360     last = prev;
00361 
00362   thing = curr->item;
00363   delete curr;
00364 
00365   size--;
00366   return thing;
00367 }

Here is the call graph for this function:

int List::Size  )  [inline]
 

Definition at line 92 of file raplist.h.

References size.

Referenced by RapAgent::LossDetection().

00092 {return size;}  // Return the number of elements

void List::SortedInsert void *  item,
float  sortKey
 

Definition at line 214 of file raplist.cc.

References first, IsEmpty(), ListElement::key, last, ListElement::next, and size.

00215 {
00216   ListElement *element = new ListElement(item, sortKey);
00217   ListElement *ptr;             // keep track
00218   
00219   if (IsEmpty()) 
00220     {                           // List is empty, put in front
00221       first = element;
00222       last = element;
00223     } 
00224   else if (sortKey < first->key) 
00225     {                           // item goes on front of List   
00226       element->next = first;
00227       first = element;
00228     } 
00229   else 
00230     {                           // look for first elt in List bigger than item
00231       for (ptr = first; ptr->next != NULL; ptr = ptr->next) {
00232         if (sortKey < ptr->next->key) 
00233           {
00234             element->next = ptr->next;
00235             ptr->next = element;
00236             return;
00237           }     
00238       }
00239       last->next = element;     // item goes at end of List
00240       last = element;
00241     }
00242   
00243   size++;
00244 }

Here is the call graph for this function:

void * List::SortedRemove float *  keyPtr  ) 
 

Definition at line 259 of file raplist.cc.

References first, IsEmpty(), ListElement::item, ListElement::key, last, ListElement::next, and size.

Referenced by Remove().

00260 {
00261   ListElement *element = first;
00262   void *thing;
00263   
00264   if (IsEmpty()) 
00265     return NULL;
00266   
00267   thing = first->item;
00268   if (first == last) 
00269     {                           // List had one item, now has none 
00270       first = NULL;
00271       last = NULL;
00272     } 
00273   else 
00274     first = element->next;
00275 
00276   if (keyPtr != NULL)
00277     *keyPtr = element->key;
00278   delete element;
00279   
00280   size--;
00281   return thing;
00282 }

Here is the call graph for this function:


Member Data Documentation

ListElement* List::first [private]
 

Definition at line 106 of file raplist.h.

Referenced by Append(), IsEmpty(), IsPresent(), List(), Mapcar(), MinKey(), Prepend(), Purge(), SetRemove(), SortedInsert(), and SortedRemove().

ListElement* List::last [private]
 

Definition at line 107 of file raplist.h.

Referenced by Append(), List(), Prepend(), Purge(), SetRemove(), SortedInsert(), and SortedRemove().

int List::size [private]
 

Definition at line 108 of file raplist.h.

Referenced by Append(), List(), Prepend(), Purge(), SetRemove(), Size(), SortedInsert(), and SortedRemove().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:55:14 2004 for NS2.26SourcesOriginal by doxygen 1.3.3