1 /* src/toolbox/list.h -
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
29 Changes: Christian Thalinger
31 $Id: list.h 3449 2005-10-19 19:56:46Z twisti $
39 typedef struct listnode { /* structure for list element */
40 struct listnode *next;
41 struct listnode *prev;
45 typedef struct list { /* structure for list head */
52 /* function prototypes */
54 void list_init(list *l, int nodeoffset);
56 void list_addlast(list *l, void *element);
57 void list_addfirst(list *l, void *element);
59 void list_remove(list *l, void *element);
61 void *list_first(list *l);
62 void *list_last(list *l);
64 void *list_next(list *l, void *element);
65 void *list_prev(list *l, void *element);
69 ---------------------- interface description -----------------------------
71 The list management with this module works like this:
73 - to be used in a list, a structure must have an element of type
76 - there needs to be a structure of type 'list'.
78 - the function list_init(l, nodeoffset) initializes the structure.
79 nodeoffset is the offset of the 'listnode' from the start of the
82 - The remaining functions provide inserting, removing and searching.
84 This small example aims to demonstrate correct usage:
100 list_init (&l, OFFSET(struct node,linkage) );
101 list_addlast (&l, a);
102 list_addlast (&l, b);
103 list_addlast (&l, c);
107 printf ("Element: %d\n", e->value);
108 e = list_next (&l,e);
113 The output from this program should be:
120 The reason for the usage of 'nodeoffset' is that this way, the same node can
121 part of different lists (there must be one 'listnode' element for every
130 * These are local overrides for various environment variables in Emacs.
131 * Please do not remove this and leave it at the end of the file, where
132 * Emacs will automagically detect them.
133 * ---------------------------------------------------------------------
136 * indent-tabs-mode: t