summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-04-09 10:24:59 +0000
committerBruno Haible <bruno@clisp.org>2003-04-09 10:24:59 +0000
commitbfefa088aa22eb8f026e93ee1c372fe18c3fa3a1 (patch)
tree2a7c601567b956ac42857b9ec88bb870e53ee7b4
parent3bdad49e79619a0de67bb9ea112829417f4eabcd (diff)
downloadgperf-bfefa088aa22eb8f026e93ee1c372fe18c3fa3a1.tar.gz
Renamings and small reorganizations.
-rw-r--r--ChangeLog15
-rw-r--r--src/search.cc60
-rw-r--r--src/search.h16
3 files changed, 34 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index c69b0b0..ab7c47d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
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.cc (char_to_index): Remove variable.
(Output::output_asso_values_ref): New function.
diff --git a/src/search.cc b/src/search.cc
index 61fb5ef..04608c1 100644
--- a/src/search.cc
+++ b/src/search.cc
@@ -92,7 +92,7 @@ Search::Search (KeywordExt_List *list)
}
void
-Search::preprepare ()
+Search::prepare ()
{
KeywordExt_List *temp;
@@ -670,14 +670,19 @@ Search::find_alpha_inc ()
/* ======================= Finding good asso_values ======================== */
+/* Initializes the asso_values[] related parameters. */
+
void
-Search::prepare ()
+Search::prepare_asso_values ()
{
KeywordExt_List *temp;
/* Initialize each keyword's _selchars array. */
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
(and - if !option[NOLENGTH] - also the same length).
We deal with these by building an equivalence class, so that only
@@ -768,42 +773,8 @@ Search::prepare ()
/* Memory allocation. */
_asso_values = new int[_alpha_size];
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* 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 ();
+ int non_linked_length = _list_len;
unsigned int 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
hash values, as computed in compute_hash(). */
- _max_hash_value = (option[NOLENGTH] ? 0 : max_key_length ())
- + (_asso_value_max - 1) * get_max_keysig_size ();
+ _max_hash_value = (option[NOLENGTH] ? 0 : _max_key_len)
+ + (_asso_value_max - 1) * _max_selchars_length;
/* Allocate a sparse bit vector for detection of collisions of hash
values. */
_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.
Return the sum of this expression over all equivalence classes. */
unsigned int sum = 0;
- unsigned int m = get_max_keysig_size();
+ unsigned int m = _max_selchars_length;
unsigned int split_cardinalities[m+1];
for (EquivalenceClass *cls = partition; cls; cls = cls->_next)
{
@@ -1383,8 +1354,8 @@ Search::find_asso_values ()
_asso_value_max = step->_asso_value_max;
/* Reinitialize _max_hash_value. */
_max_hash_value =
- (option[NOLENGTH] ? 0 : max_key_length ())
- + (_asso_value_max - 1) * get_max_keysig_size ();
+ (option[NOLENGTH] ? 0 : _max_key_len)
+ + (_asso_value_max - 1) * _max_selchars_length;
/* Reinitialize _collision_detector. */
delete _collision_detector;
_collision_detector =
@@ -1459,7 +1430,6 @@ Search::compute_hash (KeywordExt *keyword) const
void
Search::find_good_asso_values ()
{
- prepare ();
prepare_asso_values ();
/* Search for good _asso_values[]. */
@@ -1557,7 +1527,7 @@ void
Search::optimize ()
{
/* Preparations. */
- preprepare ();
+ prepare ();
/* Step 1: Finding good byte positions. */
find_positions ();
@@ -1633,7 +1603,7 @@ Search::~Search ()
"\ntotal keywords = %d\ntotal duplicates = %d\nmaximum key length = %d\n",
_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",
field_width, "selchars");
for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest())
diff --git a/src/search.h b/src/search.h
index 9d14aec..17c874c 100644
--- a/src/search.h
+++ b/src/search.h
@@ -39,7 +39,7 @@ public:
~Search ();
void optimize ();
private:
- void preprepare ();
+ void prepare ();
/* Computes the upper bound on the indices passed to asso_values[],
assuming no alpha_increments. */
@@ -76,17 +76,6 @@ private:
/* Find good _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. */
void prepare_asso_values ();
@@ -136,6 +125,9 @@ public:
upper case characters to lower case characters (and maybe more). */
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
(not counting their representatives which stay on the main list). */
int _total_duplicates;