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

Fill unused asso_values[] entries in search.cc, not in output.cc.

This commit is contained in:
Bruno Haible
2003-04-01 08:13:30 +00:00
parent 8193024d96
commit 0093e33163
5 changed files with 26 additions and 8 deletions

View File

@@ -1,5 +1,13 @@
2002-12-10 Bruno Haible <bruno@clisp.org> 2002-12-10 Bruno Haible <bruno@clisp.org>
* src/search.cc (Search::optimize): Fill unused asso_values[] entries
with a large value.
* src/output.h (Output::Output): Remove occurrences argument.
(Output::_occurrences): Remove field.
* src/output.cc (Output::Output): Remove occurrences argument.
(Output::output_hash_function): Ignore _occurrences.
* src/main.cc (main): Don't pass the _occurrences to Output.
* src/search.cc (Search::preprepare): Exit if keywords contain * src/search.cc (Search::preprepare): Exit if keywords contain
out-of-range characters. out-of-range characters.

View File

@@ -109,7 +109,6 @@ main (int argc, char *argv[])
searcher._alpha_inc, searcher._alpha_inc,
searcher._total_duplicates, searcher._total_duplicates,
searcher._alpha_size, searcher._alpha_size,
searcher._occurrences,
searcher._asso_values); searcher._asso_values);
outputter.output (); outputter.output ();

View File

@@ -89,7 +89,7 @@ Output::Output (KeywordExt_List *head, const char *struct_decl,
int total_keys, int max_key_len, int min_key_len, int total_keys, int max_key_len, int min_key_len,
const Positions& positions, const unsigned int *alpha_inc, const Positions& positions, const unsigned int *alpha_inc,
int total_duplicates, unsigned int alpha_size, int total_duplicates, unsigned int alpha_size,
const int *occurrences, const int *asso_values) const int *asso_values)
: _head (head), _struct_decl (struct_decl), : _head (head), _struct_decl (struct_decl),
_struct_decl_lineno (struct_decl_lineno), _return_type (return_type), _struct_decl_lineno (struct_decl_lineno), _return_type (return_type),
_struct_tag (struct_tag), _struct_tag (struct_tag),
@@ -103,7 +103,7 @@ Output::Output (KeywordExt_List *head, const char *struct_decl,
_max_key_len (max_key_len), _min_key_len (min_key_len), _max_key_len (max_key_len), _min_key_len (min_key_len),
_key_positions (positions), _alpha_inc (alpha_inc), _key_positions (positions), _alpha_inc (alpha_inc),
_total_duplicates (total_duplicates), _alpha_size (alpha_size), _total_duplicates (total_duplicates), _alpha_size (alpha_size),
_occurrences (occurrences), _asso_values (asso_values) _asso_values (asso_values)
{ {
} }
@@ -492,8 +492,7 @@ Output::output_hash_function () const
printf (","); printf (",");
if ((count % columns) == 0) if ((count % columns) == 0)
printf ("\n "); printf ("\n ");
printf ("%*d", field_width, printf ("%*d", field_width, _asso_values[count]);
_occurrences[count] ? _asso_values[count] : _max_hash_value + 1);
} }
printf ("\n" printf ("\n"

View File

@@ -54,7 +54,6 @@ public:
const unsigned int *alpha_inc, const unsigned int *alpha_inc,
int total_duplicates, int total_duplicates,
unsigned int alpha_size, unsigned int alpha_size,
const int *occurrences,
const int *asso_values); const int *asso_values);
/* Generates the hash function and the key word recognizer function. */ /* Generates the hash function and the key word recognizer function. */
@@ -132,8 +131,6 @@ private:
int _max_hash_value; int _max_hash_value;
/* Size of alphabet. */ /* Size of alphabet. */
unsigned int const _alpha_size; unsigned int const _alpha_size;
/* Counts occurrences of each key set character. */
const int * const _occurrences;
/* Value associated with each character. */ /* Value associated with each character. */
const int * const _asso_values; const int * const _asso_values;
}; };

View File

@@ -1477,6 +1477,21 @@ Search::optimize ()
/* Sorts the keyword list by hash value. */ /* Sorts the keyword list by hash value. */
sort (); sort ();
/* Set unused asso_values[c] to max_hash_value + 1. This is not absolutely
necessary, but speeds up the lookup function in many cases of lookup
failure: no string comparison is needed once the hash value of a string
is larger than the hash value of any keyword. */
int max_hash_value;
{
KeywordExt_List *temp;
for (temp = _head; temp->rest(); temp = temp->rest())
;
max_hash_value = temp->first()->_hash_value;
}
for (unsigned int c = 0; c < _alpha_size; c++)
if (_occurrences[c] == 0)
_asso_values[c] = max_hash_value + 1;
} }
/* Prints out some diagnostics upon completion. */ /* Prints out some diagnostics upon completion. */