mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 21:19:24 +00:00
Some polishing.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
2002-10-13 Bruno Haible <bruno@clisp.org>
|
2002-10-13 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
|
* src/bool-array.*: Some polishing.
|
||||||
|
|
||||||
* src/options.h (Options::operator=, Options::operator!=): Remove
|
* src/options.h (Options::operator=, Options::operator!=): Remove
|
||||||
unused methods.
|
unused methods.
|
||||||
* src/options.icc (Options::operator=, Options::operator!=): Remove.
|
* src/options.icc (Options::operator=, Options::operator!=): Remove.
|
||||||
|
|||||||
@@ -32,11 +32,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|||||||
- set_bit will be called 300394 times.
|
- set_bit will be called 300394 times.
|
||||||
With a conventional bit array implementation, clear would be too slow.
|
With a conventional bit array implementation, clear would be too slow.
|
||||||
With a tree/hash based bit array implementation, set_bit would be slower. */
|
With a tree/hash based bit array implementation, set_bit would be slower. */
|
||||||
|
|
||||||
class Bool_Array
|
class Bool_Array
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* Initializes the bit array with room for s bits, numbered from 0 to s-1. */
|
/* Initializes the bit array with room for SIZE bits, numbered from
|
||||||
Bool_Array (unsigned int s);
|
0 to SIZE-1. */
|
||||||
|
Bool_Array (unsigned int size);
|
||||||
|
|
||||||
/* Frees this object. */
|
/* Frees this object. */
|
||||||
~Bool_Array ();
|
~Bool_Array ();
|
||||||
@@ -48,11 +50,16 @@ public:
|
|||||||
int set_bit (unsigned int index);
|
int set_bit (unsigned int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _size; /* Size of array. */
|
/* Size of array. */
|
||||||
unsigned int _iteration_number; /* Number of times clear() was called + 1. */
|
unsigned int const _size;
|
||||||
|
|
||||||
|
/* Current iteration number. Always nonzero. Starts out as 1, and is
|
||||||
|
incremented each time clear() is called. */
|
||||||
|
unsigned int _iteration_number;
|
||||||
|
|
||||||
/* For each index, we store in storage_array[index] the iteration_number at
|
/* For each index, we store in storage_array[index] the iteration_number at
|
||||||
the time set_bit(index) was last called. */
|
the time set_bit(index) was last called. */
|
||||||
unsigned int *_storage_array;
|
unsigned int * const _storage_array;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __OPTIMIZE__ /* efficiency hack! */
|
#ifdef __OPTIMIZE__ /* efficiency hack! */
|
||||||
|
|||||||
@@ -24,15 +24,18 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|||||||
//#include <string.h>
|
//#include <string.h>
|
||||||
//#include "options.h"
|
//#include "options.h"
|
||||||
|
|
||||||
/* Initializes the bit array with room for s bits, numbered from 0 to s-1. */
|
/* Initializes the bit array with room for SIZE bits, numbered from
|
||||||
|
0 to SIZE-1. */
|
||||||
INLINE
|
INLINE
|
||||||
Bool_Array::Bool_Array (unsigned int s)
|
Bool_Array::Bool_Array (unsigned int size)
|
||||||
: _size (s), _iteration_number (1), _storage_array (new unsigned int [s])
|
: _size (size),
|
||||||
|
_iteration_number (1),
|
||||||
|
_storage_array (new unsigned int [size])
|
||||||
{
|
{
|
||||||
memset (_storage_array, 0, s * sizeof (unsigned int));
|
memset (_storage_array, 0, size * sizeof (_storage_array[0]));
|
||||||
if (option[DEBUG])
|
if (option[DEBUG])
|
||||||
fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
|
fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
|
||||||
_size, (unsigned int) (_size * sizeof (*_storage_array)));
|
_size, (unsigned int) (_size * sizeof (_storage_array[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets the specified bit to one. Returns its previous value (0 or 1). */
|
/* Sets the specified bit to one. Returns its previous value (0 or 1). */
|
||||||
@@ -61,7 +64,7 @@ Bool_Array::clear ()
|
|||||||
if (++_iteration_number == 0)
|
if (++_iteration_number == 0)
|
||||||
{
|
{
|
||||||
_iteration_number = 1;
|
_iteration_number = 1;
|
||||||
memset (_storage_array, 0, _size * sizeof (unsigned int));
|
memset (_storage_array, 0, _size * sizeof (_storage_array[0]));
|
||||||
if (option[DEBUG])
|
if (option[DEBUG])
|
||||||
{
|
{
|
||||||
fprintf (stderr, "(re-initialized bool_array)\n");
|
fprintf (stderr, "(re-initialized bool_array)\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user