mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
Make the option -s easier to use.
This commit is contained in:
17
ChangeLog
17
ChangeLog
@@ -1,3 +1,20 @@
|
||||
2002-12-07 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
* src/options.h (Options::get_size_multiple): Change return type to
|
||||
float.
|
||||
(Options::_size_multiple): Change type to float.
|
||||
* src/options.icc (Options::get_size_multiple): Change return type to
|
||||
float.
|
||||
* src/options.cc (Options::long_usage): Update description of option
|
||||
-s.
|
||||
(Options::~Options): Update.
|
||||
(Options::parse_options): For option -s, accept a fraction.
|
||||
* src/search.cc (Search::prepare_asso_values): Use get_size_multiple
|
||||
as it is.
|
||||
* tests/test-6.exp: Update.
|
||||
* doc/gperf.texi (Algorithmic Details): Update description of option
|
||||
-s.
|
||||
|
||||
2002-12-04 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
Improve debugging output.
|
||||
|
||||
@@ -1074,16 +1074,13 @@ table.
|
||||
Affects the size of the generated hash table. The numeric argument for
|
||||
this option indicates ``how many times larger or smaller'' the maximum
|
||||
associated value range should be, in relationship to the number of keywords.
|
||||
If the @var{size-multiple} is negative the maximum associated value is
|
||||
calculated by @emph{dividing} the number of keywords by it. For
|
||||
example, a value of 3 means ``allow the maximum associated value to be
|
||||
It can be written as an integer, a floating-point number or a fraction.
|
||||
For example, a value of 3 means ``allow the maximum associated value to be
|
||||
about 3 times larger than the number of input keywords''.
|
||||
|
||||
Conversely, a value of -3 means ``allow the maximum associated value to
|
||||
be about 3 times smaller than the number of input keywords''. Negative
|
||||
values are useful for limiting the overall size of the generated hash
|
||||
table, though this usually increases the number of duplicate hash
|
||||
values.
|
||||
Conversely, a value of 1/3 means ``allow the maximum associated value to
|
||||
be about 3 times smaller than the number of input keywords''. Values
|
||||
smaller than 1 are useful for limiting the overall size of the generated hash
|
||||
table, though the option @samp{-m} is better at this purpose.
|
||||
|
||||
If `generate switch' option @samp{-S} (or, equivalently, @samp{%switch}) is
|
||||
@emph{not} enabled, the maximum
|
||||
|
||||
@@ -234,7 +234,7 @@ Options::long_usage (FILE * stream) const
|
||||
" in relationship to the number of keys, e.g. a value\n"
|
||||
" of 3 means \"allow the maximum associated value to\n"
|
||||
" be about 3 times larger than the number of input\n"
|
||||
" keys\". Conversely, a value of -3 means \"make the\n"
|
||||
" keys\". Conversely, a value of 1/3 means \"make the\n"
|
||||
" maximum associated value about 3 times smaller than\n"
|
||||
" the number of input keys\". A larger table should\n"
|
||||
" decrease the time required for an unsuccessful\n"
|
||||
@@ -481,7 +481,7 @@ Options::~Options ()
|
||||
"\ninitializer suffix = %s"
|
||||
"\nasso_values iterations = %d"
|
||||
"\njump value = %d"
|
||||
"\nhash table size multiplier = %d"
|
||||
"\nhash table size multiplier = %g"
|
||||
"\ninitial associated value = %d"
|
||||
"\ndelimiters = %s"
|
||||
"\nnumber of switch statements = %d\n",
|
||||
@@ -873,8 +873,44 @@ Options::parse_options (int argc, char *argv[])
|
||||
}
|
||||
case 's': /* Range of associated values, determines size of final table. */
|
||||
{
|
||||
if (abs (_size_multiple = atoi (/*getopt*/optarg)) > 50)
|
||||
fprintf (stderr, "%d is excessive, did you really mean this?! (try `%s --help' for help)\n", _size_multiple, program_name);
|
||||
float numerator;
|
||||
float denominator = 1;
|
||||
bool invalid = false;
|
||||
char *endptr;
|
||||
|
||||
numerator = strtod (/*getopt*/optarg, &endptr);
|
||||
if (endptr == /*getopt*/optarg)
|
||||
invalid = true;
|
||||
else if (*endptr != '\0')
|
||||
{
|
||||
if (*endptr == '/')
|
||||
{
|
||||
char *denomptr = endptr + 1;
|
||||
denominator = strtod (denomptr, &endptr);
|
||||
if (endptr == denomptr || *endptr != '\0')
|
||||
invalid = true;
|
||||
}
|
||||
else
|
||||
invalid = true;
|
||||
}
|
||||
if (invalid)
|
||||
{
|
||||
fprintf (stderr, "Invalid value for option -s.\n");
|
||||
short_usage (stderr);
|
||||
exit (1);
|
||||
}
|
||||
_size_multiple = numerator / denominator;
|
||||
/* Backward compatibility: -3 means 1/3. */
|
||||
if (_size_multiple < 0)
|
||||
_size_multiple = 1 / (-_size_multiple);
|
||||
/* Catch stupid users. */
|
||||
if (_size_multiple == 0)
|
||||
_size_multiple = 1;
|
||||
/* Warnings. */
|
||||
if (_size_multiple > 50)
|
||||
fprintf (stderr, "Size multiple %g is excessive, did you really mean this?! (try '%s --help' for help)\n", _size_multiple, program_name);
|
||||
else if (_size_multiple < 0.01f)
|
||||
fprintf (stderr, "Size multiple %g is extremely small, did you really mean this?! (try '%s --help' for help)\n", _size_multiple, program_name);
|
||||
break;
|
||||
}
|
||||
case 'S': /* Generate switch statement output, rather than lookup table. */
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
void set_total_switches (int total_switches);
|
||||
|
||||
/* Returns the factor by which to multiply the generated table's size. */
|
||||
int get_size_multiple () const;
|
||||
float get_size_multiple () const;
|
||||
|
||||
/* Returns the generated function name. */
|
||||
const char * get_function_name () const;
|
||||
@@ -235,7 +235,7 @@ private:
|
||||
int _total_switches;
|
||||
|
||||
/* Factor by which to multiply the generated table's size. */
|
||||
int _size_multiple;
|
||||
float _size_multiple;
|
||||
|
||||
/* Names used for generated lookup function. */
|
||||
const char * _function_name;
|
||||
|
||||
@@ -87,7 +87,7 @@ Options::get_total_switches () const
|
||||
}
|
||||
|
||||
/* Returns the factor by which to multiply the generated table's size. */
|
||||
INLINE int
|
||||
INLINE float
|
||||
Options::get_size_multiple () const
|
||||
{
|
||||
return _size_multiple;
|
||||
|
||||
@@ -802,16 +802,11 @@ Search::get_max_keysig_size () const
|
||||
void
|
||||
Search::prepare_asso_values ()
|
||||
{
|
||||
int size_multiple = option.get_size_multiple ();
|
||||
int non_linked_length = keyword_list_length ();
|
||||
int asso_value_max;
|
||||
|
||||
if (size_multiple == 0)
|
||||
asso_value_max = non_linked_length;
|
||||
else if (size_multiple > 0)
|
||||
asso_value_max = non_linked_length * size_multiple;
|
||||
else /* if (size_multiple < 0) */
|
||||
asso_value_max = non_linked_length / -size_multiple;
|
||||
asso_value_max =
|
||||
static_cast<int>(non_linked_length * option.get_size_multiple());
|
||||
/* Round up to the next power of two. This makes it easy to ensure
|
||||
an _asso_value[c] is >= 0 and < asso_value_max. Also, the jump value
|
||||
being odd, it guarantees that Search::try_asso_value() will iterate
|
||||
|
||||
@@ -117,7 +117,7 @@ Algorithm employed by gperf:
|
||||
in relationship to the number of keys, e.g. a value
|
||||
of 3 means "allow the maximum associated value to
|
||||
be about 3 times larger than the number of input
|
||||
keys". Conversely, a value of -3 means "make the
|
||||
keys". Conversely, a value of 1/3 means "make the
|
||||
maximum associated value about 3 times smaller than
|
||||
the number of input keys". A larger table should
|
||||
decrease the time required for an unsuccessful
|
||||
|
||||
Reference in New Issue
Block a user