* Removed all Id tags.
[cacao.git] / src / toolbox / chain.h
1 /* toolbox/chain.h - management of doubly linked lists with external linking
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Reinhard Grafl
28
29
30 */
31
32
33 #ifndef _CHAIN_H
34 #define _CHAIN_H
35
36 typedef struct chainlink {          /* structure for list element */
37         struct chainlink *next;
38         struct chainlink *prev;
39         void *element;
40 } chainlink;
41
42 typedef struct chain {              /* structure for list */
43         int  usedump;   
44
45         chainlink *first;
46         chainlink *last;
47         chainlink *active;
48 } chain;
49
50
51 /* function prototypes */
52 chain *chain_new(void);
53 chain *chain_dnew(void);
54 void chain_free(chain *c);
55
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);
60
61 void chain_remove(chain *c);
62 void *chain_remove_go_prev(chain *c);
63 void chain_removespecific(chain *c, void *element);
64
65 void *chain_next(chain *c);
66 void *chain_prev(chain *c);
67 void *chain_this(chain *c);
68
69 void *chain_first(chain *c);
70 void *chain_last(chain *c);
71
72
73 /*
74 --------------------------- interface description ------------------------
75
76 Usage of these functions for list management is possible without additional
77 preparation in the element structures, as opposed to the module 'list'.
78
79 Consequently, the functions are a little slower and need more memory.
80
81 A new list is created with
82         chain_new
83 or  chain_dnew.
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.
88
89 After usage, a list can be freed with
90         chain_free.
91 (use only if the list was created with 'chain_new')
92
93
94 Adding elements is easy with:
95         chain_addafter, chain_addlast, chain_addbefore, chain_addfirst          
96         
97 Search the list with:
98         chain_first, chain_last, chain_prev, chain_next, chain_this
99         
100 Delete elements from the list:
101         chain_remove, chain_remove_go_prev, chain_removespecific
102         
103         
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.
108
109 */
110
111 #endif /* _CHAIN_H */
112
113
114 /*
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  * ---------------------------------------------------------------------
119  * Local variables:
120  * mode: c
121  * indent-tabs-mode: t
122  * c-basic-offset: 4
123  * tab-width: 4
124  * End:
125  */