diff options
| author | David Lamparter <equinox@diac24.net> | 2017-08-09 20:43:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-09 20:43:40 +0200 |
| commit | 2c3699c0eb00def0dddf033c7ecf23d0c5d479ab (patch) | |
| tree | f3384bc2df97f8701da32dedffeb155f8de8bea0 /lib/hash.c | |
| parent | fc73dd4bdf96cbab00e7d5de67ec56503c6d9783 (diff) | |
| parent | bed7ad8387b9dc99c675cd1e13984a337fecd1c7 (diff) | |
Merge pull request #940 from qlyoung/hashtable-expansion-lf
lib: use load factor as hash expansion trigger
Diffstat (limited to 'lib/hash.c')
| -rw-r--r-- | lib/hash.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/lib/hash.c b/lib/hash.c index 801871f839..66341cf2f1 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -141,18 +141,15 @@ void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *)) unsigned int key; unsigned int index; void *newdata; - unsigned int len; struct hash_backet *backet; key = (*hash->hash_key)(data); index = key & (hash->size - 1); - len = 0; for (backet = hash->index[index]; backet != NULL; backet = backet->next) { if (backet->key == key && (*hash->hash_cmp)(backet->data, data)) return backet->data; - ++len; } if (alloc_func) { @@ -160,7 +157,7 @@ void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *)) if (newdata == NULL) return NULL; - if (len > HASH_THRESHOLD) { + if (HASH_THRESHOLD(hash->count + 1, hash->size)) { hash_expand(hash); index = key & (hash->size - 1); } |
