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
32 #include "mm/memory.h"
33 #include "toolbox/worklist.h"
36 /******************************************************************************
38 Worklist Implementation
40 New Elements (integers) are pushed on a stack and remembered in a
41 bitvector, to ensure efficitently uniqueness.
43 ******************************************************************************/
45 /*******************************************************************************
48 IN: int size size of worklist
50 RETURN: worklist * new worklist
51 *******************************************************************************/
52 worklist *wl_new(int size) {
56 w->W_stack = DMNEW(int, size);
58 w->W_bv = bv_new(size);
65 /*******************************************************************************
68 Adds the integer element to the worklist, if this value is not already
71 IN: worklist *w pointer to worklist created with wl_new
72 int element integer element to be added
73 *******************************************************************************/
74 void wl_add(worklist *w, int element) {
75 _WL_CHECK_BOUNDS(element, 0, w->size);
76 if (!bv_get_bit(w->W_bv, element)) {
77 _BV_ASSERT((w->W_top < w->size));
78 w->W_stack[(w->W_top)++] = element;
79 bv_set_bit(w->W_bv, element);
83 /*******************************************************************************
86 Returns and removes an element from the worklist.
88 IN: worklist *w pointer to worklist created with wl_new
90 RETURN int an element removed from the worklist
91 *******************************************************************************/
92 int wl_get(worklist *w) {
95 _WL_ASSERT((w->W_top > 0));
96 element = w->W_stack[--(w->W_top)];
97 bv_reset_bit(w->W_bv, element);
101 /*******************************************************************************
104 Checks if the worklist is empty.
106 IN: worklist *w pointer to worklist created with wl_new
108 RETURN bool true if w is empty, false otherwise
109 *******************************************************************************/
110 bool wl_is_empty(worklist *w) {
111 return (w->W_top == 0);
114 /*******************************************************************************
117 Empties the worklist.
119 IN: worklist *w pointer to worklist created with wl_new
120 *******************************************************************************/
121 void wl_reset(worklist *w, int size) {
123 bv_reset(w->W_bv, size);
127 * These are local overrides for various environment variables in Emacs.
128 * Please do not remove this and leave it at the end of the file, where
129 * Emacs will automagically detect them.
130 * ---------------------------------------------------------------------
133 * indent-tabs-mode: t