bool-array.icc revision 228060
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 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) 12 any later version. 13 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. 18 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. */ 23 24// This needs: 25//#include <stdio.h> 26//#include <string.h> 27//#include "options.h" 28 29/* Initializes the bit array with room for SIZE bits, numbered from 30 0 to SIZE-1. */ 31INLINE 32Bool_Array::Bool_Array (unsigned int size) 33 : _size (size), 34 _iteration_number (1), 35 _storage_array (new unsigned int [size]) 36{ 37 memset (_storage_array, 0, size * sizeof (_storage_array[0])); 38 if (option[DEBUG]) 39 fprintf (stderr, "\nbool array size = %d, total bytes = %d\n", 40 _size, 41 static_cast<unsigned int> (_size * sizeof (_storage_array[0]))); 42} 43 44/* Sets the specified bit to true. 45 Returns its previous value (false or true). */ 46INLINE bool 47Bool_Array::set_bit (unsigned int index) 48{ 49 if (_storage_array[index] == _iteration_number) 50 /* The bit was set since the last clear() call. */ 51 return true; 52 else 53 { 54 /* The last operation on this bit was clear(). Set it now. */ 55 _storage_array[index] = _iteration_number; 56 return false; 57 } 58} 59 60/* Resets all bits to zero. */ 61INLINE void 62Bool_Array::clear () 63{ 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. */ 67 68 if (++_iteration_number == 0) 69 { 70 _iteration_number = 1; 71 memset (_storage_array, 0, _size * sizeof (_storage_array[0])); 72 if (option[DEBUG]) 73 { 74 fprintf (stderr, "(re-initialized bool_array)\n"); 75 fflush (stderr); 76 } 77 } 78} 79