version 1.48, 2020/10/25 17:01:05 |
version 1.49, 2020/10/25 17:58:53 |
Line 203 Hash_FindValueHash(HashTable *t, const c |
|
Line 203 Hash_FindValueHash(HashTable *t, const c |
|
static void |
static void |
RebuildTable(HashTable *t) |
RebuildTable(HashTable *t) |
{ |
{ |
HashEntry *e, *next = NULL, **hp, **xp; |
unsigned int oldSize = t->bucketsSize; |
int i; |
HashEntry **oldBuckets = t->buckets; |
unsigned int mask, oldsize, newsize; |
unsigned int newSize = 2 * oldSize; |
HashEntry **oldhp; |
unsigned int newMask = newSize - 1; |
|
HashEntry **newBuckets = bmake_malloc(sizeof(*newBuckets) * newSize); |
oldhp = t->buckets; |
size_t i; |
oldsize = t->bucketsSize; |
|
newsize = oldsize << 1; |
for (i = 0; i < newSize; i++) |
t->bucketsSize = (unsigned int)newsize; |
newBuckets[i] = NULL; |
t->bucketsMask = mask = newsize - 1; |
|
t->buckets = hp = bmake_malloc(sizeof(*hp) * newsize); |
for (i = 0; i < oldSize; i++) { |
i = (int)newsize; |
HashEntry *he = oldBuckets[i]; |
while (--i >= 0) |
while (he != NULL) { |
*hp++ = NULL; |
HashEntry *next = he->next; |
for (hp = oldhp, i = (int)oldsize; --i >= 0;) { |
he->next = newBuckets[he->key_hash & newMask]; |
for (e = *hp++; e != NULL; e = next) { |
newBuckets[he->key_hash & newMask] = he; |
next = e->next; |
he = next; |
xp = &t->buckets[e->key_hash & mask]; |
|
e->next = *xp; |
|
*xp = e; |
|
} |
} |
} |
} |
free(oldhp); |
|
|
free(oldBuckets); |
|
|
|
t->bucketsSize = newSize; |
|
t->bucketsMask = newMask; |
|
t->buckets = newBuckets; |
DEBUG5(HASH, "%s: %p size=%d entries=%d maxchain=%d\n", |
DEBUG5(HASH, "%s: %p size=%d entries=%d maxchain=%d\n", |
__func__, t, t->bucketsSize, t->numEntries, t->maxchain); |
__func__, t, t->bucketsSize, t->numEntries, t->maxchain); |
t->maxchain = 0; |
t->maxchain = 0; |