| 1 |
pippijn |
1.4 |
/** |
| 2 |
|
|
* dlink.h: Data structures and macros for manipulating linked lists. |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.3 |
* Copyright © 2005 William Pitcock, et al. |
| 10 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.4 |
* $Id: dlink.h,v 1.3 2007-08-28 17:08:06 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#ifndef NODE_H |
| 16 |
|
|
#define NODE_H |
| 17 |
|
|
|
| 18 |
pippijn |
1.3 |
#include <common/memory.h> |
| 19 |
|
|
|
| 20 |
pippijn |
1.1 |
/* macros for linked lists */ |
| 21 |
|
|
#define LIST_FOREACH(n, head) for (n = (head); n; n = n->next) |
| 22 |
|
|
#define LIST_FOREACH_NEXT(n, head) for (n = (head); n->next; n = n->next) |
| 23 |
|
|
#define LIST_FOREACH_PREV(n, tail) for (n = (tail); n; n = n->prev) |
| 24 |
|
|
|
| 25 |
|
|
#define LIST_LENGTH(list) (list)->count |
| 26 |
|
|
|
| 27 |
|
|
#define LIST_FOREACH_SAFE(n, tn, head) for (n = (head), tn = n ? n->next : NULL; n != NULL; n = tn, tn = n ? n->next : NULL) |
| 28 |
|
|
|
| 29 |
|
|
/* list node struct */ |
| 30 |
pippijn |
1.3 |
struct node_t : zero_initialised |
| 31 |
pippijn |
1.1 |
{ |
| 32 |
pippijn |
1.3 |
node_t *next; |
| 33 |
|
|
node_t *prev; |
| 34 |
pippijn |
1.1 |
void *data; /* pointer to real structure */ |
| 35 |
|
|
}; |
| 36 |
|
|
|
| 37 |
|
|
/* node list struct */ |
| 38 |
pippijn |
1.3 |
struct list_t : zero_initialised |
| 39 |
pippijn |
1.1 |
{ |
| 40 |
pippijn |
1.3 |
node_t *head; |
| 41 |
|
|
node_t *tail; |
| 42 |
pippijn |
1.1 |
unsigned int count; /* how many entries in the list */ |
| 43 |
pippijn |
1.3 |
|
| 44 |
|
|
list_t () |
| 45 |
|
|
: head (0), tail (0), count (0) |
| 46 |
|
|
{ |
| 47 |
|
|
} |
| 48 |
pippijn |
1.1 |
}; |
| 49 |
|
|
|
| 50 |
|
|
E node_t *node_create (void); |
| 51 |
|
|
E void node_free (node_t *n); |
| 52 |
|
|
E void node_add (void *data, node_t *n, list_t *l); |
| 53 |
|
|
E void node_add_head (void *data, node_t *n, list_t *l); |
| 54 |
|
|
E void node_add_before (void *data, node_t *n, list_t *l, node_t *before); |
| 55 |
|
|
E void node_del (node_t *n, list_t *l); |
| 56 |
|
|
E node_t *node_find (void *data, list_t *l); |
| 57 |
|
|
E void node_move (node_t *m, list_t *oldlist, list_t *newlist); |
| 58 |
|
|
|
| 59 |
|
|
#endif |