1 /* src/toolbox/worklist.c - worklist implementation
3 Copyright (C) 2005, 2006 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
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Ullrich
33 #include "mm/memory.h"
34 #include "toolbox/worklist.h"
37 /******************************************************************************
39 Worklist Implementation
41 New Elements (integers) are pushed on a stack and remembered in a
42 bitvector, to ensure efficitently uniqueness.
44 ******************************************************************************/
46 /*******************************************************************************
49 IN: int size size of worklist
51 RETURN: worklist * new worklist
52 *******************************************************************************/
53 worklist *wl_new(int size) {
57 w->W_stack = DMNEW(int, size);
59 w->W_bv = bv_new(size);
66 /*******************************************************************************
69 Adds the integer element to the worklist, if this value is not already
72 IN: worklist *w pointer to worklist created with wl_new
73 int element integer element to be added
74 *******************************************************************************/
75 void wl_add(worklist *w, int element) {
76 _WL_CHECK_BOUNDS(element, 0, w->size);
77 if (!bv_get_bit(w->W_bv, element)) {
78 _BV_ASSERT((w->W_top < w->size));
79 w->W_stack[(w->W_top)++] = element;
80 bv_set_bit(w->W_bv, element);
84 /*******************************************************************************
87 Returns and removes an element from the worklist.
89 IN: worklist *w pointer to worklist created with wl_new
91 RETURN int an element removed from the worklist
92 *******************************************************************************/
93 int wl_get(worklist *w) {
96 _WL_ASSERT((w->W_top > 0));
97 element = w->W_stack[--(w->W_top)];
98 bv_reset_bit(w->W_bv, element);
102 /*******************************************************************************
105 Checks if the worklist is empty.
107 IN: worklist *w pointer to worklist created with wl_new
109 RETURN bool true if w is empty, false otherwise
110 *******************************************************************************/
111 bool wl_is_empty(worklist *w) {
112 return (w->W_top == 0);
115 /*******************************************************************************
118 Empties the worklist.
120 IN: worklist *w pointer to worklist created with wl_new
121 *******************************************************************************/
122 void wl_reset(worklist *w, int size) {
124 bv_reset(w->W_bv, size);
128 * These are local overrides for various environment variables in Emacs.
129 * Please do not remove this and leave it at the end of the file, where
130 * Emacs will automagically detect them.
131 * ---------------------------------------------------------------------
134 * indent-tabs-mode: t