diff options
author | Bruno Haible <bruno@clisp.org> | 2003-02-14 12:52:29 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2003-02-14 12:52:29 +0000 |
commit | 799d1c7534f4366fe1592b3b010e0a8be3eb3863 (patch) | |
tree | 31356f2f56cb9d42a5e5c5e79a3d05bd604f7137 | |
parent | ee135115f5da5bcfe6626a08fb91891d2aa2ee86 (diff) | |
download | gperf-799d1c7534f4366fe1592b3b010e0a8be3eb3863.tar.gz |
Change element type of _selchars from 'unsigned char' to 'unsigned int'.
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | src/hash-table.cc | 20 | ||||
-rw-r--r-- | src/keyword.cc | 12 | ||||
-rw-r--r-- | src/keyword.h | 2 | ||||
-rw-r--r-- | src/search.cc | 62 | ||||
-rw-r--r-- | src/search.h | 6 |
6 files changed, 79 insertions, 42 deletions
@@ -1,5 +1,24 @@ 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.icc: New file, extracted from options.icc. * src/positions.cc: New file, extracted from options.cc. diff --git a/src/hash-table.cc b/src/hash-table.cc index 6928eb6..6a2be7c 100644 --- a/src/hash-table.cc +++ b/src/hash-table.cc @@ -104,10 +104,15 @@ Hash_Table::~Hash_Table () for (int i = _size - 1; i >= 0; i--) if (_table[i]) - fprintf (stderr, "%8d, %*.*s, %.*s\n", - i, - field_width, _table[i]->_selchars_length, _table[i]->_selchars, - _table[i]->_allchars_length, _table[i]->_allchars); + { + fprintf (stderr, "%8d, ", i); + if (field_width > _table[i]->_selchars_length) + 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"); } @@ -119,7 +124,8 @@ inline bool Hash_Table::equal (KeywordExt *item1, KeywordExt *item2) const { 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 && (_ignore_length || item1->_allchars_length == item2->_allchars_length); @@ -130,7 +136,9 @@ Hash_Table::equal (KeywordExt *item1, KeywordExt *item2) const KeywordExt * 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 increment = (((hash_val >> _log_size) diff --git a/src/keyword.cc b/src/keyword.cc index 7ed112f..85cc565 100644 --- a/src/keyword.cc +++ b/src/keyword.cc @@ -31,14 +31,14 @@ /* --------------------------- KeywordExt class --------------------------- */ -/* Sort a small set of 'unsigned char', base[0..len-1], in place. */ -static inline void sort_char_set (unsigned char *base, int len) +/* Sort a small set of 'unsigned int', base[0..len-1], in place. */ +static inline void sort_char_set (unsigned int *base, int len) { /* Bubble sort is sufficient here. */ for (int i = 1; i < len; i++) { int j; - unsigned char tmp; + unsigned int tmp; for (j = i, tmp = base[j]; j > 0 && tmp < base[j - 1]; j--) base[j] = base[j - 1]; @@ -61,9 +61,9 @@ void KeywordExt::init_selchars (bool use_all_chars, const Positions& positions) { const char *k = _allchars; - unsigned char *key_set = - new unsigned char[(use_all_chars ? _allchars_length : positions.get_size ())]; - unsigned char *ptr = key_set; + unsigned int *key_set = + new unsigned int[(use_all_chars ? _allchars_length : positions.get_size ())]; + unsigned int *ptr = key_set; if (use_all_chars) /* Use all the character positions in the KEY. */ diff --git a/src/keyword.h b/src/keyword.h index 4f0b509..6c87d74 100644 --- a/src/keyword.h +++ b/src/keyword.h @@ -59,7 +59,7 @@ struct KeywordExt : public Keyword /* The selected characters that participate for the hash function, selected according to the keyposition list, as a canonically reordered multiset. */ - const unsigned char * _selchars; + const unsigned int * _selchars; int _selchars_length; /* Chained list of keywords having the same _selchars and - if !option[NOLENGTH] - also the same _allchars_length. diff --git a/src/search.cc b/src/search.cc index 98efcc6..a1e5335 100644 --- a/src/search.cc +++ b/src/search.cc @@ -316,10 +316,14 @@ Search::prepare () /* Complain if user hasn't enabled the duplicate option. */ if (!option[DUP] || option[DEBUG]) - fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"%.*s\".\n", - keyword->_allchars_length, keyword->_allchars, - other_keyword->_allchars_length, other_keyword->_allchars, - keyword->_selchars_length, keyword->_selchars); + { + fprintf (stderr, "Key link: \"%.*s\" = \"%.*s\", with key set \"", + keyword->_allchars_length, keyword->_allchars, + 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 { @@ -358,7 +362,7 @@ Search::prepare () for (temp = _head; temp; temp = temp->rest()) { 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--) _occurrences[*ptr]++; } @@ -377,7 +381,7 @@ Search::compute_occurrence (KeywordExt *ptr) const { int value = 0; - const unsigned char *p = ptr->_selchars; + const unsigned int *p = ptr->_selchars; unsigned int i = ptr->_selchars_length; for (; i > 0; p++, i--) value += _occurrences[*p]; @@ -407,7 +411,7 @@ Search::clear_determined () inline void Search::set_determined (KeywordExt *keyword) { - const unsigned char *p = keyword->_selchars; + const unsigned int *p = keyword->_selchars; unsigned int i = keyword->_selchars_length; for (; i > 0; p++, i--) _determined[*p] = true; @@ -419,7 +423,7 @@ Search::set_determined (KeywordExt *keyword) inline bool Search::already_determined (KeywordExt *keyword) const { - const unsigned char *p = keyword->_selchars; + const unsigned int *p = keyword->_selchars; unsigned int i = keyword->_selchars_length; for (; i > 0; p++, i--) if (!_determined[*p]) @@ -563,7 +567,7 @@ Search::prepare_asso_values () _collision_detector = new Bool_Array (_max_hash_value + 1); /* 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]) 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; - const unsigned char *p = keyword->_selchars; + const unsigned int *p = keyword->_selchars; int i = keyword->_selchars_length; for (; i > 0; p++, i--) sum += _asso_values[*p]; @@ -624,11 +628,11 @@ Search::compute_hash (KeywordExt *keyword) const Returns the size of the resulting set. */ inline int -compute_disjoint_union (const unsigned char *set_1, int size_1, - const unsigned char *set_2, int size_2, - unsigned char *set_3) +compute_disjoint_union (const unsigned int *set_1, int size_1, + const unsigned int *set_2, int size_2, + unsigned int *set_3) { - unsigned char *base = set_3; + unsigned int *base = set_3; while (size_1 > 0 && size_2 > 0) if (*set_1 == *set_2) @@ -638,7 +642,7 @@ compute_disjoint_union (const unsigned char *set_1, int size_1, } else { - unsigned char next; + unsigned int next; if (*set_1 < *set_2) next = *set_1++, size_1--; else @@ -649,7 +653,7 @@ compute_disjoint_union (const unsigned char *set_1, int size_1, while (size_1 > 0) { - unsigned char next; + unsigned int next; next = *set_1++, size_1--; if (set_3 == base || next != set_3[-1]) *set_3++ = next; @@ -657,7 +661,7 @@ compute_disjoint_union (const unsigned char *set_1, int size_1, while (size_2 > 0) { - unsigned char next; + unsigned int next; next = *set_2++, size_2--; if (set_3 == base || next != set_3[-1]) *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[]. */ 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. */ for (int i = 1; i < len; i++) { int curr; - unsigned char tmp; + unsigned int tmp; for (curr = i, tmp = set[curr]; 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! */ 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]; @@ -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 hash functions of prior and curr with different multiplicity. So we compute the set of such c. */ - unsigned char *union_set = _union_set; + unsigned int *union_set = _union_set; int union_set_length = compute_disjoint_union (prior->_selchars, prior->_selchars_length, curr->_selchars, curr->_selchars_length, @@ -778,7 +782,7 @@ Search::change_some_asso_value (KeywordExt *prior, KeywordExt *curr) ? option.get_iterations () : keyword_list_length (); - const unsigned char *p = union_set; + const unsigned int *p = union_set; int i = union_set_length; for (; i > 0; p++, i--) 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", field_width, "selchars"); 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, - field_width, ptr->first()->_selchars_length, ptr->first()->_selchars, - ptr->first()->_allchars_length, ptr->first()->_allchars); + { + fprintf (stderr, "%11d,%11d,%6d, ", + ptr->first()->_hash_value, ptr->first()->_allchars_length, ptr->first()->_final_index); + 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"); } diff --git a/src/search.h b/src/search.h index 363c9b3..a260686 100644 --- a/src/search.h +++ b/src/search.h @@ -80,10 +80,10 @@ private: int compute_hash (KeywordExt *keyword) const; /* 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]. */ - 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 collision between the two given keywords. */ @@ -152,7 +152,7 @@ private: int _fewest_collisions; /* 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. */ int _num_done; |