1 /************************** toolbox/list.h *************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Management of doubly linked lists
9 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
11 Last Change: 1996/10/03
13 *******************************************************************************/
18 typedef struct listnode { /* structure for list element */
19 struct listnode *next,*prev;
22 typedef struct list { /* structure for list head */
23 listnode *first,*last;
28 void list_init (list *l, int nodeoffset);
30 void list_addlast (list *l, void *element);
31 void list_addfirst (list *l, void *element);
33 void list_remove (list *l, void *element);
35 void *list_first (list *l);
36 void *list_last (list *l);
38 void *list_next (list *l, void *element);
39 void *list_prev (list *l, void *element);
43 ---------------------- interface description -----------------------------
45 The list management with this module works like this:
47 - to be used in a list, a structure must have an element of type
50 - there needs to be a structure of type 'list'.
52 - the function list_init(l, nodeoffset) initializes the structure.
53 nodeoffset is the offset of the 'listnode' from the start of the
56 - The remaining functions provide inserting, removing and searching.
58 This small example aims to demonstrate correct usage:
74 list_init (&l, OFFSET(struct node,linkage) );
81 printf ("Element: %d\n", e->value);
87 The output from this program should be:
94 The reason for the usage of 'nodeoffset' is that this way, the same node can
95 part of different lists (there must be one 'listnode' element for every