|
142 | 142 | {
|
143 | 143 | REBCNT *hashes;
|
144 | 144 | REBVAL *word;
|
145 |
| - REBINT hash; |
| 145 | + REBCNT key; |
| 146 | + REBCNT hash=0; |
146 | 147 | REBCNT size;
|
147 |
| - REBINT skip; |
148 |
| - REBCNT n; |
| 148 | + REBCNT n, i; |
149 | 149 |
|
150 | 150 | // Allocate a new hash table:
|
151 | 151 | Expand_Hash(PG_Word_Table.hashes);
|
|
156 | 156 | hashes = (REBCNT *)PG_Word_Table.hashes->data;
|
157 | 157 | size = PG_Word_Table.hashes->tail;
|
158 | 158 | for (n = 1; n < PG_Word_Table.series->tail; n++, word++) {
|
159 |
| - hash = Hash_Word(VAL_SYM_NAME(word), -1); |
160 |
| - skip = (hash & 0x0000FFFF) % size; |
161 |
| - if (skip == 0) skip = 1; |
162 |
| - hash = (hash & 0x00FFFF00) % size; |
163 |
| - while (hashes[hash]) { |
164 |
| - hash += skip; |
165 |
| - if (hash >= (REBINT)size) hash -= size; |
| 159 | + key = CRC_Word(VAL_SYM_NAME(word), UNKNOWN); |
| 160 | + for (i = 0; i < size; i++) { |
| 161 | + hash = Hash_Probe(key, i, size); |
| 162 | + if (!hashes[hash]) break; |
166 | 163 | }
|
167 | 164 | hashes[hash] = n;
|
168 | 165 | }
|
|
196 | 193 | **
|
197 | 194 | ***********************************************************************/
|
198 | 195 | {
|
199 |
| - REBINT hash; |
200 |
| - REBINT size; |
201 |
| - REBINT skip; |
| 196 | + REBCNT key; |
| 197 | + REBCNT hash = 0; |
| 198 | + REBLEN size; |
202 | 199 | REBINT n;
|
203 |
| - REBCNT h; |
| 200 | + REBCNT h=0, i; |
204 | 201 | REBCNT *hashes;
|
205 | 202 | REBVAL *words;
|
206 | 203 | REBVAL *w;
|
|
225 | 222 | CLEAR_SERIES(Bind_Table);
|
226 | 223 | }
|
227 | 224 |
|
228 |
| - size = (REBINT)PG_Word_Table.hashes->tail; |
| 225 | + size = PG_Word_Table.hashes->tail; |
229 | 226 | words = BLK_HEAD(PG_Word_Table.series);
|
230 | 227 | hashes = (REBCNT *)PG_Word_Table.hashes->data;
|
231 | 228 |
|
232 | 229 | // Hash the word, including a skip factor for lookup:
|
233 |
| - hash = Hash_Word(str, len); |
234 |
| - skip = (hash & 0x0000FFFF) % size; |
235 |
| - if (skip == 0) skip = 1; |
236 |
| - hash = (hash & 0x00FFFF00) % size; |
237 |
| - //Debug_Fmt("%s hash %d skip %d", str, hash, skip); |
238 |
| - |
| 230 | + key = CRC_Word(str, len); |
239 | 231 | // Search hash table for word match:
|
240 |
| - while (NZ(h = hashes[hash])) { |
241 |
| - while ((n = Compare_UTF8(VAL_SYM_NAME(words+h), str, len)) >= 0) { |
242 |
| - //if (Match_String("script", str, len)) |
243 |
| - // Debug_Fmt("---- %s %d %d\n", VAL_SYM_NAME(&words[h]), n, h); |
| 232 | + for (i = 0; i < size; i++) { |
| 233 | + hash = Hash_Probe(key, i, size); |
| 234 | + h = hashes[hash]; |
| 235 | + if (!h) break; |
| 236 | + while ((n = Compare_UTF8(VAL_SYM_NAME(words + h), str, len)) >= 0) { |
244 | 237 | if (n == 0) return h; // direct hit
|
245 |
| - if (VAL_SYM_ALIAS(words+h)) h = VAL_SYM_ALIAS(words+h); |
| 238 | + if (VAL_SYM_ALIAS(words + h)) h = VAL_SYM_ALIAS(words + h); |
246 | 239 | else goto make_sym; // Create new alias for word
|
247 | 240 | }
|
248 |
| - hash += skip; |
249 |
| - if (hash >= size) hash -= size; |
250 | 241 | }
|
251 | 242 |
|
252 | 243 | make_sym:
|
|
337 | 328 | /*
|
338 | 329 | ***********************************************************************/
|
339 | 330 | {
|
340 |
| - if (num == 0 || num >= PG_Word_Table.series->tail) return (REBYTE*)"???"; |
| 331 | + if (num == 0 || num >= PG_Word_Table.series->tail) |
| 332 | + return (REBYTE*)"???"; |
341 | 333 | return VAL_SYM_NAME(BLK_SKIP(PG_Word_Table.series, num));
|
342 | 334 | }
|
343 | 335 |
|
|
0 commit comments