1 #include <stdlib.h> // for malloc, free
2 #include <string.h> // for strcmp
3 #include "bits/wrappers.h"
6 #define ITER_REFS node = &list->fst; *node != NULL; node = &(*node)->nxt
8 void list_ini(List *list)
11 list->end = &list->fst;
14 WRAP_NODE_FUNCTIONS(List, list_)
16 void list_apd(List *list, void *dat)
18 list_nmk(list, list->end, dat);
21 void list_ppd(List *list, void *dat)
23 ListNode *fst = list->fst;
24 list_nmk(list, &list->fst, dat);
28 ListNode **list_nfd(List *list, void *key, Comparator cmp)
33 if (cmp((*node)->dat, key) == 0)
39 void list_nmk(List *list, ListNode **node, void *dat)
41 *node = malloc(sizeof **node);
45 if (list->end == node)
46 list->end = &(*node)->nxt;
49 void list_nrm(List *list, ListNode **node)
51 ListNode *old = *node;
54 if (list->end == &old->nxt)
60 void list_itr(List *list, Iterator iter, void *arg, Transformer trans)
62 LIST_ITERATE(list, node)
63 iter(trans ? trans(node->dat) : node->dat, arg);
66 void list_clr(List *list, Iterator iter, void *arg, Transformer trans)
68 for (ListNode *node = list->fst; node != NULL;) {
69 ListNode *next = node->nxt;
72 iter(trans ? trans(node->dat) : node->dat, arg);