1 /* toolbox/chain.h - management of doubly linked lists with external linking
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
36 typedef struct chainlink { /* structure for list element */
37 struct chainlink *next;
38 struct chainlink *prev;
42 typedef struct chain { /* structure for list */
51 /* function prototypes */
52 chain *chain_new(void);
53 chain *chain_dnew(void);
54 void chain_free(chain *c);
56 void chain_addafter(chain *c, void *element);
57 void chain_addbefore(chain *c, void *element);
58 void chain_addlast(chain *c, void *element);
59 void chain_addfirst(chain *c, void *element);
61 void chain_remove(chain *c);
62 void *chain_remove_go_prev(chain *c);
63 void chain_removespecific(chain *c, void *element);
65 void *chain_next(chain *c);
66 void *chain_prev(chain *c);
67 void *chain_this(chain *c);
69 void *chain_first(chain *c);
70 void *chain_last(chain *c);
74 --------------------------- interface description ------------------------
76 Usage of these functions for list management is possible without additional
77 preparation in the element structures, as opposed to the module 'list'.
79 Consequently, the functions are a little slower and need more memory.
81 A new list is created with
84 The latter allocates all additional data structures on the dump memory (faster)
85 for which no explicit freeing is necessary after the processing. Care needs to
86 be taken to not accidentally free parts of these structures by calling
87 'dump_release' too early.
89 After usage, a list can be freed with
91 (use only if the list was created with 'chain_new')
94 Adding elements is easy with:
95 chain_addafter, chain_addlast, chain_addbefore, chain_addfirst
98 chain_first, chain_last, chain_prev, chain_next, chain_this
100 Delete elements from the list:
101 chain_remove, chain_remove_go_prev, chain_removespecific
104 ATTENTION: As mentioned earlier, there are no pointers to the list or to other
105 nodes inside the list elements, so list elements cannot be used as pointers
106 into the list. Therefore a 'cursor' is used to make one element current. Every
107 insertion/deletion occurs at a position relative to this cursor.
111 #endif /* _CHAIN_H */
115 * These are local overrides for various environment variables in Emacs.
116 * Please do not remove this and leave it at the end of the file, where
117 * Emacs will automagically detect them.
118 * ---------------------------------------------------------------------
121 * indent-tabs-mode: t