From 230dc9c3c1219ebb49b90bff99d14a338453f6e3 Mon Sep 17 00:00:00 2001 From: Denis Lisov Date: Sun, 12 Dec 2021 15:25:06 +0300 Subject: 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. --- Hashtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hashtable.c b/Hashtable.c index a9575a5c..8aff1df3 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -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; } -- cgit v1.2.3