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 public: 00029 ListElement(void *itemPtr, int sortKey); // initialize a list element 00030 00031 ListElement *next; // next element on list, 00032 // NULL if this is the last 00033 int key; // priority, for a sorted list 00034 void *item; // pointer to item on the list 00035 }; 00036 00037 // The following class defines a "list" -- a singly linked list of 00038 // list elements, each of which points to a single item on the list. 00039 // 00040 // By using the "Sorted" functions, the list can be kept in sorted 00041 // in increasing order by "key" in ListElement. 00042 00043 class List { 00044 public: 00045 List(); // initialize the list 00046 ~List(); // de-allocate the list 00047 00048 void Prepend(void *item); // Put item at the beginning of the list 00049 void Append(void *item); // Put item at the end of the list 00050 void *Remove(); // Take item off the front of the list 00051 00052 void Mapcar(VoidFunctionPtr func); // Apply "func" to every element 00053 // on the list 00054 bool IsEmpty(); // is the list empty? 00055 00056 00057 // Routines to put/get items on/off list in order (sorted by key) 00058 void SortedInsert(void *item, int sortKey); // Put item into list 00059 void *SortedRemove(int *keyPtr); // Remove first item from list 00060 00061 private: 00062 ListElement *first; // Head of the list, NULL if list is empty 00063 ListElement *last; // Last element of list 00064 }; 00065 00066 #endif // LIST_H
1.2.14 written by Dimitri van Heesch,
© 1997-2002