Hashtable: adjust shrink-on-remove factor

Due to the use of prime numbers Hashtable_remove used to never shrink
from some sizes. For example, a size 8191 hashtable would try to shrink
to 4095, which nextPrime would round back to 8191 instead of the
intended 4093. A factor of 3 is enough to allow every prime size used to
shrink to the previous one.
This commit is contained in:
Denis Lisov 2021-12-12 15:25:06 +03:00 committed by cgzones
parent d084a80023
commit 230dc9c3c1
1 changed files with 1 additions and 1 deletions

View File

@ -286,7 +286,7 @@ void* Hashtable_remove(Hashtable* this, ht_key_t key) {
/* shrink on load-factor < 0.125 */
if (8 * this->items < this->size)
Hashtable_setSize(this, this->size / 2);
Hashtable_setSize(this, this->size / 3); /* account for nextPrime rounding up */
return res;
}