1 /* src/toolbox/chain.c - 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
29 Changes: Christian Thalinger
31 $Id: chain.c 4357 2006-01-22 23:33:38Z twisti $
40 #include "mm/memory.h"
41 #include "toolbox/chain.h"
44 chain *chain_new(void)
58 chain *chain_dnew(void)
72 void chain_free(chain *c)
80 chainlink *nextl = l->next;
90 void chain_addafter(chain *c, void *element)
98 newlink = DNEW(chainlink);
101 newlink = NEW(chainlink);
104 newlink->element = element;
107 newlink->next = active->next;
108 newlink->prev = active;
110 active->next = newlink;
112 newlink->next->prev = newlink;
119 newlink->next = NULL;
120 newlink->prev = NULL;
129 void chain_addbefore(chain *c, void *element)
137 newlink = DNEW(chainlink);
140 newlink = NEW(chainlink);
143 newlink->element = element;
146 newlink->next = active;
147 newlink->prev = active->prev;
149 active->prev = newlink;
151 newlink->prev->next = newlink;
158 newlink->next = NULL;
159 newlink->prev = NULL;
168 void chain_addlast(chain *c, void *e)
171 chain_addafter(c, e);
175 void chain_addfirst(chain *c, void *e)
178 chain_addbefore(c, e);
182 void chain_remove(chain *c)
190 active->next->prev = active->prev;
193 c->last = active->prev;
197 active->prev->next = active->next;
200 c->first = active->next;
205 c->active = active->prev;
208 c->active = active->next;
212 FREE(active, chainlink);
216 void *chain_remove_go_prev(chain *c)
219 return chain_this(c);
224 void chain_removespecific(chain *c, void *e)
240 void *chain_next(chain *c)
250 c->active = active->next;
251 return c->active->element;
258 void *chain_prev(chain *c)
268 c->active = active->prev;
269 return c->active->element;
276 void *chain_this(chain *c)
279 return c->active->element;
285 void *chain_first(chain *c)
287 c->active = c->first;
290 return c->active->element;
295 void *chain_last(chain *c)
300 return c->active->element;
307 * These are local overrides for various environment variables in Emacs.
308 * Please do not remove this and leave it at the end of the file, where
309 * Emacs will automagically detect them.
310 * ---------------------------------------------------------------------
313 * indent-tabs-mode: t