From 5e5d12ca2d28df846ce1266b2794a57960a54832 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 12 Nov 2002 13:03:02 +0000 Subject: [PATCH] Some polishing. --- ChangeLog | 2 ++ src/bool-array.h | 17 ++++++++++++----- src/bool-array.icc | 15 +++++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index c772ea7..8c67a93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2002-10-13 Bruno Haible + * src/bool-array.*: Some polishing. + * src/options.h (Options::operator=, Options::operator!=): Remove unused methods. * src/options.icc (Options::operator=, Options::operator!=): Remove. diff --git a/src/bool-array.h b/src/bool-array.h index 45425d9..d9842ec 100644 --- a/src/bool-array.h +++ b/src/bool-array.h @@ -32,11 +32,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - set_bit will be called 300394 times. With a conventional bit array implementation, clear would be too slow. With a tree/hash based bit array implementation, set_bit would be slower. */ + class Bool_Array { public: - /* Initializes the bit array with room for s bits, numbered from 0 to s-1. */ - Bool_Array (unsigned int s); + /* Initializes the bit array with room for SIZE bits, numbered from + 0 to SIZE-1. */ + Bool_Array (unsigned int size); /* Frees this object. */ ~Bool_Array (); @@ -48,11 +50,16 @@ public: int set_bit (unsigned int index); private: - unsigned int _size; /* Size of array. */ - unsigned int _iteration_number; /* Number of times clear() was called + 1. */ + /* Size of array. */ + 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 the time set_bit(index) was last called. */ - unsigned int *_storage_array; + unsigned int * const _storage_array; }; #ifdef __OPTIMIZE__ /* efficiency hack! */ diff --git a/src/bool-array.icc b/src/bool-array.icc index 35eef84..6a41cdf 100644 --- a/src/bool-array.icc +++ b/src/bool-array.icc @@ -24,15 +24,18 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ //#include //#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 -Bool_Array::Bool_Array (unsigned int s) - : _size (s), _iteration_number (1), _storage_array (new unsigned int [s]) +Bool_Array::Bool_Array (unsigned int size) + : _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]) 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). */ @@ -61,7 +64,7 @@ Bool_Array::clear () if (++_iteration_number == 0) { _iteration_number = 1; - memset (_storage_array, 0, _size * sizeof (unsigned int)); + memset (_storage_array, 0, _size * sizeof (_storage_array[0])); if (option[DEBUG]) { fprintf (stderr, "(re-initialized bool_array)\n");