1/* Inline Functions for bool-array.{h,cc}. 2 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>. 6 7 This file is part of GNU GPERF. 8 9 This program 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 3 of the License, or 12 (at your option) any later version. 13 14 This program 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. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21 22// This needs: 23//#include <stdio.h> 24//#include <string.h> 25//#include "options.h" 26 27/* Initializes the bit array with room for SIZE bits, numbered from 28 0 to SIZE-1. */ 29INLINE 30Bool_Array::Bool_Array (unsigned int size) 31 : _size (size), 32 _iteration_number (1), 33 _storage_array (new unsigned int [size]) 34{ 35 memset (_storage_array, 0, size * sizeof (_storage_array[0])); 36 if (option[DEBUG]) 37 fprintf (stderr, "\nbool array size = %d, total bytes = %d\n", 38 _size, 39 static_cast<unsigned int> (_size * sizeof (_storage_array[0]))); 40} 41 42/* Sets the specified bit to true. 43 Returns its previous value (false or true). */ 44INLINE bool 45Bool_Array::set_bit (unsigned int index) 46{ 47 if (_storage_array[index] == _iteration_number) 48 /* The bit was set since the last clear() call. */ 49 return true; 50 else 51 { 52 /* The last operation on this bit was clear(). Set it now. */ 53 _storage_array[index] = _iteration_number; 54 return false; 55 } 56} 57 58/* Resets all bits to zero. */ 59INLINE void 60Bool_Array::clear () 61{ 62 /* If we wrap around it's time to zero things out again! However, this only 63 occurs once about every 2^32 iterations, so it will not happen more 64 frequently than once per second. */ 65 66 if (++_iteration_number == 0) 67 { 68 _iteration_number = 1; 69 memset (_storage_array, 0, _size * sizeof (_storage_array[0])); 70 if (option[DEBUG]) 71 { 72 fprintf (stderr, "(re-initialized bool_array)\n"); 73 fflush (stderr); 74 } 75 } 76} 77