Skip to content

Commit 7cf3e2a

Browse files
committed
Hashtable: Always choose next prime when growing "buckets"
The next prime number for the size of "buckets" may be less than 2 times the old size. That would cause a skip in the prime number selection, effectively making the new "buckets" size nearly 4 times the old size (in constrast with 2 times the old size). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent 76806a8 commit 7cf3e2a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Hashtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void Hashtable_put(Hashtable* this, ht_key_t key, void* value) {
230230
CRT_fatalError("Hashtable: size overflow");
231231

232232
if (this->items >= this->size * 7 / 10)
233-
Hashtable_setSize(this, 2 * this->size);
233+
Hashtable_setSize(this, this->size + 1);
234234

235235
insert(this, key, value);
236236

0 commit comments

Comments
 (0)