mirror of https://github.com/xzeldon/htop.git
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:
parent
d084a80023
commit
230dc9c3c1
|
@ -286,7 +286,7 @@ void* Hashtable_remove(Hashtable* this, ht_key_t key) {
|
||||||
|
|
||||||
/* shrink on load-factor < 0.125 */
|
/* shrink on load-factor < 0.125 */
|
||||||
if (8 * this->items < this->size)
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue