As suggested in the comments of this question, I am using as a hash function this:
atol(phone) % buckets
However, I got the same exact result from atol()
for all my phone numbers! I removed the first two digits (they are the same for all the numbers in my case) and got different results (of course collisions were detected..).
Why this happened?
Check the output of this:
printf("%s %ld %ld %s %ld %d %ld\n", str, atol(str), atol(str) % N,
phone, atol(phone), N, atol(phone) % N);
Just some instances:
48614858 48614858 58 6948614858 2147483647 200 47
61468264 61468264 64 6961468264 2147483647 200 47
54079694 54079694 94 6954079694 2147483647 200 47
48370923 48370923 123 6948370923 2147483647 200 47
52746354 52746354 154 6952746354 2147483647 200 47
Meta-question: If a better approach can be suggested to get a better hash function, I am still open in changing my code.
EDIT:
strtol()
gives same results.