1 |
/* |
2 |
* Copyright © 2005 William Pitcock, et al. |
3 |
* Rights to this code are as documented in doc/LICENSE. |
4 |
* |
5 |
* Data structures and macros for manipulating linked lists. |
6 |
* |
7 |
* $Id: dlink.h 8027 2007-04-02 10:47:18Z nenolod $ |
8 |
*/ |
9 |
|
10 |
#ifndef NODE_H |
11 |
#define NODE_H |
12 |
|
13 |
/* macros for linked lists */ |
14 |
#define LIST_FOREACH(n, head) for (n = (head); n; n = n->next) |
15 |
#define LIST_FOREACH_NEXT(n, head) for (n = (head); n->next; n = n->next) |
16 |
#define LIST_FOREACH_PREV(n, tail) for (n = (tail); n; n = n->prev) |
17 |
|
18 |
#define LIST_LENGTH(list) (list)->count |
19 |
|
20 |
#define LIST_FOREACH_SAFE(n, tn, head) for (n = (head), tn = n ? n->next : NULL; n != NULL; n = tn, tn = n ? n->next : NULL) |
21 |
|
22 |
/* list node struct */ |
23 |
struct node_t |
24 |
{ |
25 |
node_t *next, *prev; |
26 |
void *data; /* pointer to real structure */ |
27 |
}; |
28 |
|
29 |
/* node list struct */ |
30 |
struct list_t |
31 |
{ |
32 |
node_t *head, *tail; |
33 |
unsigned int count; /* how many entries in the list */ |
34 |
}; |
35 |
|
36 |
E node_t *node_create (void); |
37 |
E void node_free (node_t *n); |
38 |
E void node_add (void *data, node_t *n, list_t *l); |
39 |
E void node_add_head (void *data, node_t *n, list_t *l); |
40 |
E void node_add_before (void *data, node_t *n, list_t *l, node_t *before); |
41 |
E void node_del (node_t *n, list_t *l); |
42 |
E node_t *node_find (void *data, list_t *l); |
43 |
E void node_move (node_t *m, list_t *oldlist, list_t *newlist); |
44 |
|
45 |
#endif |