1 /* toolbox/chain.h - management of doubly linked lists with external linking
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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 $Id: chain.h 557 2003-11-02 22:51:59Z twisti $
37 typedef struct chainlink { /* structure for list element */
38 struct chainlink *next;
39 struct chainlink *prev;
43 typedef struct chain { /* structure for list */
52 /* function prototypes */
55 void chain_free(chain *c);
57 void chain_addafter(chain *c, void *element);
58 void chain_addbefore(chain *c, void *element);
59 void chain_addlast(chain *c, void *element);
60 void chain_addfirst(chain *c, void *element);
62 void chain_remove(chain *c);
63 void *chain_remove_go_prev(chain *c);
64 void chain_removespecific(chain *c, void *element);
66 void *chain_next(chain *c);
67 void *chain_prev(chain *c);
68 void *chain_this(chain *c);
70 void *chain_first(chain *c);
71 void *chain_last(chain *c);
75 --------------------------- interface description ------------------------
77 Usage of these functions for list management is possible without additional
78 preparation in the element structures, as opposed to the module 'list'.
80 Consequently, the functions are a little slower and need more memory.
82 A new list is created with
85 The latter allocates all additional data structures on the dump memory (faster)
86 for which no explicit freeing is necessary after the processing. Care needs to
87 be taken to not accidentally free parts of these structures by calling
88 'dump_release' too early.
90 After usage, a list can be freed with
92 (use only if the list was created with 'chain_new')
95 Adding elements is easy with:
96 chain_addafter, chain_addlast, chain_addbefore, chain_addfirst
99 chain_first, chain_last, chain_prev, chain_next, chain_this
101 Delete elements from the list:
102 chain_remove, chain_remove_go_prev, chain_removespecific
105 ATTENTION: As mentioned earlier, there are no pointers to the list or to other
106 nodes inside the list elements, so list elements cannot be used as pointers
107 into the list. Therefore a 'cursor' is used to make one element current. Every
108 insertion/deletion occurs at a position relative to this cursor.
112 #endif /* _CHAIN_H */
116 * These are local overrides for various environment variables in Emacs.
117 * Please do not remove this and leave it at the end of the file, where
118 * Emacs will automagically detect them.
119 * ---------------------------------------------------------------------
122 * indent-tabs-mode: t