Mercurial > hg > xemacs-beta
diff src/hash.c @ 647:b39c14581166
[xemacs-hg @ 2001-08-13 04:45:47 by ben]
removal of unsigned, size_t, etc.
author | ben |
---|---|
date | Mon, 13 Aug 2001 04:46:48 +0000 |
parents | abe6d1db359e |
children | fdefd0186b75 |
line wrap: on
line diff
--- a/src/hash.c Wed Aug 08 12:15:04 2001 +0000 +++ b/src/hash.c Mon Aug 13 04:46:48 2001 +0000 @@ -31,19 +31,19 @@ #define KEYS_DIFFER_P(old, new, testfun) \ (((old) != (new)) && (!(testfun) || !(testfun) ((old),(new)))) -static void rehash (hentry *harray, struct hash_table *ht, hash_size_t size); +static void rehash (hentry *harray, struct hash_table *ht, Element_Count size); -unsigned long -memory_hash (const void *xv, size_t size) +Hash_Code +memory_hash (const void *xv, Memory_Count size) { - unsigned int h = 0; + Hash_Code h = 0; unsigned const char *x = (unsigned const char *) xv; if (!x) return 0; while (size--) { - unsigned int g; + Hash_Code g; h = (h << 4) + *x++; if ((g = h & 0xf0000000) != 0) h = (h ^ (g >> 24)) ^ g; @@ -52,17 +52,17 @@ return h; } -unsigned long +Hash_Code string_hash (const char *xv) { - unsigned int h = 0; + Hash_Code h = 0; unsigned const char *x = (unsigned const char *) xv; if (!x) return 0; while (*x) { - unsigned int g; + Hash_Code g; h = (h << 4) + *x++; if ((g = h & 0xf0000000) != 0) h = (h ^ (g >> 24)) ^ g; @@ -72,13 +72,13 @@ } /* Return a suitable size for a hash table, with at least SIZE slots. */ -static size_t -hash_table_size (size_t requested_size) +static Element_Count +hash_table_size (Element_Count requested_size) { /* Return some prime near, but greater than or equal to, SIZE. Decades from the time of writing, someone will have a system large enough that the list below will be too short... */ - static const size_t primes [] = + static const Element_Count primes [] = { 19, 29, 41, 59, 79, 107, 149, 197, 263, 347, 457, 599, 787, 1031, 1361, 1777, 2333, 3037, 3967, 5167, 6719, 8737, 11369, 14783, @@ -88,7 +88,7 @@ 10445899, 13579681, 17653589, 22949669, 29834603, 38784989, 50420551, 65546729, 85210757, 110774011, 144006217, 187208107, 243370577, 316381771, 411296309, 534685237, 695090819, 903618083, - 1174703521, 1527114613, 1985248999, 2580823717UL, 3355070839UL + 1174703521, 1527114613, 1985248999 /* , 2580823717UL, 3355070839UL */ }; /* We've heard of binary search. */ int low, high; @@ -116,12 +116,12 @@ { hentry *harray = hash_table->harray; hash_table_test_function test_function = hash_table->test_function; - hash_size_t size = hash_table->size; - unsigned int hcode_initial = + Element_Count size = hash_table->size; + Hash_Code hcode_initial = hash_table->hash_function ? hash_table->hash_function (key) : - (unsigned long) key; - unsigned int hcode = hcode_initial % size; + (Hash_Code) key; + Element_Count hcode = (Element_Count) (hcode_initial % size); hentry *e = &harray [hcode]; const void *e_key = e->key; @@ -129,8 +129,8 @@ KEYS_DIFFER_P (e_key, key, test_function) : e->contents == NULL_ENTRY) { - size_t h2 = size - 2; - unsigned int incr = 1 + (hcode_initial % h2); + Element_Count h2 = size - 2; + Element_Count incr = (Element_Count) (1 + (hcode_initial % h2)); do { hcode += incr; if (hcode >= size) hcode -= size; @@ -164,7 +164,7 @@ } struct hash_table* -make_hash_table (hash_size_t size) +make_hash_table (Element_Count size) { struct hash_table *hash_table = xnew_and_zero (struct hash_table); hash_table->size = hash_table_size (COMFORTABLE_SIZE (size)); @@ -174,7 +174,7 @@ } struct hash_table * -make_general_hash_table (hash_size_t size, +make_general_hash_table (Element_Count size, hash_table_hash_function hash_function, hash_table_test_function test_function) { @@ -185,9 +185,9 @@ } static void -grow_hash_table (struct hash_table *hash_table, hash_size_t new_size) +grow_hash_table (struct hash_table *hash_table, Element_Count new_size) { - hash_size_t old_size = hash_table->size; + Element_Count old_size = hash_table->size; hentry *old_harray = hash_table->harray; hash_table->size = hash_table_size (new_size); @@ -217,15 +217,15 @@ else { hash_table_test_function test_function = hash_table->test_function; - hash_size_t size = hash_table->size; + Element_Count size = hash_table->size; hentry *harray = hash_table->harray; - unsigned int hcode_initial = + Hash_Code hcode_initial = hash_table->hash_function ? hash_table->hash_function (key) : - (unsigned long) key; - unsigned int hcode = hcode_initial % size; - size_t h2 = size - 2; - unsigned int incr = 1 + (hcode_initial % h2); + (Hash_Code) key; + Element_Count hcode = (Element_Count) (hcode_initial % size); + Element_Count h2 = size - 2; + Element_Count incr = (Element_Count) (1 + (hcode_initial % h2)); const void *e_key = harray [hcode].key; const void *oldcontents; @@ -268,7 +268,7 @@ /* only increment the fullness when we used up a new hentry */ if (!e_key || KEYS_DIFFER_P (e_key, key, test_function)) { - hash_size_t comfortable_size = COMFORTABLE_SIZE (++(hash_table->fullness)); + Element_Count comfortable_size = COMFORTABLE_SIZE (++(hash_table->fullness)); if (hash_table->size < comfortable_size) grow_hash_table (hash_table, comfortable_size + 1); } @@ -276,7 +276,7 @@ } static void -rehash (hentry *harray, struct hash_table *hash_table, hash_size_t size) +rehash (hentry *harray, struct hash_table *hash_table, Element_Count size) { hentry *limit = harray + size; hentry *e; @@ -299,12 +299,12 @@ { hentry *harray = hash_table->harray; hash_table_test_function test_function = hash_table->test_function; - hash_size_t size = hash_table->size; - unsigned int hcode_initial = + Element_Count size = hash_table->size; + Hash_Code hcode_initial = (hash_table->hash_function) ? (hash_table->hash_function (key)) : - ((unsigned long) key); - unsigned int hcode = hcode_initial % size; + ((Hash_Code) key); + Element_Count hcode = (Element_Count) (hcode_initial % size); hentry *e = &harray [hcode]; const void *e_key = e->key; @@ -312,8 +312,8 @@ KEYS_DIFFER_P (e_key, key, test_function) : e->contents == NULL_ENTRY) { - size_t h2 = size - 2; - unsigned int incr = 1 + (hcode_initial % h2); + Element_Count h2 = size - 2; + Element_Count incr = (Element_Count) (1 + (hcode_initial % h2)); do { hcode += incr; if (hcode >= size) hcode -= size;