listcoll.h

Go to the documentation of this file.
00001 /* Copyright (c) 2005 by John M. Boyer, All Rights Reserved.  Please see
00002  * License.txt for use and redistribution license. */
00003 /* Copyright (c) 1997-2003 by John M. Boyer, All Rights Reserved.
00004         This code may not be reproduced in whole or in part without
00005         the written permission of the author. */
00006 
00007 #ifndef _LISTCOLL_H
00008 #define _LISTCOLL_H
00009 
00010 #include <string.h>
00011 typedef struct
00012 {
00013   int prev,
00014     next;
00015 }
00016 lcnode;
00017 typedef struct
00018 {
00019   int N;
00020   lcnode *List;
00021 }
00022 listCollectionRec;
00023 typedef listCollectionRec *listCollectionP;
00024 listCollectionP LCNew (int N);
00025 void LCFree (listCollectionP * pListColl);
00026 
00027 #ifndef SPEED_MACROS
00028 void LCReset (listCollectionP listColl);
00029 void LCCopy (listCollectionP dst,
00030              listCollectionP src);
00031 int LCGetNext (listCollectionP listColl,
00032                int theList,
00033                int theNode);
00034 int LCGetPrev (listCollectionP listColl,
00035                int theList,
00036                int theNode);
00037 int LCPrepend (listCollectionP listColl,
00038                int theList,
00039                int theNode);
00040 int LCAppend (listCollectionP listColl,
00041               int theList,
00042               int theNode);
00043 int LCDelete (listCollectionP listColl,
00044               int theList,
00045               int theNode);
00046 
00047 #else /*  */
00048 
00049 /* void LCReset(listCollectionP listColl); */
00050 
00051 #define LCReset(listColl) memset(listColl->List, NIL_CHAR, listColl->N*sizeof(lcnode))
00052 
00053 /* void LCCopy(listCollectionP dst, listCollectionP src) */
00054 
00055 #define LCCopy(dst, src) memcpy(dst->List, src->List, src->N*sizeof(lcnode))
00056 
00057 /* int  LCGetNext(listCollectionP listColl, int theList, int theNode); 
00058   Return theNode's successor, unless it is theList head pointer */
00059 
00060 #define LCGetNext(listColl, theList, theNode) listColl->List[theNode].next==theList ? NIL : listColl->List[theNode].next
00061 
00062 /* int  LCGetPrev(listCollectionP listColl, int theList, int theNode); 
00063   Return theNode's predecessor unless theNode is theList head.
00064   To start going backwards, use NIL for theNode, which returns theList head's predecessor 
00065   Usage: Obtain last node, loop while NIL not returned, process node then get predecessor.
00066     After theList head processed, get predecessor returns NIL because we started with
00067     theList head's predecessor. */
00068 
00069 #define LCGetPrev(listColl, theList, theNode) (theNode == NIL ? listColl->List[theList].prev : theNode == theList ? NIL : listColl->List[theNode].prev)
00070 /* int  LCPrepend(listCollectionP listColl, int theList, int theNode);
00071         After an append, theNode is last, which in a circular list is the direct predecessor
00072   of the list head node, so we just back up one. For singletons, this has no effect.*/
00073 
00074 #define LCPrepend(listColl, theList, theNode) listColl->List[LCAppend(listColl, theList, theNode)].prev
00075 
00076 /* int  LCAppend(listCollectionP listColl, int theList, int theNode);
00077   If theList is empty, then theNode becomes its only member and is returned.
00078   Otherwise, theNode is placed before theList head, which is returned. */
00079 
00080 #define LCAppend(listColl, theList, theNode) (theList == NIL ? (listColl->List[theNode].prev = listColl->List[theNode].next = theNode) : (listColl->List[theNode].next = theList, listColl->List[theNode].prev = listColl->List[theList].prev, listColl->List[listColl->List[theNode].prev].next = theNode, listColl->List[theList].prev = theNode, theList))
00081 /* int  LCDelete(listCollectionP listColl, int theList, int theNode); 
00082   If theList contains only one node, then NIL it out and return NIL meaning empty list 
00083   Otherwise, join the predecessor and successor, then 
00084   return either the list head or its successor if the deleted node is the list head
00085   (in that case, the caller makes the successor become the new list head).*/
00086 
00087 #define LCDelete(listColl, theList, theNode) listColl->List[theList].next == theList ? (listColl->List[theList].prev = listColl->List[theList].next = NIL)  : (listColl-> List[listColl-> List[theNode].  prev].next = listColl-> List[theNode].next, listColl-> List[listColl-> List[theNode].  next].prev = listColl-> List[theNode].prev, (theList == theNode ?  listColl-> List[theNode].  next : theList))
00088 
00089 #endif /*  */
00090 
00091 #endif /*  */

Generated on Thu Oct 20 14:58:42 2005 for DominoParitySeparator by  doxygen 1.4.5