Mercurial > hg > xemacs-beta
comparison src/hash.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 7d59cb494b73 |
children | de805c49cfc1 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
32 (((old) != (new)) && (!(testfun) || !(testfun) ((old),(new)))) | 32 (((old) != (new)) && (!(testfun) || !(testfun) ((old),(new)))) |
33 | 33 |
34 static void rehash (hentry *harray, struct hash_table *ht, hash_size_t size); | 34 static void rehash (hentry *harray, struct hash_table *ht, hash_size_t size); |
35 | 35 |
36 unsigned long | 36 unsigned long |
37 memory_hash (CONST void *xv, size_t size) | 37 memory_hash (const void *xv, size_t size) |
38 { | 38 { |
39 unsigned int h = 0; | 39 unsigned int h = 0; |
40 unsigned CONST char *x = (unsigned CONST char *) xv; | 40 unsigned const char *x = (unsigned const char *) xv; |
41 | 41 |
42 if (!x) return 0; | 42 if (!x) return 0; |
43 | 43 |
44 while (size--) | 44 while (size--) |
45 { | 45 { |
57 hash_table_size (size_t requested_size) | 57 hash_table_size (size_t requested_size) |
58 { | 58 { |
59 /* Return some prime near, but greater than or equal to, SIZE. | 59 /* Return some prime near, but greater than or equal to, SIZE. |
60 Decades from the time of writing, someone will have a system large | 60 Decades from the time of writing, someone will have a system large |
61 enough that the list below will be too short... */ | 61 enough that the list below will be too short... */ |
62 static CONST size_t primes [] = | 62 static const size_t primes [] = |
63 { | 63 { |
64 19, 29, 41, 59, 79, 107, 149, 197, 263, 347, 457, 599, 787, 1031, | 64 19, 29, 41, 59, 79, 107, 149, 197, 263, 347, 457, 599, 787, 1031, |
65 1361, 1777, 2333, 3037, 3967, 5167, 6719, 8737, 11369, 14783, | 65 1361, 1777, 2333, 3037, 3967, 5167, 6719, 8737, 11369, 14783, |
66 19219, 24989, 32491, 42257, 54941, 71429, 92861, 120721, 156941, | 66 19219, 24989, 32491, 42257, 54941, 71429, 92861, 120721, 156941, |
67 204047, 265271, 344857, 448321, 582821, 757693, 985003, 1280519, | 67 204047, 265271, 344857, 448321, 582821, 757693, 985003, 1280519, |
83 high = mid; | 83 high = mid; |
84 } | 84 } |
85 return primes [high]; | 85 return primes [high]; |
86 } | 86 } |
87 | 87 |
88 CONST void * | 88 const void * |
89 gethash (CONST void *key, struct hash_table *hash_table, CONST void **ret_value) | 89 gethash (const void *key, struct hash_table *hash_table, const void **ret_value) |
90 { | 90 { |
91 if (!key) | 91 if (!key) |
92 { | 92 { |
93 *ret_value = hash_table->zero_entry; | 93 *ret_value = hash_table->zero_entry; |
94 return (void *) hash_table->zero_set; | 94 return (void *) hash_table->zero_set; |
102 hash_table->hash_function ? | 102 hash_table->hash_function ? |
103 hash_table->hash_function (key) : | 103 hash_table->hash_function (key) : |
104 (unsigned long) key; | 104 (unsigned long) key; |
105 unsigned int hcode = hcode_initial % size; | 105 unsigned int hcode = hcode_initial % size; |
106 hentry *e = &harray [hcode]; | 106 hentry *e = &harray [hcode]; |
107 CONST void *e_key = e->key; | 107 const void *e_key = e->key; |
108 | 108 |
109 if (e_key ? | 109 if (e_key ? |
110 KEYS_DIFFER_P (e_key, key, test_function) : | 110 KEYS_DIFFER_P (e_key, key, test_function) : |
111 e->contents == NULL_ENTRY) | 111 e->contents == NULL_ENTRY) |
112 { | 112 { |
186 | 186 |
187 xfree (old_harray); | 187 xfree (old_harray); |
188 } | 188 } |
189 | 189 |
190 void | 190 void |
191 puthash (CONST void *key, void *contents, struct hash_table *hash_table) | 191 puthash (const void *key, void *contents, struct hash_table *hash_table) |
192 { | 192 { |
193 if (!key) | 193 if (!key) |
194 { | 194 { |
195 hash_table->zero_entry = contents; | 195 hash_table->zero_entry = contents; |
196 hash_table->zero_set = 1; | 196 hash_table->zero_set = 1; |
205 hash_table->hash_function (key) : | 205 hash_table->hash_function (key) : |
206 (unsigned long) key; | 206 (unsigned long) key; |
207 unsigned int hcode = hcode_initial % size; | 207 unsigned int hcode = hcode_initial % size; |
208 size_t h2 = size - 2; | 208 size_t h2 = size - 2; |
209 unsigned int incr = 1 + (hcode_initial % h2); | 209 unsigned int incr = 1 + (hcode_initial % h2); |
210 CONST void *e_key = harray [hcode].key; | 210 const void *e_key = harray [hcode].key; |
211 CONST void *oldcontents; | 211 const void *oldcontents; |
212 | 212 |
213 if (e_key && KEYS_DIFFER_P (e_key, key, test_function)) | 213 if (e_key && KEYS_DIFFER_P (e_key, key, test_function)) |
214 { | 214 { |
215 do | 215 do |
216 { | 216 { |
267 puthash (e->key, e->contents, hash_table); | 267 puthash (e->key, e->contents, hash_table); |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 void | 271 void |
272 remhash (CONST void *key, struct hash_table *hash_table) | 272 remhash (const void *key, struct hash_table *hash_table) |
273 { | 273 { |
274 if (!key) | 274 if (!key) |
275 { | 275 { |
276 hash_table->zero_entry = 0; | 276 hash_table->zero_entry = 0; |
277 hash_table->zero_set = 0; | 277 hash_table->zero_set = 0; |
285 (hash_table->hash_function) ? | 285 (hash_table->hash_function) ? |
286 (hash_table->hash_function (key)) : | 286 (hash_table->hash_function (key)) : |
287 ((unsigned long) key); | 287 ((unsigned long) key); |
288 unsigned int hcode = hcode_initial % size; | 288 unsigned int hcode = hcode_initial % size; |
289 hentry *e = &harray [hcode]; | 289 hentry *e = &harray [hcode]; |
290 CONST void *e_key = e->key; | 290 const void *e_key = e->key; |
291 | 291 |
292 if (e_key ? | 292 if (e_key ? |
293 KEYS_DIFFER_P (e_key, key, test_function) : | 293 KEYS_DIFFER_P (e_key, key, test_function) : |
294 e->contents == NULL_ENTRY) | 294 e->contents == NULL_ENTRY) |
295 { | 295 { |