94 |
if (size == 0) |
if (size == 0) |
95 |
size = M4_HASH_DEFAULT_SIZE; |
size = M4_HASH_DEFAULT_SIZE; |
96 |
|
|
97 |
hash = XMALLOC (m4_hash, 1); |
hash = xmalloc (sizeof *hash); |
98 |
HASH_SIZE (hash) = size; |
HASH_SIZE (hash) = size; |
99 |
HASH_LENGTH (hash) = 0; |
HASH_LENGTH (hash) = 0; |
100 |
HASH_BUCKETS (hash) = XCALLOC (hash_node *, size); |
HASH_BUCKETS (hash) = xcalloc (size, sizeof HASH_BUCKETS (hash)); |
101 |
HASH_HASH_FUNC (hash) = hash_func; |
HASH_HASH_FUNC (hash) = hash_func; |
102 |
HASH_CMP_FUNC (hash) = cmp_func; |
HASH_CMP_FUNC (hash) = cmp_func; |
103 |
|
|
178 |
} |
} |
179 |
else |
else |
180 |
{ |
{ |
181 |
node = XMALLOC (hash_node, 1); |
node = xmalloc (sizeof *node); |
182 |
} |
} |
183 |
|
|
184 |
assert (node); |
assert (node); |
345 |
original_buckets = HASH_BUCKETS (hash); |
original_buckets = HASH_BUCKETS (hash); |
346 |
|
|
347 |
HASH_SIZE (hash) = size; |
HASH_SIZE (hash) = size; |
348 |
HASH_BUCKETS (hash)= XCALLOC (hash_node *, size); |
HASH_BUCKETS (hash) = xcalloc (size, sizeof HASH_BUCKETS (hash)); |
349 |
|
|
350 |
{ |
{ |
351 |
size_t i; |
size_t i; |
376 |
|
|
377 |
/* HASH sizes are always 1 less than a power of 2. */ |
/* HASH sizes are always 1 less than a power of 2. */ |
378 |
HASH_SIZE (hash) = (2* (1+ original_size)) -1; |
HASH_SIZE (hash) = (2* (1+ original_size)) -1; |
379 |
HASH_BUCKETS (hash) = XCALLOC (hash_node *, hash->size); |
HASH_BUCKETS (hash) = xcalloc (hash->size, sizeof HASH_BUCKETS (hash)); |
380 |
|
|
381 |
{ |
{ |
382 |
size_t i; |
size_t i; |
447 |
/* On the first iteration, allocate an iterator. */ |
/* On the first iteration, allocate an iterator. */ |
448 |
if (!place) |
if (!place) |
449 |
{ |
{ |
450 |
place = XCALLOC (m4_hash_iterator, 1); |
place = xcalloc (1, sizeof *place); |
451 |
ITERATOR_HASH (place) = hash; |
ITERATOR_HASH (place) = hash; |
452 |
} |
} |
453 |
|
|