1 /* Inline Functions for bool-array.{h,cc}.
3 Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc.
4 Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
5 and Bruno Haible <bruno@clisp.org>.
7 This file is part of GNU GPERF.
9 GNU GPERF is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU GPERF is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING.
21 If not, write to the Free Software Foundation, Inc.,
22 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
27 //#include "options.h"
29 /* Initializes the bit array with room for SIZE bits, numbered from
32 Bool_Array::Bool_Array (unsigned int size)
34 _iteration_number (1),
35 _storage_array (new unsigned int [size])
37 memset (_storage_array, 0, size * sizeof (_storage_array[0]));
39 fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
41 static_cast<unsigned int> (_size * sizeof (_storage_array[0])));
44 /* Sets the specified bit to true.
45 Returns its previous value (false or true). */
47 Bool_Array::set_bit (unsigned int index)
49 if (_storage_array[index] == _iteration_number)
50 /* The bit was set since the last clear() call. */
54 /* The last operation on this bit was clear(). Set it now. */
55 _storage_array[index] = _iteration_number;
60 /* Resets all bits to zero. */
64 /* If we wrap around it's time to zero things out again! However, this only
65 occurs once about every 2^32 iterations, so it will not happen more
66 frequently than once per second. */
68 if (++_iteration_number == 0)
70 _iteration_number = 1;
71 memset (_storage_array, 0, _size * sizeof (_storage_array[0]));
74 fprintf (stderr, "(re-initialized bool_array)\n");