We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
It's been discussed in several other issue threads. But folks like me doesn't pay attention. Perhaps this will get your attention.
There's a bug in double hash calculation.
Pay attention to the issue #35
There's a case where hash_b will return the (bucket_size - 1) and then the calculation will ignore attemptNumber because of modulus operator.
(hash_a + (attempt * (hash_b + 1))) % num_buckets;
is basically:
(hash_a + (attempt * num_buckets) % num_buckets;
Anything multiplies with num_buckets will get to 0 because of modulus. Therefore it will stuck in infinite loop to get you a negative index.
Fix:
static int ht_hash(const char* s, const int num_buckets, const int attempt) { const int hash_a = ht_generic_hash(s, 151, num_buckets); int hash_b = ht_generic_hash(s, 163, num_buckets); if (hash_b == num_buckets - 1) { hash_b = 1; } return (hash_a + (attempt * (hash_b + 1))) % num_buckets; }
Another fix (possibly more mathematically correct): Reference: https://en.wikipedia.org/wiki/Double_hashing
We should map the domain of h2 to {1, num_buckets-1}. One solution could be:
static int ht_hash(const char* s, const int num_buckets, const int attempt) { const int hash_a = ht_generic_hash(s, 151, num_buckets); const int hash_b = ht_generic_hash(s, 163, num_buckets-1); return (hash_a + (attempt * (hash_b + 1))) % num_buckets; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
It's been discussed in several other issue threads. But folks like me doesn't pay attention. Perhaps this will get your attention.
There's a bug in double hash calculation.
Pay attention to the issue #35
There's a case where hash_b will return the (bucket_size - 1) and then the calculation will ignore attemptNumber because of modulus operator.
(hash_a + (attempt * (hash_b + 1))) % num_buckets;
is basically:
(hash_a + (attempt * num_buckets) % num_buckets;
Anything multiplies with num_buckets will get to 0 because of modulus. Therefore it will stuck in infinite loop to get you a negative index.
Fix:
Another fix (possibly more mathematically correct):
Reference: https://en.wikipedia.org/wiki/Double_hashing
We should map the domain of h2 to {1, num_buckets-1}.
One solution could be:
The text was updated successfully, but these errors were encountered: