|
Packit |
b27855 |
/* This may look like C code, but it is really -*- C++ -*- */
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* Simple lookup table abstraction implemented as an Iteration Number Array.
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc.
|
|
Packit |
b27855 |
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
|
|
Packit |
b27855 |
and Bruno Haible <bruno@clisp.org>.
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
This file is part of GNU GPERF.
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
b27855 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
b27855 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
b27855 |
(at your option) any later version.
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
b27855 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
b27855 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
b27855 |
GNU General Public License for more details.
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
You should have received a copy of the GNU General Public License
|
|
Packit |
b27855 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
#ifndef bool_array_h
|
|
Packit |
b27855 |
#define bool_array_h 1
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* A Bool_Array instance is a bit array of fixed size, optimized for being
|
|
Packit |
b27855 |
filled sparsely and cleared frequently. For example, when processing
|
|
Packit |
b27855 |
tests/chill.gperf, the array will be:
|
|
Packit |
b27855 |
- of size 15391,
|
|
Packit |
b27855 |
- clear will be called 3509 times,
|
|
Packit |
b27855 |
- set_bit will be called 300394 times.
|
|
Packit |
b27855 |
With a conventional bit array implementation, clear would be too slow.
|
|
Packit |
b27855 |
With a tree/hash based bit array implementation, set_bit would be slower. */
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
class Bool_Array
|
|
Packit |
b27855 |
{
|
|
Packit |
b27855 |
public:
|
|
Packit |
b27855 |
/* Initializes the bit array with room for SIZE bits, numbered from
|
|
Packit |
b27855 |
0 to SIZE-1. */
|
|
Packit |
b27855 |
Bool_Array (unsigned int size);
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* Frees this object. */
|
|
Packit |
b27855 |
~Bool_Array ();
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* Resets all bits to zero. */
|
|
Packit |
b27855 |
void clear ();
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* Sets the specified bit to true.
|
|
Packit |
b27855 |
Returns its previous value (false or true). */
|
|
Packit |
b27855 |
bool set_bit (unsigned int index);
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
private:
|
|
Packit |
b27855 |
/* Size of array. */
|
|
Packit |
b27855 |
unsigned int const _size;
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* Current iteration number. Always nonzero. Starts out as 1, and is
|
|
Packit |
b27855 |
incremented each time clear() is called. */
|
|
Packit |
b27855 |
unsigned int _iteration_number;
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
/* For each index, we store in storage_array[index] the iteration_number at
|
|
Packit |
b27855 |
the time set_bit(index) was last called. */
|
|
Packit |
b27855 |
unsigned int * const _storage_array;
|
|
Packit |
b27855 |
};
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
#ifdef __OPTIMIZE__ /* efficiency hack! */
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
#include <stdio.h>
|
|
Packit |
b27855 |
#include <string.h>
|
|
Packit |
b27855 |
#include "options.h"
|
|
Packit |
b27855 |
#define INLINE inline
|
|
Packit |
b27855 |
#include "bool-array.icc"
|
|
Packit |
b27855 |
#undef INLINE
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
#endif
|
|
Packit |
b27855 |
|
|
Packit |
b27855 |
#endif
|