311 |
return M4_HASH_LENGTH (hash); |
return M4_HASH_LENGTH (hash); |
312 |
} |
} |
313 |
|
|
314 |
|
/* Force the number of buckets to be the given value. You probably ought |
315 |
|
not to be using this function once the table has been in use, since |
316 |
|
the maximum density algorithm will grow the number of buckets back to |
317 |
|
what was there before if you try to shrink the table. It is useful |
318 |
|
to set a smaller or larger initial size if you know in advance what |
319 |
|
order of magnitude of entries will be in the table. Be aware that |
320 |
|
the efficiency of the lookup and grow features require that the size |
321 |
|
always be 1 less than a power of 2. */ |
322 |
|
void |
323 |
|
m4_hash_resize (m4_hash *hash, size_t size) |
324 |
|
{ |
325 |
|
m4_hash_node **original_buckets; |
326 |
|
size_t original_size; |
327 |
|
|
328 |
|
assert (hash); |
329 |
|
|
330 |
|
original_size = M4_HASH_SIZE (hash); |
331 |
|
original_buckets = M4_HASH_BUCKETS (hash); |
332 |
|
|
333 |
|
M4_HASH_SIZE (hash) = size; |
334 |
|
M4_HASH_BUCKETS (hash)= XCALLOC (m4_hash_node *, size); |
335 |
|
|
336 |
|
{ |
337 |
|
size_t i; |
338 |
|
for (i = 0; i < original_size; ++i) |
339 |
|
if (original_buckets[i]) |
340 |
|
m4_hash_bucket_insert (hash, original_buckets[i]); |
341 |
|
} |
342 |
|
|
343 |
|
XFREE (original_buckets); |
344 |
|
} |
345 |
|
|
346 |
/* If the node density breaks the threshold, increase the size of |
/* If the node density breaks the threshold, increase the size of |
347 |
HASH and repopulate with the original nodes. */ |
HASH and repopulate with the original nodes. */ |
348 |
void |
void |