Main Page | Alphabetical List | Class List | File List | Class Members | File Members

list.h

Go to the documentation of this file.
00001 // list.h 00002 // Data structures to manage LISP-like lists. 00003 // 00004 // As in LISP, a list can contain any type of data structure 00005 // as an item on the list: thread control blocks, 00006 // pending interrupts, etc. That is why each item is a "void *", 00007 // or in other words, a "pointers to anything". 00008 // 00009 // Copyright (c) 1992-1993 The Regents of the University of California. 00010 // All rights reserved. See copyright.h for copyright notice and limitation 00011 // of liability and disclaimer of warranty provisions. 00012 00013 #ifndef LIST_H 00014 #define LIST_H 00015 00016 #include "copyright.h" 00017 #include "utility.h" 00018 00019 // The following class defines a "list element" -- which is 00020 // used to keep track of one item on a list. It is equivalent to a 00021 // LISP cell, with a "car" ("next") pointing to the next element on the list, 00022 // and a "cdr" ("item") pointing to the item on the list. 00023 // 00024 // Internal data structures kept public so that List operations can 00025 // access them directly. 00026 00027 class ListElement 00028 { 00029 public: 00030 ListElement(void *itemPtr, int sortKey); // initialize a list element 00031 00032 ListElement *next; // next element on list, 00033 // NULL if this is the last 00034 int key; // priority, for a sorted list 00035 void *item; // pointer to item on the list 00036 }; 00037 00038 // The following class defines a "list" -- a singly linked list of 00039 // list elements, each of which points to a single item on the list. 00040 // 00041 // By using the "Sorted" functions, the list can be kept in sorted 00042 // in increasing order by "key" in ListElement. 00043 00044 class List 00045 { 00046 public: 00047 List(); // initialize the list 00048 ~List(); // de-allocate the list 00049 00050 void Prepend(void *item); // Put item at the beginning of the list 00051 void Append(void *item);// Put item at the end of the list 00052 void *Remove(); // Take item off the front of the list 00053 00054 void Mapcar(VoidFunctionPtr func); // Apply "func" to every element 00055 // on the list 00056 bool IsEmpty(); // is the list empty? 00057 00058 00059 // Routines to put/get items on/off list in order (sorted by key) 00060 void SortedInsert(void *item, int sortKey); // Put item into list 00061 void* SortedRemove(int *keyPtr); // Remove first item from list 00062 ListElement* GetFirst(); 00063 00064 private: 00065 ListElement *first; // Head of the list, NULL if list is empty 00066 ListElement *last; // Last element of list 00067 }; 00068 00069 class DeltaList 00070 { 00071 public: 00072 DeltaList(); 00073 ~DeltaList(); 00074 00075 void Insert(void *item, int key); // add an item and its key 00076 void* Remove(void *item); // remove a specific element from the list 00077 void* RemoveZero(); // remove and return the first element if its key is zero. 00078 // If the first element has a nonzero key, return a NULL 00079 void Decrement(); // decrement the head of the list 00080 void ShowList(); 00081 int IsEmpty() { return m_first == 0; } 00082 00083 private: 00084 class Elem 00085 { 00086 public: 00087 Elem() {item = 0; key = 0; next = 0;} 00088 void *item; 00089 int key; 00090 Elem *next; 00091 }; 00092 00093 Elem *m_first; 00094 }; 00095 00096 #endif // LIST_H

Generated on Thu Sep 16 12:33:45 2004 for NachOS by doxygen 1.3.8