00001
00002
00003
00004
00005
00006 #ifndef DLIST_H
00007 #define DLIST_H
00008
00009 #ifndef COMMON_H
00010 #include "common.h"
00011 #endif
00012
00013 struct dlNode
00014
00015 {
00016 struct dlNode *next;
00017 struct dlNode *prev;
00018 void *val;
00019 };
00020
00021 struct dlList
00022
00023 {
00024 struct dlNode *head;
00025 struct dlNode *nullMiddle;
00026 struct dlNode *tail;
00027 };
00028
00029 #define dlEnd(node) (node->next == NULL)
00030
00031
00032 #define dlStart(node) (node->prev == NULL)
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 struct dlList *newDlList();
00044
00045
00046 #define dlListNew newDlList
00047
00048
00049 void dlListInit(struct dlList *dl);
00050
00051
00052 void dlListReset(struct dlList *dl);
00053
00054
00055 void freeDlList(struct dlList **pList);
00056
00057 #define dlListFree freeDlList
00058
00059 void freeDlListAndVals(struct dlList **pList);
00060
00061
00062 #define dlListFreeAndVals freeDlListAndVals
00063
00064 void dlAddBefore(struct dlNode *anchor, struct dlNode *newNode);
00065
00066
00067 void dlAddAfter(struct dlNode *anchor, struct dlNode *newNode);
00068
00069
00070 void dlAddHead(struct dlList *list, struct dlNode *newNode);
00071
00072
00073 void dlAddTail(struct dlList *list, struct dlNode *newNode);
00074
00075
00076 struct dlNode *dlAddValBefore(struct dlNode *anchor, void *val);
00077
00078
00079 struct dlNode *dlAddValAfter(struct dlNode *anchor, void *val);
00080
00081
00082 struct dlNode *dlAddValHead(struct dlList *list, void *val);
00083
00084
00085 struct dlNode *dlAddValTail(struct dlList *list, void *val);
00086
00087
00088 void dlRemove(struct dlNode *node);
00089
00090
00091 void dlRemoveHead(struct dlList *list);
00092
00093
00094 void dlRemoveTail(struct dlList *list);
00095
00096
00097 struct dlNode *dlPopHead(struct dlList *list);
00098
00099
00100 struct dlNode *dlPopTail(struct dlList *list);
00101
00102
00103 void dlDelete(struct dlNode **nodePtr);
00104
00105
00106 int dlCount(struct dlList *list);
00107
00108
00109 boolean dlEmpty(struct dlList *list);
00110
00111
00112 #define dlIsEmpty(list) ((list)->head->next == NULL)
00113
00114
00115 struct dlNode *dlGetBeforeHead(struct dlList *list);
00116
00117
00118 struct dlNode *dlGetAfterTail(struct dlList *list);
00119
00120
00121 void dlSort(struct dlList *list, int (*compare )(const void *elem1, const void *elem2));
00122
00123
00124
00125
00126
00127 void *dlListToSlList(struct dlList *dList);
00128
00129
00130 void dlCat(struct dlList *a, struct dlList *b);
00131
00132
00133 struct dlNode *dlValInList(struct dlList *list, void *val);
00134
00135
00136 #endif
00137
00138