-
Notifications
You must be signed in to change notification settings - Fork 279
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
ht_get_hash
not working correctly
#45
Comments
What have you set HT_PRIME_1 and HT_PRIME_2 to? I am facing the same issue |
I have found the solution to this issue. #define HT_PRIME_1 151;
#define HT_PRIME_2 163; The ht_get_hash function no longer returns negative values and also works in far fewer attempts. |
@nouritsu my
|
Do you ever get out-of-bounds writes? I see you get negative indices🤔 |
@winterrdog yes, program ends with "Segmentation fault" in some cases (not always though). It means that negative index works in some cases (or at least it doesn't cause segmentation fault) while not in others. I have no idea how this happens. |
the reason is because of an edge case that was not handled with You could deal with it in two ways e.g. either by always checking if the calculated index is within bounds of the table's static int is_valid_index(ht_hash_table* table, int index)
{
return index >= 0 && index < table->size;
} or do a single check like the one i did in the |
ht_get_hash
returns the same slot subsequently up to very high attempts in some cases. Example:My definitions:
The text was updated successfully, but these errors were encountered: