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

listNode.c

Go to the documentation of this file.
00001 /*
00002  * listNode.c
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.c
00014  *
00015  * Implementation for the list node functions.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #if defined(DEBUG)
00021 #define LIST_NODE_DEBUGGING
00022 #endif
00023 
00024 #include <assert.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 
00028 #include "assert_pp.h"
00029 
00030 #include "listNode.h"
00031 
00032 void lnRemove(struct lnMinNode *node)
00033 {
00034 #ifdef LIST_NODE_DEBUGGING
00035     require(node != NULL);
00036     require(node->ln_Succ != NULL);
00037     require(node->ln_Pred != NULL);
00038 #endif
00039     
00040     node->ln_Pred->ln_Succ = node->ln_Succ;
00041     node->ln_Succ->ln_Pred = node->ln_Pred;
00042     
00043 #ifdef LIST_NODE_DEBUGGING
00044     node->ln_Succ = 0;
00045     node->ln_Pred = 0;
00046 #endif
00047 }
00048 
00049 void lnNewList(struct lnMinList *list)
00050 {
00051 #ifdef LIST_NODE_DEBUGGING
00052     require(list != NULL);
00053 #endif
00054     
00055     list->lh_Head = (struct lnMinNode *)&(list->lh_Tail);
00056     list->lh_Tail = 0;
00057     list->lh_TailPred = (struct lnMinNode *)list;
00058 }
00059 
00060 void lnMoveList(struct lnMinList *dest, struct lnMinList *src)
00061 {
00062 #ifdef LIST_NODE_DEBUGGING
00063     require(dest != NULL);
00064     require(src != NULL);
00065 #endif
00066     
00067     dest->lh_Head = src->lh_Head;
00068     dest->lh_TailPred = src->lh_TailPred;
00069     dest->lh_Head->ln_Pred = (struct lnMinNode *)dest;
00070     dest->lh_TailPred->ln_Succ = (struct lnMinNode *)&dest->lh_Tail;
00071     lnNewList(src);
00072 }
00073 
00074 void lnAppendList(struct lnMinList *dest, struct lnMinList *src)
00075 {
00076 #ifdef LIST_NODE_DEBUGGING
00077     require(dest != NULL);
00078     require(src != NULL);
00079 #endif
00080     
00081     if( !lnEmptyList(src) )
00082     {
00083         dest->lh_TailPred->ln_Succ = src->lh_Head;
00084         src->lh_Head->ln_Pred = dest->lh_TailPred;
00085         dest->lh_TailPred = src->lh_TailPred;
00086         dest->lh_TailPred->ln_Succ =
00087             (struct lnMinNode *)&dest->lh_Tail;
00088         lnNewList(src);
00089     }
00090 }
00091 
00092 void lnAddHead(struct lnMinList *list, struct lnMinNode *node)
00093 {
00094 #ifdef LIST_NODE_DEBUGGING
00095     require(list != NULL);
00096     require(node != NULL);
00097 #endif
00098     
00099     node->ln_Succ = list->lh_Head;
00100     node->ln_Pred = (struct lnMinNode *)list;
00101     list->lh_Head->ln_Pred = node;
00102     list->lh_Head = node;
00103 }
00104 
00105 void lnAddTail(struct lnMinList *list, struct lnMinNode *node)
00106 {
00107 #ifdef LIST_NODE_DEBUGGING
00108     require(list != NULL);
00109     require(node != NULL);
00110 #endif
00111     
00112     list->lh_TailPred->ln_Succ = node;
00113     node->ln_Pred = list->lh_TailPred;
00114     list->lh_TailPred = node;
00115     node->ln_Succ = (struct lnMinNode *)&(list->lh_Tail);
00116 }
00117 
00118 struct lnMinNode *lnRemHead(struct lnMinList *list)
00119 {
00120     struct lnMinNode *remnode = 0;
00121     
00122 #ifdef LIST_NODE_DEBUGGING
00123     require(list != NULL);
00124 #endif
00125     
00126     if( list->lh_Head->ln_Succ )
00127     {
00128         remnode = list->lh_Head;
00129         list->lh_Head = remnode->ln_Succ;
00130         list->lh_Head->ln_Pred = (struct lnMinNode *)list;
00131 #ifdef LIST_NODE_DEBUGGING
00132         remnode->ln_Succ = 0;
00133         remnode->ln_Pred = 0;
00134 #endif
00135     }
00136     return( remnode );
00137 }
00138 
00139 struct lnMinNode *lnRemTail(struct lnMinList *list )
00140 {
00141     struct lnMinNode *remnode = 0;
00142     
00143 #ifdef LIST_NODE_DEBUGGING
00144     require(list != NULL);
00145 #endif
00146     
00147     if( list->lh_TailPred->ln_Pred )
00148     {
00149         remnode = list->lh_TailPred;
00150         list->lh_TailPred = remnode->ln_Pred;
00151         list->lh_TailPred->ln_Succ =
00152             (struct lnMinNode *)&(list->lh_Tail);
00153 #ifdef LIST_NODE_DEBUGGING
00154         remnode->ln_Succ = 0;
00155         remnode->ln_Pred = 0;
00156 #endif
00157     }
00158     return( remnode);
00159 }
00160 
00161 void lnInsert(struct lnMinNode *pred, struct lnMinNode *node)
00162 {
00163 #ifdef LIST_NODE_DEBUGGING
00164     require(pred != NULL);
00165     require(node != NULL);
00166 #endif
00167     
00168     node->ln_Succ = pred->ln_Succ;
00169     pred->ln_Succ = node;
00170     node->ln_Pred = pred;
00171     node->ln_Succ->ln_Pred = node;
00172 }
00173 
00174 void lnEnqueue(struct lnList *list, struct lnNode *node)
00175 {
00176     struct lnNode *curr;
00177     int done = 0;
00178     
00179 #ifdef LIST_NODE_DEBUGGING
00180     require(list != NULL);
00181     require(node != NULL);
00182 #endif
00183     
00184     curr = list->lh_Head;
00185     while( curr->ln_Succ && !done )
00186     {
00187         if( node->ln_Pri > curr->ln_Pri )
00188         {
00189             lnInsert((struct lnMinNode *)curr->ln_Pred,
00190                      (struct lnMinNode *)node);
00191             done = 1;
00192         }
00193         curr = curr->ln_Succ;
00194     }
00195     if( !done )
00196         lnAddTail((struct lnMinList *)list, (struct lnMinNode *)node);
00197 }
00198 
00199 struct lnNode *lnFindName(struct lnList *list, const char *name)
00200 {
00201     struct lnNode *curr, *retval = NULL;
00202     
00203 #ifdef LIST_NODE_DEBUGGING
00204     require(list != NULL);
00205     require(name != NULL);
00206 #endif
00207     
00208     curr = list->lh_Head;
00209     while( (curr->ln_Succ != NULL) && (retval == NULL) )
00210     {
00211         if( strcmp(curr->ln_Name, name) == 0 )
00212         {
00213             retval = curr;
00214         }
00215         curr = curr->ln_Succ;
00216     }
00217     return( retval );
00218 }
00219 
00220 unsigned int lnCountNodes(struct lnMinList *list)
00221 {
00222     unsigned int retval = 0;
00223     struct lnMinNode *curr;
00224 
00225 #ifdef LIST_NODE_DEBUGGING
00226     require(list != NULL);
00227 #endif
00228     
00229     curr = list->lh_Head;
00230     while( curr->ln_Succ != NULL )
00231     {
00232         retval += 1;
00233         curr = curr->ln_Succ;
00234     }
00235     return( retval );
00236 }

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1