Skip to content

Commit

Permalink
libkmod: hash_new(): always use a step size of at least 4
Browse files Browse the repository at this point in the history
The current algorithm would choose a step size of 4 for
n_buckets == 31, but 1 for n_buckets == 32, which seems wrong.
Fix it.

Signed-off-by: Martin Wilck <[email protected]>
  • Loading branch information
mwilck authored and lucasdemarchi committed Nov 29, 2024
1 parent 5857e76 commit bd374ed
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion shared/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct hash *hash_new(unsigned int n_buckets, void (*free_value)(void *value))
hash->n_buckets = n_buckets;
hash->free_value = free_value;
hash->step = n_buckets / 32;
if (hash->step == 0)
if (hash->step < 4)
hash->step = 4;
else if (hash->step > 64)
hash->step = 64;
Expand Down

0 comments on commit bd374ed

Please sign in to comment.