Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash_b 2 bad scenarii #35

Open
BechirZalila opened this issue Dec 13, 2018 · 2 comments
Open

hash_b 2 bad scenarii #35

BechirZalila opened this issue Dec 13, 2018 · 2 comments

Comments

@BechirZalila
Copy link

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
}

@gabrieledarrigo
Copy link

Thank you, this was really useful;
With this fix, I was capable to insert few millions of entries without any hassle!

@BechirZalila
Copy link
Author

Glad it helped you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants