diff options
author | Bruno Haible <bruno@clisp.org> | 2003-03-10 15:01:00 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2003-03-10 15:01:00 +0000 |
commit | 6ba54862299937b54369f1d64f620ad2bc8fd60f (patch) | |
tree | 9069ea492a4d31083c86009b8322c3d6885e32c0 | |
parent | 9492f0dad7d0546e8efa62ee72ba7ce5d5899e55 (diff) | |
download | gperf-6ba54862299937b54369f1d64f620ad2bc8fd60f.tar.gz |
Make the option -s easier to use.
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | doc/gperf.texi | 17 | ||||
-rw-r--r-- | src/options.cc | 44 | ||||
-rw-r--r-- | src/options.h | 4 | ||||
-rw-r--r-- | src/options.icc | 2 | ||||
-rw-r--r-- | src/search.cc | 9 | ||||
-rw-r--r-- | tests/test-6.exp | 2 |
7 files changed, 70 insertions, 25 deletions
@@ -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. diff --git a/doc/gperf.texi b/doc/gperf.texi index f52bb04..c925cfc 100644 --- a/doc/gperf.texi +++ b/doc/gperf.texi @@ -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 -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. +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 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 diff --git a/src/options.cc b/src/options.cc index f743738..bfe4007 100644 --- a/src/options.cc +++ b/src/options.cc @@ -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. */ diff --git a/src/options.h b/src/options.h index 6053b45..2a20d57 100644 --- a/src/options.h +++ b/src/options.h @@ -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; diff --git a/src/options.icc b/src/options.icc index c84768a..c54af90 100644 --- a/src/options.icc +++ b/src/options.icc @@ -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; diff --git a/src/search.cc b/src/search.cc index a27b1fd..4d2c58f 100644 --- a/src/search.cc +++ b/src/search.cc @@ -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 diff --git a/tests/test-6.exp b/tests/test-6.exp index 6985dd9..1fa9072 100644 --- a/tests/test-6.exp +++ b/tests/test-6.exp @@ -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 |