1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

Renamings and small reorganizations.

This commit is contained in:
Bruno Haible
2003-04-09 10:24:59 +00:00
parent 3bdad49e79
commit bfefa088aa
3 changed files with 34 additions and 57 deletions

View File

@@ -1,5 +1,20 @@
2002-12-12 Bruno Haible <bruno@clisp.org> 2002-12-12 Bruno Haible <bruno@clisp.org>
* src/search.h (Search::keyword_list_length, Search::max_key_length,
Search::get_max_keysig_size, Search::prepare): Remove declarations.
(Search::prepare): Renamed from Search::preprepare.
(Search::_max_selchars_length): New field.
* src/search.cc (Search::prepare): Renamed from Search::preprepare.
(Search::prepare_asso_values): Merged with old Search::prepare.
Initialize _max_selchars_length.
(Search::keyword_list_length): Remove function. Use _list_len instead.
(Search::max_key_length): Remove function. Use _max_key_len instead.
(Search::get_max_keysig_size): Remove function. Use
_max_selchars_length instead.
(Search::count_possible_collisions, Search::find_asso_values): Update.
(Search::find_good_asso_values): Call just prepare_asso_values.
(Search::~Search): Update.
* src/output.h (Output::output_asso_values_ref): New declaration. * src/output.h (Output::output_asso_values_ref): New declaration.
* src/output.cc (char_to_index): Remove variable. * src/output.cc (char_to_index): Remove variable.
(Output::output_asso_values_ref): New function. (Output::output_asso_values_ref): New function.

View File

