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
38 #include "mm/memory.h"
39 #include "toolbox/chain.h"
42 chain *chain_new(void)
56 chain *chain_dnew(void)
70 void chain_free(chain *c)
78 chainlink *nextl = l->next;
88 void chain_addafter(chain *c, void *element)
96 newlink = DNEW(chainlink);
99 newlink = NEW(chainlink);
102 newlink->element = element;
105 newlink->next = active->next;
106 newlink->prev = active;
108 active->next = newlink;
110 newlink->next->prev = newlink;
117 newlink->next = NULL;
118 newlink->prev = NULL;
127 void chain_addbefore(chain *c, void *element)
135 newlink = DNEW(chainlink);
138 newlink = NEW(chainlink);
141 newlink->element = element;
144 newlink->next = active;
145 newlink->prev = active->prev;
147 active->prev = newlink;
149 newlink->prev->next = newlink;
156 newlink->next = NULL;
157 newlink->prev = NULL;
166 void chain_addlast(chain *c, void *e)
169 chain_addafter(c, e);
173 void chain_addfirst(chain *c, void *e)
176 chain_addbefore(c, e);
180 void chain_remove(chain *c)
188 active->next->prev = active->prev;
191 c->last = active->prev;
195 active->prev->next = active->next;
198 c->first = active->next;
203 c->active = active->prev;
206 c->active = active->next;
210 FREE(active, chainlink);
214 void *chain_remove_go_prev(chain *c)
217 return chain_this(c);
222 void chain_removespecific(chain *c, void *e)
238 void *chain_next(chain *c)
248 c->active = active->next;
249 return c->active->element;
256 void *chain_prev(chain *c)
266 c->active = active->prev;
267 return c->active->element;
274 void *chain_this(chain *c)
277 return c->active->element;
283 void *chain_first(chain *c)
285 c->active = c->first;
288 return c->active->element;
293 void *chain_last(chain *c)
298 return c->active->element;
305 * These are local overrides for various environment variables in Emacs.
306 * Please do not remove this and leave it at the end of the file, where
307 * Emacs will automagically detect them.
308 * ---------------------------------------------------------------------
311 * indent-tabs-mode: t