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

listNode.h

Go to the documentation of this file.
00001 /*
00002  * listNode.h
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file listNode.h
00014  *
00015  * Amiga-style doubly linked list functions.
00016  */
00017 
00018 #ifndef _list_node_h
00019 #define _list_node_h
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 /**
00026  * Basic node structure that is used for doubly linked list.
00027  */
00028 struct lnMinNode {
00029         struct lnMinNode *ln_Succ;
00030         struct lnMinNode *ln_Pred;
00031 };
00032 
00033 /**
00034  * Extended node structure that is used for doubly linked lists that can be
00035  * ordered by priority.
00036  */
00037 struct lnNode {
00038         struct lnNode *ln_Succ;
00039         struct lnNode *ln_Pred;
00040         int ln_Pri;
00041         const char *ln_Name;
00042 };
00043 
00044 /**
00045  * A combined head and tail for lists that contain lnMinNode's.
00046  */
00047 struct lnMinList {
00048         struct lnMinNode *lh_Head; /**< points to the head node */
00049         struct lnMinNode *lh_Tail; /**< always == 0 */
00050         struct lnMinNode *lh_TailPred; /**< points to the tail node */
00051 };
00052 
00053 /**
00054  * A combined head and tail for lists that contain lnNode's.
00055  */
00056 struct lnList {
00057         struct lnNode *lh_Head;
00058         struct lnNode *lh_Tail;
00059         struct lnNode *lh_TailPred;
00060         int lh_Pri;
00061         const char *lh_Name;
00062 };
00063 
00064 /**
00065  * Remove a node from the list
00066  *
00067  * @param node The node to remove.
00068  */
00069 void lnRemove(struct lnMinNode *node);
00070 
00071 /**
00072  * Initialize a list
00073  *
00074  * @param list The list object to initialize.
00075  */
00076 void lnNewList(struct lnMinList *list);
00077 
00078 /**
00079  * Transfer the nodes on src to dest, overwriting any nodes on dest
00080  *
00081  * @param dest The destination list object.
00082  * @param src The source list object.
00083  */
00084 void lnMoveList(struct lnMinList *dest, struct lnMinList *src);
00085 
00086 /**
00087  * Append the nodes from src to dest.
00088  *
00089  * @param dest The destination list object.
00090  * @param src The source list object.
00091  */
00092 void lnAppendList(struct lnMinList *dest, struct lnMinList *src);
00093 
00094 /**
00095  * Add a node to the head of the list.
00096  *
00097  * @param list The list object the node is to be added to.
00098  * @param node The node to add.
00099  */
00100 void lnAddHead(struct lnMinList *list, struct lnMinNode *node);
00101 
00102 /**
00103  * Add a node to the tail of the list.
00104  *
00105  * @param list The list object the node is to be added to.
00106  * @param node The node to add.
00107  */
00108 void lnAddTail(struct lnMinList *list, struct lnMinNode *node);
00109 
00110 /**
00111  * Remove and return the node at the head of the list, or NULL if the list is
00112  * empty.
00113  *
00114  * @param list A valid list object.
00115  * @return The node at the head of 'list', or NULL if the list is empty.
00116  */
00117 struct lnMinNode *lnRemHead(struct lnMinList *list);
00118 
00119 /**
00120  * Remove and return the node at the tail of the list, or NULL if the list is
00121  * empty
00122  *
00123  * @param list A valid list object.
00124  * @return The node at the tail of 'list', or NULL if the list is empty.
00125  */
00126 struct lnMinNode *lnRemTail(struct lnMinList *list);
00127 
00128 /**
00129  * Check if a list is empty.
00130  *
00131  * @param list The list to check.
00132  * @return True if the list is empty.
00133  */
00134 #define lnEmptyList(list) \
00135     ((struct lnMinNode *)(list)->lh_TailPred == (struct lnMinNode *)(list))
00136 
00137 /**
00138  * Insert a node at a specific position in a list.
00139  *
00140  * @param pred The node in the list that the new node should be inserted after.
00141  * @param node The node to insert.
00142  */
00143 void lnInsert(struct lnMinNode *pred, struct lnMinNode *node);
00144 
00145 /**
00146  * Insert a node into a prioritized list.
00147  *
00148  * @param list An ordered list.
00149  * @param node The node to insert.
00150  */
00151 void lnEnqueue(struct lnList *list, struct lnNode *node);
00152 
00153 /**
00154  * Find a node with the given name.
00155  *
00156  * @param list The list to search.
00157  * @param name The name to search for.
00158  * @return The first node in the list that matches the given name or NULL if no
00159  *         match could be found.
00160  */
00161 struct lnNode *lnFindName(struct lnList *list, const char *name);
00162 
00163 /**
00164  * Count the number of nodes in a list.
00165  *
00166  * @param list The list to scan.
00167  * @return The number of nodes in the list.
00168  */
00169 unsigned int lnCountNodes(struct lnMinList *list);
00170 
00171 #ifdef __cplusplus
00172 }
00173 #endif
00174 
00175 #endif

Generated on Mon Dec 1 16:29:06 2003 for CPU Broker by doxygen 1.3.4