ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/dlink.h
(Generate patch)

Comparing ermyth/include/dlink.h (file contents):
Revision 1.2 by pippijn, Sat Jul 21 01:29:07 2007 UTC vs.
Revision 1.3 by pippijn, Tue Aug 28 17:08:06 2007 UTC

1/* 1/*
2 * Copyright © 2005 William Pitcock, et al. 2 * Copyright © 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/pod/license.pod. 3 * Rights to this code are as documented in doc/pod/license.pod.
4 * 4 *
5 * Data structures and macros for manipulating linked lists. 5 * Data structures and macros for manipulating linked lists.
6 * 6 *
7 * $Id: dlink.h,v 1.2 2007/07/21 01:29:07 pippijn Exp $ 7 * $Id: dlink.h,v 1.3 2007/08/28 17:08:06 pippijn Exp $
8 */ 8 */
9 9
10#ifndef NODE_H 10#ifndef NODE_H
11#define NODE_H 11#define NODE_H
12
13#include <common/memory.h>
12 14
13/* macros for linked lists */ 15/* macros for linked lists */
14#define LIST_FOREACH(n, head) for (n = (head); n; n = n->next) 16#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) 17#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) 18#define LIST_FOREACH_PREV(n, tail) for (n = (tail); n; n = n->prev)
18#define LIST_LENGTH(list) (list)->count 20#define LIST_LENGTH(list) (list)->count
19 21
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) 22#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 23
22/* list node struct */ 24/* list node struct */
23struct node_t 25struct node_t : zero_initialised
24{ 26{
25 node_t *next, *prev; 27 node_t *next;
28 node_t *prev;
26 void *data; /* pointer to real structure */ 29 void *data; /* pointer to real structure */
27}; 30};
28 31
29/* node list struct */ 32/* node list struct */
30struct list_t 33struct list_t : zero_initialised
31{ 34{
32 node_t *head, *tail; 35 node_t *head;
36 node_t *tail;
33 unsigned int count; /* how many entries in the list */ 37 unsigned int count; /* how many entries in the list */
38
39 list_t ()
40 : head (0), tail (0), count (0)
41 {
42 }
34}; 43};
35 44
36E node_t *node_create (void); 45E node_t *node_create (void);
37E void node_free (node_t *n); 46E void node_free (node_t *n);
38E void node_add (void *data, node_t *n, list_t *l); 47E void node_add (void *data, node_t *n, list_t *l);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines