Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

list.h

Go to the documentation of this file.
00001 #ifndef LIST_H
00002 #define LIST_H
00003 
00004 /****************************************************************************************/
00005 /*  List                                                                                */
00006 /*                                                                                      */
00007 /*  Author: Charles Bloom                                                               */
00008 /*  Description: List/Link/Node Primitives                                              */
00009 /*                                                                                      */
00010 /*  The contents of this file are subject to the Genesis3D Public License               */
00011 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00012 /*  compliance with the License. You may obtain a copy of the License at                */
00013 /*  http://www.genesis3d.com                                                            */
00014 /*                                                                                      */
00015 /*  Software distributed under the License is distributed on an "AS IS"                 */
00016 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00017 /*  the License for the specific language governing rights and limitations              */
00018 /*  under the License.                                                                  */
00019 /*                                                                                      */
00020 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00021 /*  Genesis3D Version 1.1 released November 15, 1999                                 */
00022 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00023 /*                                                                                      */
00024 /****************************************************************************************/
00025 
00026 #include "basetype.h"
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 #define LISTCALL        __fastcall
00033 
00034 /*******************************************/
00037 geBoolean List_Start(void);
00038 geBoolean List_Stop(void);
00039 
00040 /*******************************************/
00043 typedef struct List List;
00044 
00045 extern List *   LISTCALL List_Create(void);
00046 extern void             LISTCALL List_Destroy(List * pList);
00047 extern List *   LISTCALL List_AddTail(List *pList,void * Data);
00048 extern List *   LISTCALL List_AddHead(List *pList,void * Data);
00049         // returns a pointer to the node created
00050 extern void *   LISTCALL List_CutHead(List *pList);
00051 extern void *   LISTCALL List_CutTail(List *pList);
00052 extern void *   LISTCALL List_PeekHead(List *pList);
00053 extern void *   LISTCALL List_PeekTail(List *pList);
00054 
00055 extern List *   LISTCALL List_Next(List *pNode);
00056 extern List *   LISTCALL List_Prev(List *pNode);
00057 
00058 extern void             LISTCALL List_CutNode(List *pNode);
00059 extern void             LISTCALL List_DeleteNode(List *pNode);
00060 extern void             LISTCALL List_FreeNode(List *pNode);
00061 extern void *   LISTCALL List_NodeData(List *pNode);
00062 
00063 extern List *   List_Find(List *pList,void *Data);
00064 
00065 /****
00066 
00067         Iterate on a list via :
00068 
00069         List *pNode,*pList;
00070         for( pNode = List_Next(pList); pNode != pList; pNode = List_Next(pNode) )
00071         {
00072                 //do stuff to pNode
00073         }
00074 
00075 ****/
00076 
00077 typedef struct Stack Stack;
00078 
00079 extern Stack *  LISTCALL Stack_Create(void);
00080 extern void     LISTCALL Stack_Destroy(Stack * pStack);
00081 extern void     LISTCALL Stack_Push_Func(Stack *pStack,void * Data);
00082 extern void *   LISTCALL Stack_Pop_Func(Stack *pStack);
00083 extern int              LISTCALL Stack_Extend(Stack *pStack);   // returns new length
00084 
00085 #ifdef _DEBUG
00086 
00087 #define Stack_Push      Stack_Push_Func
00088 #define Stack_Pop       Stack_Pop_Func
00089 
00090 #else
00091 
00092 // this struct is exposed only in release mode!
00093 // don't look into it!
00094 
00095 struct Stack
00096 {
00097         void ** Buffer, **End;
00098         void ** Head;
00099         int members;
00100 };
00101 
00102 //#define Stack_Push(pStack,Data)       do { *((pStack)->Head)++ = (void *)(Data); if ( (pStack)->Head == (pStack)->End ) Stack_Extend(pStack); } while(0)
00103 #define Stack_Push(pStack,Data) *((pStack)->Head)++ = (void *)(Data), ( (pStack)->Head != (pStack)->End ) || Stack_Extend(pStack)
00104 #define Stack_Pop(pStack)               ( ((pStack)->Head == (pStack)->Buffer) ? NULL : *( -- ((pStack)->Head) ) )
00105 
00106 #endif
00107 
00108 typedef struct Link Link;
00109 
00110 extern Link *   LISTCALL Link_Create(void);
00111 extern void             LISTCALL Link_Destroy(Link * pLink);
00112 extern void             LISTCALL Link_Push(Link *pLink,void * Data);
00113 extern void *   LISTCALL Link_Pop(Link *pLink);
00114 extern void *   LISTCALL Link_Peek(Link *pLink);
00115 
00116 typedef struct LinkNode LinkNode;
00117 
00118 /************************************/
00119 /*** a radix of each type ****/
00120 
00121 typedef struct RadixList RadixList;
00122 
00123 extern RadixList * RadixList_Create(int RadixListMax);
00124 extern void RadixList_Destroy(RadixList * pRadixList);
00125 extern List * RadixList_Add(RadixList *pRadixList,void * Data,int Key);
00126         // returns a pointer to the node created
00127 extern void * RadixList_CutMax(RadixList *pRadixList,int * pMaxKey);
00128 extern void * RadixList_CutMin(RadixList *pRadixList,int * pMinKey);
00129 extern void * RadixList_CutKey(RadixList *pRadixList,int Key);
00130 
00131 typedef struct RadixLN RadixLN;
00132 
00133 extern RadixLN * RadixLN_Create(int RadixLNMax);
00134 extern void RadixLN_Destroy(RadixLN * pRadixLN);
00135 extern void RadixLN_AddTail(RadixLN *pRadixLN,LinkNode * LN,int Key);
00136 extern void RadixLN_AddHead(RadixLN *pRadixLN,LinkNode * LN,int Key);
00137 extern LinkNode * RadixLN_CutMax(RadixLN *pRadixLN,int * pMaxKey);
00138 extern LinkNode * RadixLN_CutMin(RadixLN *pRadixLN,int * pMinKey);
00139 extern LinkNode * RadixLN_CutKey(RadixLN *pRadixLN,int Key);
00140 extern LinkNode * RadixLN_PeekMax(RadixLN *pRadixLN,int * pMaxKey);
00141 extern LinkNode * RadixLN_PeekMin(RadixLN *pRadixLN,int * pMinKey);
00142 
00143 typedef struct RadixLink RadixLink;
00144 
00145 extern                  RadixLink * RadixLink_Create(int RadixLinkMax);
00146 extern void             RadixLink_Destroy(RadixLink * pRadixLink);
00147 extern void             RadixLink_Add(RadixLink *pRadixLink,void * Data,int Key);
00148 extern void *   RadixLink_CutMax(RadixLink *pRadixLink,int * pMaxKey);
00149 extern void *   RadixLink_CutMin(RadixLink *pRadixLink,int * pMinKey);
00150 extern void *   RadixLink_CutKey(RadixLink *pRadixLink,int Key);
00151 extern void             RadixLink_Grow(RadixLink *pRadixLink,int NewMax);
00152 
00153 /******************************/
00154 
00155 typedef struct Hash Hash;
00156 typedef struct HashNode HashNode;
00157 
00158 extern Hash *   Hash_Create(void);
00159 extern void             Hash_Destroy(Hash *pHash);
00160 HashNode *      LISTCALL Hash_Add(Hash *pHash,uint32 Key,uint32 Data);
00161 void            LISTCALL Hash_DeleteNode(Hash *pHash,HashNode *pNode);
00162 HashNode *      LISTCALL Hash_Get(Hash *pHash,uint32 Key,uint32 *pData);
00163                                                         // pdata is optional
00164 HashNode *      LISTCALL Hash_WalkNext(Hash *pHash,HashNode *pCur);
00165                                                         //use pCur == NULL to start walking
00166 
00167 uint32          LISTCALL Hash_NumMembers(Hash *pHash);
00168 
00169 void    HashNode_SetData(HashNode *pNode,uint32 Data);
00170 void    HashNode_GetData(HashNode *pNode,uint32 *pKey,uint32 *pData);
00171 uint32  HashNode_Key(HashNode *pNode);
00172 uint32  HashNode_Data(HashNode *pNode);
00173 
00174 uint32  Hash_StringToKey(const char * String);
00175 
00176 /******************************/
00177 
00178 struct LinkNode 
00179 {
00180         LinkNode *Next,*Prev;
00181 }; 
00182 
00183 #define zLN_InitList(List)                      do { (List)->Next = List; (List)->Prev = List; } while(0)
00184 #define zLN_Cut(Node)                           do { (Node)->Prev->Next = (Node)->Next; (Node)->Next->Prev = (Node)->Prev; zLN_InitList(Node); } while(0)
00185 #define zLN_Fix(Node)                           do { (Node)->Prev->Next = Node; (Node)->Next->Prev = Node; } while(0)
00186 #define zLN_AddAfter(Node,List)         do { (Node)->Prev = List; (Node)->Next = (List)->Next; LN_Fix(Node); } while(0)
00187 #define zLN_AddBefore(Node,List)        do { (Node)->Next = List; (Node)->Prev = (List)->Prev; LN_Fix(Node); } while(0)
00188 #define zLN_Walk_Editting(Node,List,Holder)     for( Node = (List)->Next; (Node) != (List) && ((Holder) = (Node)->Next) != NULL ; Node = Holder )
00189 #define zLN_Walk(Node,List)                     for( Node = (List)->Next; (Node) != (List) ; Node = (Node)->Next )
00190 #define zLN_EmptyList(List)                     ( (List)->Next == (List) )
00191 
00192 #define LN_InitList(List)                       zLN_InitList((LinkNode *)List)
00193 #define LN_Cut(Node)                            zLN_Cut((LinkNode *)Node)
00194 #define LN_Fix(Node)                            zLN_Fix((LinkNode *)Node)
00195 #define LN_AddAfter(Node,List)          zLN_AddAfter((LinkNode *)Node,(LinkNode *)List)
00196 #define LN_AddBefore(Node,List)         zLN_AddBefore((LinkNode *)Node,(LinkNode *)List)
00197 #define LN_Walk(Node,List)                      zLN_Walk((LinkNode *)Node,(LinkNode *)List)
00198 #define LN_Walk_Editting(Node,List,Holder)                      zLN_Walk_Editting((LinkNode *)Node,(LinkNode *)List,((LinkNode *)Holder))
00199 #define LN_EmptyList(List)                      zLN_EmptyList((LinkNode *)List)
00200 #define LN_Prev(Node)                           (void *)(((LinkNode *)Node)->Prev)
00201 #define LN_Next(Node)                           (void *)(((LinkNode *)Node)->Next)
00202 
00203 #define LN_Null(node)   LN_InitList(node)
00204 
00205 LinkNode *      LISTCALL LN_CutHead(LinkNode *pList);
00206 LinkNode *      LISTCALL LN_CutTail(LinkNode *pList);
00207 
00208 int LN_ListLen(LinkNode *pList);
00209 
00210 #define LN_AddHead(list,node)   LN_AddAfter(node,list)
00211 #define LN_AddTail(list,node)   LN_AddBefore(node,list)
00212 #define LN_IsEmpty      LN_EmptyList
00213 
00214 
00215         /* use LN_Walk as :
00216         *
00217 
00218                 void doStuffOnAllNodes(LinkNode *pList)
00219                 {
00220                         LinkNode *pNode;
00221                         LN_Walk(pNode,pList) {
00222                                 doStuff(pNode);
00223                         }
00224                 }
00225 
00226         *
00227         */
00228 
00229 #ifdef __cplusplus
00230 }
00231 #endif
00232 
00233 #endif  // LIST_H
00234 

Generated on Tue Sep 30 12:35:58 2003 for GTestAndEngine by doxygen 1.3.2