@@ -92,7 +92,7 @@ Search::Search (KeywordExt_List *list)
} }
void void
Search::preprepare () Search::prepare ()
{ {
KeywordExt_List *temp; KeywordExt_List *temp;
@@ -670,14 +670,19 @@ Search::find_alpha_inc ()
/* ======================= Finding good asso_values ======================== */ /* ======================= Finding good asso_values ======================== */
/* Initializes the asso_values[] related parameters. */
void void
Search::prepare () Search::prepare_asso_values ()
{ {
KeywordExt_List *temp; KeywordExt_List *temp;
/* Initialize each keyword's _selchars array. */ /* Initialize each keyword's _selchars array. */
init_selchars_multiset(_key_positions, _alpha_unify, _alpha_inc); init_selchars_multiset(_key_positions, _alpha_unify, _alpha_inc);
/* Compute the maximum _selchars_length over all keywords. */
_max_selchars_length = _key_positions.iterator(_max_key_len).remaining();
/* Check for duplicates, i.e. keywords with the same _selchars array /* Check for duplicates, i.e. keywords with the same _selchars array
(and - if !option[NOLENGTH] - also the same length). (and - if !option[NOLENGTH] - also the same length).
We deal with these by building an equivalence class, so that only We deal with these by building an equivalence class, so that only
@@ -768,42 +773,8 @@ Search::prepare ()
/* Memory allocation. */ /* Memory allocation. */
_asso_values = new int[_alpha_size]; _asso_values = new int[_alpha_size];
}
/* ------------------------------------------------------------------------- */ int non_linked_length = _list_len;
/* Returns the length of keyword list. */
int
Search::keyword_list_length () const
{
return _list_len;
}
/* Returns the maximum length of keywords. */
int
Search::max_key_length () const
{
return _max_key_len;
}
/* Returns the number of key positions. */
int
Search::get_max_keysig_size () const
{
return _key_positions.is_useall() ? _max_key_len : _key_positions.get_size();
}
/* ---------------------- Finding good asso_values[] ----------------------- */
/* Initializes the asso_values[] related parameters. */
void
Search::prepare_asso_values ()
{
int non_linked_length = keyword_list_length ();
unsigned int asso_value_max; unsigned int asso_value_max;
asso_value_max = asso_value_max =
@@ -824,8 +795,8 @@ Search::prepare_asso_values ()
/* Given the bound for _asso_values[c], we have a bound for the possible /* Given the bound for _asso_values[c], we have a bound for the possible
hash values, as computed in compute_hash(). */ hash values, as computed in compute_hash(). */
_max_hash_value = (option[NOLENGTH] ? 0 : max_key_length ()) _max_hash_value = (option[NOLENGTH] ? 0 : _max_key_len)
+ (_asso_value_max - 1) * get_max_keysig_size (); + (_asso_value_max - 1) * _max_selchars_length;
/* Allocate a sparse bit vector for detection of collisions of hash /* Allocate a sparse bit vector for detection of collisions of hash
values. */ values. */
_collision_detector = new Bool_Array (_max_hash_value + 1); _collision_detector = new Bool_Array (_max_hash_value + 1);
@@ -1031,7 +1002,7 @@ Search::count_possible_collisions (EquivalenceClass *partition, unsigned int c)
This leads to (|p|^2 - |p1|^2 - |p2|^2 - ...)/2 possible collisions. This leads to (|p|^2 - |p1|^2 - |p2|^2 - ...)/2 possible collisions.
Return the sum of this expression over all equivalence classes. */ Return the sum of this expression over all equivalence classes. */
unsigned int sum = 0; unsigned int sum = 0;
unsigned int m = get_max_keysig_size(); unsigned int m = _max_selchars_length;
unsigned int split_cardinalities[m+1]; unsigned int split_cardinalities[m+1];
for (EquivalenceClass *cls = partition; cls; cls = cls->_next) for (EquivalenceClass *cls = partition; cls; cls = cls->_next)
{ {
@@ -1383,8 +1354,8 @@ Search::find_asso_values ()
_asso_value_max = step->_asso_value_max; _asso_value_max = step->_asso_value_max;
/* Reinitialize _max_hash_value. */ /* Reinitialize _max_hash_value. */
_max_hash_value = _max_hash_value =
(option[NOLENGTH] ? 0 : max_key_length ()) (option[NOLENGTH] ? 0 : _max_key_len)
+ (_asso_value_max - 1) * get_max_keysig_size (); + (_asso_value_max - 1) * _max_selchars_length;
/* Reinitialize _collision_detector. */ /* Reinitialize _collision_detector. */
delete _collision_detector; delete _collision_detector;
_collision_detector = _collision_detector =
@@ -1459,7 +1430,6 @@ Search::compute_hash (KeywordExt *keyword) const
void void
Search::find_good_asso_values () Search::find_good_asso_values ()
{ {
prepare ();
prepare_asso_values (); prepare_asso_values ();
/* Search for good _asso_values[]. */ /* Search for good _asso_values[]. */
@@ -1557,7 +1527,7 @@ void
Search::optimize () Search::optimize ()
{ {
/* Preparations. */ /* Preparations. */
preprepare (); prepare ();
/* Step 1: Finding good byte positions. */ /* Step 1: Finding good byte positions. */
find_positions (); find_positions ();
@@ -1633,7 +1603,7 @@ Search::~Search ()
"\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n", "\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n",
_list_len, _total_keys, _total_duplicates, _max_key_len); _list_len, _total_keys, _total_duplicates, _max_key_len);
int field_width = get_max_keysig_size (); int field_width = _max_selchars_length;
fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n", fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n",
field_width, "selchars"); field_width, "selchars");
for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest()) for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest())

View File

@@ -39,7 +39,7 @@ public:
~Search (); ~Search ();
void optimize (); void optimize ();
private: private:
void preprepare (); void prepare ();
/* Computes the upper bound on the indices passed to asso_values[], /* Computes the upper bound on the indices passed to asso_values[],
assuming no alpha_increments. */ assuming no alpha_increments. */
@@ -76,17 +76,6 @@ private:
/* Find good _alpha_inc[]. */ /* Find good _alpha_inc[]. */
void find_alpha_inc (); void find_alpha_inc ();
void prepare ();
/* Returns the length of keyword list. */
int keyword_list_length () const;
/* Returns the maximum length of keywords. */
int max_key_length () const;
/* Returns the number of key positions. */
int get_max_keysig_size () const;
/* Initializes the asso_values[] related parameters. */ /* Initializes the asso_values[] related parameters. */
void prepare_asso_values (); void prepare_asso_values ();
@@ -136,6 +125,9 @@ public:
upper case characters to lower case characters (and maybe more). */ upper case characters to lower case characters (and maybe more). */
unsigned int * _alpha_unify; unsigned int * _alpha_unify;
/* Maximum _selchars_length over all keywords. */
unsigned int _max_selchars_length;
/* Total number of duplicates that have been moved to _duplicate_link lists /* Total number of duplicates that have been moved to _duplicate_link lists
(not counting their representatives which stay on the main list). */ (not counting their representatives which stay on the main list). */
int _total_duplicates; int _total_duplicates;