| 1 | /* @title: Deprecated doubly linked list */ |
| 2 | #define dll_add(q, thing) \ |
| 3 | thing->next = NULL; \ |
| 4 | thing->prev = NULL; \ |
| 5 | if (!q->head) { \ |
| 6 | q->head = thing; \ |
| 7 | q->tail = thing; \ |
| 8 | thing->next = thing; \ |
| 9 | thing->prev = thing; \ |
| 10 | } else { \ |
| 11 | thing->prev = q->tail; \ |
| 12 | thing->next = q->head; \ |
| 13 | q->tail->next = thing; \ |
| 14 | q->head->prev = thing; \ |
| 15 | q->tail = thing; \ |
| 16 | } |
| 17 | |
| 18 | #define dll_remove(q, thing) \ |
| 19 | if (q->head == q->tail && q->head == thing) { \ |
| 20 | q->head = NULL; \ |
| 21 | q->tail = NULL; \ |
| 22 | } else if (q->head == thing) { \ |
| 23 | q->head = q->head->next; \ |
| 24 | q->head->prev = q->tail; \ |
| 25 | q->tail->next = q->head; \ |
| 26 | } else if (q->tail == thing) { \ |
| 27 | q->tail = q->tail->prev; \ |
| 28 | q->tail->next = q->head; \ |
| 29 | q->head->prev = q->tail; \ |
| 30 | } else { \ |
| 31 | typeof(thing) current = q->head->next; \ |
| 32 | while (current != q->head && current != thing) \ |
| 33 | current = current->next; \ |
| 34 | if (current == thing) { \ |
| 35 | current->prev->next = current->next; \ |
| 36 | current->next->prev = current->prev; \ |
| 37 | } \ |
| 38 | } \ |
| 39 | thing->next = NULL; \ |
| 40 | thing->prev = NULL; |
| 41 | |
| 42 | #define dll_clear(q) \ |
| 43 | typeof(q->head) start = q->head; \ |
| 44 | typeof(start) iter = start; \ |
| 45 | do { \ |
| 46 | typeof(iter->next) next = iter->next; \ |
| 47 | iter->next = iter->prev = NULL; \ |
| 48 | iter = next; \ |
| 49 | } while (iter != start); \ |
| 50 | q->head = NULL; |
| 51 | |