mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
Change element type of _selchars from 'unsigned char' to 'unsigned int'.
This commit is contained in:
19
ChangeLog
19
ChangeLog
@@ -1,5 +1,24 @@
|
|||||||
2002-11-17 Bruno Haible <bruno@clisp.org>
|
2002-11-17 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
|
* src/keyword.h (KeywordExt::_selchars): Change type to
|
||||||
|
'const unsigned int *'.
|
||||||
|
* src/keyword.cc (sort_char_set): Change argument type to
|
||||||
|
'unsigned int *'.
|
||||||
|
(KeywordExt::init_selchars): Update.
|
||||||
|
* src/search.h (Search::sort_by_occurrence): Change argument type to
|
||||||
|
'unsigned int *'.
|
||||||
|
(Search::try_asso_value): Change argument type to 'unsigned int'.
|
||||||
|
(Search::_union_set): Change type to 'unsigned int *'.
|
||||||
|
* src/search.cc (Search::prepare, Search::compute_occurrence,
|
||||||
|
Search::set_determined, Search::already_determined,
|
||||||
|
Search::prepare_asso_values, Search::compute_hash): Update.
|
||||||
|
(compute_disjoint_union): Change argument types to 'unsigned int *'.
|
||||||
|
(Search::sort_by_occurrence): Likewise.
|
||||||
|
(Search::try_asso_value): Change argument type to 'unsigned int'.
|
||||||
|
(Search::change_some_asso_value, Search::~Search): Update.
|
||||||
|
* src/hash-table.cc (Hash_Table::~Hash_Table, Hash_Table::equal,
|
||||||
|
Hash_Table::insert): Update.
|
||||||
|
|
||||||
* src/positions.h: New file, extracted from options.h.
|
* src/positions.h: New file, extracted from options.h.
|
||||||
* src/positions.icc: New file, extracted from options.icc.
|
* src/positions.icc: New file, extracted from options.icc.
|
||||||
* src/positions.cc: New file, extracted from options.cc.
|
* src/positions.cc: New file, extracted from options.cc.
|
||||||
|
|||||||
@@ -104,10 +104,15 @@ Hash_Table::~Hash_Table ()
|
|||||||
|
|
||||||
for (int i = _size - 1; i >= 0; i--)
|
for (int i = _size - 1; i >= 0; i--)
|
||||||
if (_table[i])
|
if (_table[i])
|
||||||
fprintf (stderr, "%8d, %*.*s, %.*s\n",
|
{
|
||||||
i,
|
fprintf (stderr, "%8d, ", i);
|
||||||
field_width, _table[i]->_selchars_length, _table[i]->_selchars,
|
if (field_width > _table[i]->_selchars_length)
|
||||||
_table[i]->_allchars_length, _table[i]->_allchars);
|
fprintf (stderr, "%*s", field_width - _table[i]->_selchars_length, "");
|
||||||
|
for (int j = 0; j < _table[i]->_selchars_length; j++)
|
||||||
|
putc (_table[i]->_selchars[j], stderr);
|
||||||
|
fprintf (stderr, ", %.*s\n",
|
||||||
|
_table[i]->_allchars_length, _table[i]->_allchars);
|
||||||
|
}
|
||||||
|
|
||||||
fprintf (stderr, "\nend dumping hash table\n\n");
|
fprintf (stderr, "\nend dumping hash table\n\n");
|
||||||
}
|
}
|
||||||
@@ -119,7 +124,8 @@ inline bool
|
|||||||
Hash_Table::equal (KeywordExt *item1, KeywordExt *item2) const
|
Hash_Table::equal (KeywordExt *item1, KeywordExt *item2) const
|
||||||
{
|
{
|
||||||
return item1->_selchars_length == item2->_selchars_length
|
return item1->_selchars_length == item2->_selchars_length
|
||||||
&& memcmp (item1->_selchars, item2->_selchars, item2->_selchars_length)
|
&& memcmp (item1->_selchars, item2->_selchars,
|
||||||
|
item2->_selchars_length * sizeof (unsigned int))
|
||||||
== 0
|
== 0
|
||||||
&& (_ignore_length
|
&& (_ignore_length
|
||||||
|| item1->_allchars_length == item2->_allchars_length);
|
|| item1->_allchars_length == item2->_allchars_length);
|
||||||
@@ -130,7 +136,9 @@ Hash_Table::equal (KeywordExt *item1, KeywordExt *item2) const
|
|||||||
KeywordExt *
|
KeywordExt *
|
||||||
Hash_Table::insert (KeywordExt *item)
|
Hash_Table::insert (KeywordExt *item)
|
||||||
{
|
{
|
||||||
unsigned hash_val = hashpjw (item->_selchars, item->_selchars_length);
|
unsigned hash_val =
|
||||||
|
hashpjw (reinterpret_cast<const unsigned char *>(item->_selchars),
|
||||||
|
item->_selchars_length * sizeof (unsigned int));
|
||||||
unsigned int probe = hash_val & (_size - 1);
|
unsigned int probe = hash_val & (_size - 1);
|
||||||
unsigned int increment =
|
unsigned int increment =
|
||||||
(((hash_val >> _log_size)
|
(((hash_val >> _log_size)
|
||||||
|
|||||||
@@ -31,14 +31,14 @@
|
|||||||
|
|
||||||
/* --------------------------- KeywordExt class --------------------------- */
|
/* --------------------------- KeywordExt class --------------------------- */
|
||||||
|
|
||||||
/* Sort a small set of 'unsigned char', base[0..len-1], in place. */
|
/* Sort a small set of 'unsigned int', base[0..len-1], in place. */
|
||||||
static inline void sort_char_set (unsigned char *base, int len)
|
static inline void sort_char_set (unsigned int *base, int len)
|
||||||
{
|
{
|
||||||
/* Bubble sort is sufficient here. */
|
/* Bubble sort is sufficient here. */
|
||||||
for (int i = 1; i < len; i++)
|
for (int i = 1; i < len; i++)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
unsigned char tmp;
|
unsigned int tmp;
|
||||||
|
|
||||||
for (j = i, tmp = base[j]; j > 0 && tmp < base[j - 1]; j--)
|
for (j = i, tmp = base[j]; j > 0 && tmp < base[j - 1]; j--)
|
||||||
base[j] = base[j - 1];
|
base[j] = base[j - 1];
|
||||||
@@ -61,9 +61,9 @@ void
|
|||||||
KeywordExt::init_selchars (bool use_all_chars, const Positions& positions)
|
KeywordExt::init_selchars (bool use_all_chars, const Positions& positions)
|
||||||
{
|
{
|
||||||
const char *k = _allchars;
|
const char *k = _allchars;
|
||||||
unsigned char *key_set =
|
unsigned int *key_set =
|
||||||
new unsigned char[(use_all_chars ? _allchars_length : positions.get_size ())];
|
new unsigned int[(use_all_chars ? _allchars_length : positions.get_size ())];
|
||||||
unsigned char *ptr = key_set;
|
unsigned int *ptr = key_set;
|
||||||
|
|
||||||
if (use_all_chars)
|
if (use_all_chars)
|
||||||
/* Use all the character positions in the KEY. */
|
/* Use all the character positions in the KEY. */
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ struct KeywordExt : public Keyword
|
|||||||
/* The selected characters that participate for the hash function,
|
/* The selected characters that participate for the hash function,
|
||||||
selected according to the keyposition list, as a canonically reordered
|
selected according to the keyposition list, as a canonically reordered
|
||||||
multiset. */
|
multiset. */
|
||||||
const unsigned char * _selchars;
|
const unsigned int * _selchars;
|
||||||
int _selchars_length;
|
int _selchars_length;
|
||||||
/* Chained list of keywords having the same _selchars and
|
/* Chained list of keywords having the same _selchars and
|
||||||
- if !option[NOLENGTH] - also the same _allchars_length.
|
- if !option[NOLENGTH] - also the same _allchars_length.
|
||||||
|
|||||||
@@ -316,10 +316,14 @@ Search::prepare ()
|
|||||||
|
|
||||||
/* Complain if user hasn't enabled the duplicate option. */
|
/* Complain if user hasn't enabled the duplicate option. */
|
||||||
if (!option[DUP] || option[DEBUG])
|
if (!option[DUP] || option[DEBUG])
|
||||||
fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"%.*s\".\n",
|
{
|
||||||
keyword->_allchars_length, keyword->_allchars,
|
fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"",
|
||||||
other_keyword->_allchars_length, other_keyword->_allchars,
|
keyword->_allchars_length, keyword->_allchars,
|
||||||
keyword->_selchars_length, keyword->_selchars);
|
other_keyword->_allchars_length, other_keyword->_allchars);
|
||||||
|
for (int j = 0; j < keyword->_selchars_length; j++)
|
||||||
|
putc (keyword->_selchars[j], stderr);
|
||||||
|
fprintf (stderr, "\".\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -358,7 +362,7 @@ Search::prepare ()
|
|||||||
for (temp = _head; temp; temp = temp->rest())
|
for (temp = _head; temp; temp = temp->rest())
|
||||||
{
|
{
|
||||||
KeywordExt *keyword = temp->first();
|
KeywordExt *keyword = temp->first();
|
||||||
const unsigned char *ptr = keyword->_selchars;
|
const unsigned int *ptr = keyword->_selchars;
|
||||||
for (int count = keyword->_selchars_length; count > 0; ptr++, count--)
|
for (int count = keyword->_selchars_length; count > 0; ptr++, count--)
|
||||||
_occurrences[*ptr]++;
|
_occurrences[*ptr]++;
|
||||||
}
|
}
|
||||||
@@ -377,7 +381,7 @@ Search::compute_occurrence (KeywordExt *ptr) const
|
|||||||
{
|
{
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
|
||||||
const unsigned char *p = ptr->_selchars;
|
const unsigned int *p = ptr->_selchars;
|
||||||
unsigned int i = ptr->_selchars_length;
|
unsigned int i = ptr->_selchars_length;
|
||||||
for (; i > 0; p++, i--)
|
for (; i > 0; p++, i--)
|
||||||
value += _occurrences[*p];
|
value += _occurrences[*p];
|
||||||
@@ -407,7 +411,7 @@ Search::clear_determined ()
|
|||||||
inline void
|
inline void
|
||||||
Search::set_determined (KeywordExt *keyword)
|
Search::set_determined (KeywordExt *keyword)
|
||||||
{
|
{
|
||||||
const unsigned char *p = keyword->_selchars;
|
const unsigned int *p = keyword->_selchars;
|
||||||
unsigned int i = keyword->_selchars_length;
|
unsigned int i = keyword->_selchars_length;
|
||||||
for (; i > 0; p++, i--)
|
for (; i > 0; p++, i--)
|
||||||
_determined[*p] = true;
|
_determined[*p] = true;
|
||||||
@@ -419,7 +423,7 @@ Search::set_determined (KeywordExt *keyword)
|
|||||||
inline bool
|
inline bool
|
||||||
Search::already_determined (KeywordExt *keyword) const
|
Search::already_determined (KeywordExt *keyword) const
|
||||||
{
|
{
|
||||||
const unsigned char *p = keyword->_selchars;
|
const unsigned int *p = keyword->_selchars;
|
||||||
unsigned int i = keyword->_selchars_length;
|
unsigned int i = keyword->_selchars_length;
|
||||||
for (; i > 0; p++, i--)
|
for (; i > 0; p++, i--)
|
||||||
if (!_determined[*p])
|
if (!_determined[*p])
|
||||||
@@ -563,7 +567,7 @@ Search::prepare_asso_values ()
|
|||||||
_collision_detector = new Bool_Array (_max_hash_value + 1);
|
_collision_detector = new Bool_Array (_max_hash_value + 1);
|
||||||
|
|
||||||
/* Allocate scratch set. */
|
/* Allocate scratch set. */
|
||||||
_union_set = new unsigned char [2 * get_max_keysig_size ()];
|
_union_set = new unsigned int [2 * get_max_keysig_size ()];
|
||||||
|
|
||||||
if (option[DEBUG])
|
if (option[DEBUG])
|
||||||
fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d"
|
fprintf (stderr, "total non-linked keys = %d\nmaximum associated value is %d"
|
||||||
@@ -607,7 +611,7 @@ Search::compute_hash (KeywordExt *keyword) const
|
|||||||
{
|
{
|
||||||
int sum = option[NOLENGTH] ? 0 : keyword->_allchars_length;
|
int sum = option[NOLENGTH] ? 0 : keyword->_allchars_length;
|
||||||
|
|
||||||
const unsigned char *p = keyword->_selchars;
|
const unsigned int *p = keyword->_selchars;
|
||||||
int i = keyword->_selchars_length;
|
int i = keyword->_selchars_length;
|
||||||
for (; i > 0; p++, i--)
|
for (; i > 0; p++, i--)
|
||||||
sum += _asso_values[*p];
|
sum += _asso_values[*p];
|
||||||
@@ -624,11 +628,11 @@ Search::compute_hash (KeywordExt *keyword) const
|
|||||||
Returns the size of the resulting set. */
|
Returns the size of the resulting set. */
|
||||||
|
|
||||||
inline int
|
inline int
|
||||||
compute_disjoint_union (const unsigned char *set_1, int size_1,
|
compute_disjoint_union (const unsigned int *set_1, int size_1,
|
||||||
const unsigned char *set_2, int size_2,
|
const unsigned int *set_2, int size_2,
|
||||||
unsigned char *set_3)
|
unsigned int *set_3)
|
||||||
{
|
{
|
||||||
unsigned char *base = set_3;
|
unsigned int *base = set_3;
|
||||||
|
|
||||||
while (size_1 > 0 && size_2 > 0)
|
while (size_1 > 0 && size_2 > 0)
|
||||||
if (*set_1 == *set_2)
|
if (*set_1 == *set_2)
|
||||||
@@ -638,7 +642,7 @@ compute_disjoint_union (const unsigned char *set_1, int size_1,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned char next;
|
unsigned int next;
|
||||||
if (*set_1 < *set_2)
|
if (*set_1 < *set_2)
|
||||||
next = *set_1++, size_1--;
|
next = *set_1++, size_1--;
|
||||||
else
|
else
|
||||||
@@ -649,7 +653,7 @@ compute_disjoint_union (const unsigned char *set_1, int size_1,
|
|||||||
|
|
||||||
while (size_1 > 0)
|
while (size_1 > 0)
|
||||||
{
|
{
|
||||||
unsigned char next;
|
unsigned int next;
|
||||||
next = *set_1++, size_1--;
|
next = *set_1++, size_1--;
|
||||||
if (set_3 == base || next != set_3[-1])
|
if (set_3 == base || next != set_3[-1])
|
||||||
*set_3++ = next;
|
*set_3++ = next;
|
||||||
@@ -657,7 +661,7 @@ compute_disjoint_union (const unsigned char *set_1, int size_1,
|
|||||||
|
|
||||||
while (size_2 > 0)
|
while (size_2 > 0)
|
||||||
{
|
{
|
||||||
unsigned char next;
|
unsigned int next;
|
||||||
next = *set_2++, size_2--;
|
next = *set_2++, size_2--;
|
||||||
if (set_3 == base || next != set_3[-1])
|
if (set_3 == base || next != set_3[-1])
|
||||||
*set_3++ = next;
|
*set_3++ = next;
|
||||||
@@ -668,13 +672,13 @@ compute_disjoint_union (const unsigned char *set_1, int size_1,
|
|||||||
/* Sorts the given set in increasing frequency of _occurrences[]. */
|
/* Sorts the given set in increasing frequency of _occurrences[]. */
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
Search::sort_by_occurrence (unsigned char *set, int len) const
|
Search::sort_by_occurrence (unsigned int *set, int len) const
|
||||||
{
|
{
|
||||||
/* Use bubble sort, since the set is typically short. */
|
/* Use bubble sort, since the set is typically short. */
|
||||||
for (int i = 1; i < len; i++)
|
for (int i = 1; i < len; i++)
|
||||||
{
|
{
|
||||||
int curr;
|
int curr;
|
||||||
unsigned char tmp;
|
unsigned int tmp;
|
||||||
|
|
||||||
for (curr = i, tmp = set[curr];
|
for (curr = i, tmp = set[curr];
|
||||||
curr > 0 && _occurrences[tmp] < _occurrences[set[curr-1]];
|
curr > 0 && _occurrences[tmp] < _occurrences[set[curr-1]];
|
||||||
@@ -696,7 +700,7 @@ Search::sort_by_occurrence (unsigned char *set, int len) const
|
|||||||
This is called very frequently, and needs to be fast! */
|
This is called very frequently, and needs to be fast! */
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
Search::try_asso_value (unsigned char c, KeywordExt *curr, int iterations)
|
Search::try_asso_value (unsigned int c, KeywordExt *curr, int iterations)
|
||||||
{
|
{
|
||||||
int original_value = _asso_values[c];
|
int original_value = _asso_values[c];
|
||||||
|
|
||||||
@@ -760,7 +764,7 @@ Search::change_some_asso_value (KeywordExt *prior, KeywordExt *curr)
|
|||||||
change an _asso_values[c] for a character c that contributes to the
|
change an _asso_values[c] for a character c that contributes to the
|
||||||
hash functions of prior and curr with different multiplicity.
|
hash functions of prior and curr with different multiplicity.
|
||||||
So we compute the set of such c. */
|
So we compute the set of such c. */
|
||||||
unsigned char *union_set = _union_set;
|
unsigned int *union_set = _union_set;
|
||||||
int union_set_length =
|
int union_set_length =
|
||||||
compute_disjoint_union (prior->_selchars, prior->_selchars_length,
|
compute_disjoint_union (prior->_selchars, prior->_selchars_length,
|
||||||
curr->_selchars, curr->_selchars_length,
|
curr->_selchars, curr->_selchars_length,
|
||||||
@@ -778,7 +782,7 @@ Search::change_some_asso_value (KeywordExt *prior, KeywordExt *curr)
|
|||||||
? option.get_iterations ()
|
? option.get_iterations ()
|
||||||
: keyword_list_length ();
|
: keyword_list_length ();
|
||||||
|
|
||||||
const unsigned char *p = union_set;
|
const unsigned int *p = union_set;
|
||||||
int i = union_set_length;
|
int i = union_set_length;
|
||||||
for (; i > 0; p++, i--)
|
for (; i > 0; p++, i--)
|
||||||
if (!try_asso_value (*p, curr, iterations))
|
if (!try_asso_value (*p, curr, iterations))
|
||||||
@@ -1006,10 +1010,16 @@ Search::~Search ()
|
|||||||
fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n",
|
fprintf (stderr, "\nList contents are:\n(hash value, key length, index, %*s, keyword):\n",
|
||||||
field_width, "selchars");
|
field_width, "selchars");
|
||||||
for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest())
|
for (KeywordExt_List *ptr = _head; ptr; ptr = ptr->rest())
|
||||||
fprintf (stderr, "%11d,%11d,%6d, %*.*s, %.*s\n",
|
{
|
||||||
ptr->first()->_hash_value, ptr->first()->_allchars_length, ptr->first()->_final_index,
|
fprintf (stderr, "%11d,%11d,%6d, ",
|
||||||
field_width, ptr->first()->_selchars_length, ptr->first()->_selchars,
|
ptr->first()->_hash_value, ptr->first()->_allchars_length, ptr->first()->_final_index);
|
||||||
ptr->first()->_allchars_length, ptr->first()->_allchars);
|
if (field_width > ptr->first()->_selchars_length)
|
||||||
|
fprintf (stderr, "%*s", field_width - ptr->first()->_selchars_length, "");
|
||||||
|
for (int j = 0; j < ptr->first()->_selchars_length; j++)
|
||||||
|
putc (ptr->first()->_selchars[j], stderr);
|
||||||
|
fprintf (stderr, ", %.*s\n",
|
||||||
|
ptr->first()->_allchars_length, ptr->first()->_allchars);
|
||||||
|
}
|
||||||
|
|
||||||
fprintf (stderr, "End dumping list.\n\n");
|
fprintf (stderr, "End dumping list.\n\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,10 +80,10 @@ private:
|
|||||||
int compute_hash (KeywordExt *keyword) const;
|
int compute_hash (KeywordExt *keyword) const;
|
||||||
|
|
||||||
/* Sorts the given set in increasing frequency of _occurrences[]. */
|
/* Sorts the given set in increasing frequency of _occurrences[]. */
|
||||||
void sort_by_occurrence (unsigned char *set, int len) const;
|
void sort_by_occurrence (unsigned int *set, int len) const;
|
||||||
|
|
||||||
/* Tries various other values for _asso_values[c]. */
|
/* Tries various other values for _asso_values[c]. */
|
||||||
bool try_asso_value (unsigned char c, KeywordExt *curr, int iterations);
|
bool try_asso_value (unsigned int c, KeywordExt *curr, int iterations);
|
||||||
|
|
||||||
/* Attempts to change an _asso_value[], in order to resolve a hash value
|
/* Attempts to change an _asso_value[], in order to resolve a hash value
|
||||||
collision between the two given keywords. */
|
collision between the two given keywords. */
|
||||||
@@ -152,7 +152,7 @@ private:
|
|||||||
int _fewest_collisions;
|
int _fewest_collisions;
|
||||||
|
|
||||||
/* Scratch set, used during Search::change_some_asso_value. */
|
/* Scratch set, used during Search::change_some_asso_value. */
|
||||||
unsigned char * _union_set;
|
unsigned int * _union_set;
|
||||||
|
|
||||||
/* Number of keyword being handled during Search::find_asso_values. */
|
/* Number of keyword being handled during Search::find_asso_values. */
|
||||||
int _num_done;
|
int _num_done;
|
||||||
|
|||||||
Reference in New Issue
Block a user