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