-
Notifications
You must be signed in to change notification settings - Fork 323
Open
Description
In the ht_get_hash function the case hash_b = 0 is well handled by adding one and avoiding infinit cycling with same hash value.
However, there is another case that causes infinite cycling: when hash_b = num_buckets.
The implementation below solves both cases:
static int ht_get_hash( const char* s, const int num_buckets, const int attempt) {
const int hash_a = ht_hash(s, HT_PRIME_1, taille);
int hash_b = ht_hash(s, HT_PRIME_2, taille);
if (hash_b % taille == 0) {
hash_b = 1;
}
return (hash_a + (attempt * hash_b)) % taille; // Not adding 1 to hash_b here
}
rurban, SwackSun, gabrieledarrigo, SheldonNico, basilm4r0 and 1 more
Metadata
Metadata
Assignees
Labels
No labels