summaryrefslogtreecommitdiffstats
path: root/Hashtable.c
diff options
context:
space:
mode:
authorDenis Lisov <dennis.lissov@gmail.com>2021-12-12 15:25:06 +0300
committercgzones <cgzones@googlemail.com>2021-12-13 21:05:22 +0100
commit230dc9c3c1219ebb49b90bff99d14a338453f6e3 (patch)
treeb147135422ae79eb7c42815cb03f5f4e6651f368 /Hashtable.c
parentd084a800236a3791f5cc33f6da613ce46b08394a (diff)
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.
Diffstat (limited to 'Hashtable.c')
-rw-r--r--Hashtable.c2
1 files changed, 1 insertions, 1 deletions
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;
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy