5 // this file provides macros which implement common operations on linked lists.
6 // this saves a little bit of thinking and helps prevent bugs caused by
7 // forgetting one of the steps.
9 // call them giving them the node to work on and the names of the fields
10 // for next, prev, first and last nodes.
12 // add a node to the end of a linked list
13 #define LL_ADD_END(O, PREV, NEXT, FIRST, LAST) \
25 // add a node at the start of a linked list
26 #define LL_ADD_BEGIN(O, PREV, NEXT, FIRST, LAST) \
37 // insert a node just before another node
38 #define LL_INSERT_BEFORE(O, BEHIND, PREV, NEXT, FIRST, LAST) \
40 if (BEHIND == FIRST) \
43 BEHIND->PREV->NEXT = O; \
46 O->PREV = BEHIND->PREV; \
50 // insert a node just after another node
51 #define LL_INSERT_AFTER(O, AFTER, PREV, NEXT, FIRST, LAST) \
56 AFTER->NEXT->PREV = O; \
58 O->NEXT = AFTER->NEXT; \
63 // remove a node from a linked list
64 #define LL_REMOVE(O, PREV, NEXT, FIRST, LAST) \
67 FIRST = FIRST->NEXT; \
69 O->PREV->NEXT = O->NEXT; \
74 O->NEXT->PREV = O->PREV; \
78 #define LL_DUMP_LIST(START, PREV, NEXT, NODETYPE) \
80 stat("LL_DUMP_LIST from %s using %s", #START, #NEXT); \
82 NODETYPE *n = START; \
86 stat("%d: %08x P:%08x N:%08x", iter++, n, n->PREV, n->NEXT); \