00001
00002
00003
00004
00005
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
00050
00051 #define LCReset(listColl) memset(listColl->List, NIL_CHAR, listColl->N*sizeof(lcnode))
00052
00053
00054
00055 #define LCCopy(dst, src) memcpy(dst->List, src->List, src->N*sizeof(lcnode))
00056
00057
00058
00059
00060 #define LCGetNext(listColl, theList, theNode) listColl->List[theNode].next==theList ? NIL : listColl->List[theNode].next
00061
00062
00063
00064
00065
00066
00067
00068
00069 #define LCGetPrev(listColl, theList, theNode) (theNode == NIL ? listColl->List[theList].prev : theNode == theList ? NIL : listColl->List[theNode].prev)
00070
00071
00072
00073
00074 #define LCPrepend(listColl, theList, theNode) listColl->List[LCAppend(listColl, theList, theNode)].prev
00075
00076
00077
00078
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
00082
00083
00084
00085
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