summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-01-14 12:45:46 +0000
committerBruno Haible <bruno@clisp.org>2003-01-14 12:45:46 +0000
commitc67f999b54f456288561652503e8ad314a671f98 (patch)
tree0ae11fbb7dde5077fcf928488d32d7b2dadbfe6e
parentf60e559cfa329bc7ee25132b1a589327eb240404 (diff)
downloadgperf-c67f999b54f456288561652503e8ad314a671f98.tar.gz
Bug fix: make -j 0 work.
-rw-r--r--ChangeLog7
-rw-r--r--src/search.cc48
-rw-r--r--src/search.h5
3 files changed, 38 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index ddabf85..55e718c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2002-11-03 Bruno Haible <bruno@clisp.org>
+ Bug fix: When option -j 0 was used without option -r, the output was
+ not random.
+ * src/search.h (Search::prepare_asso_values): New method declaration.
+ * src/search.cc (Search::prepare_asso_values): New method, extracted
+ from Search::init_asso_values. Call srand also when "-j 0" was given.
+ (Search::optimize): Call prepare_asso_values().
+
* src/hash-table.h (Hash_Table::_ignore_length, Hash_Table::equal):
Declare as const.
* src/hash-table.cc (Hash_Table::equal): Declare as const.
diff --git a/src/search.cc b/src/search.cc
index 7e58f4b..3935260 100644
--- a/src/search.cc
+++ b/src/search.cc
@@ -386,11 +386,10 @@ Search::get_max_keysig_size () const
/* ---------------------- Finding good asso_values[] ----------------------- */
-/* Initializes the asso_values[] related parameters and put a first guess
- into asso_values[]. */
+/* Initializes the asso_values[] related parameters. */
void
-Search::init_asso_values ()
+Search::prepare_asso_values ()
{
int size_multiple = option.get_size_multiple ();
int non_linked_length = keyword_list_length ();
@@ -416,22 +415,6 @@ Search::init_asso_values ()
asso_value_max++;
_asso_value_max = asso_value_max;
- if (option[RANDOM])
- {
- srand (reinterpret_cast<long>(time (0)));
-
- for (int i = 0; i < _alpha_size; i++)
- _asso_values[i] = rand () & (asso_value_max - 1);
- }
- else
- {
- int asso_value = option.get_initial_asso_value ();
-
- asso_value = asso_value & (_asso_value_max - 1);
- for (int i = 0; i < _alpha_size; i++)
- _asso_values[i] = asso_value;
- }
-
/* Given the bound for _asso_values[c], we have a bound for the possible
hash values, as computed in compute_hash(). */
_max_hash_value = (option[NOLENGTH] ? 0 : max_key_length ())
@@ -447,6 +430,30 @@ Search::init_asso_values ()
fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d"
"\nmaximum size of generated hash table is %d\n",
non_linked_length, asso_value_max, _max_hash_value);
+
+ if (option[RANDOM] || option.get_jump () == 0)
+ /* We will use rand(), so initialize the random number generator. */
+ srand (reinterpret_cast<long>(time (0)));
+}
+
+/* Puts a first guess into asso_values[]. */
+
+void
+Search::init_asso_values ()
+{
+ if (option[RANDOM])
+ {
+ for (int i = 0; i < _alpha_size; i++)
+ _asso_values[i] = rand () & (_asso_value_max - 1);
+ }
+ else
+ {
+ int asso_value = option.get_initial_asso_value ();
+
+ asso_value = asso_value & (_asso_value_max - 1);
+ for (int i = 0; i < _alpha_size; i++)
+ _asso_values[i] = asso_value;
+ }
}
/* Computes a keyword's hash value, relative to the current _asso_values[],
@@ -723,6 +730,7 @@ Search::optimize ()
prepare ();
if (option[ORDER])
reorder ();
+ prepare_asso_values ();
/* Search for good _asso_values[]. */
find_asso_values ();
@@ -748,7 +756,7 @@ Search::optimize ()
}
}
- /* Sorts the key word list by hash value. */
+ /* Sorts the keyword list by hash value. */
sort ();
}
diff --git a/src/search.h b/src/search.h
index 540887c..c8e0766 100644
--- a/src/search.h
+++ b/src/search.h
@@ -62,8 +62,9 @@ private:
/* Returns the number of key positions. */
int get_max_keysig_size () const;
- /* Initializes the asso_values[] related parameters and put a first guess
- into asso_values[]. */
+ /* Initializes the asso_values[] related parameters. */
+ void prepare_asso_values ();
+ /* Puts a first guess into asso_values[]. */
void init_asso_values ();
/* Computes a keyword's hash value, relative to the current _asso_values[],