Skip to content

hash_b 2 bad scenarii #35

@BechirZalila

Description

@BechirZalila

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions