Title basically says it all. I've tried Googling but return a load of false positives. I guess I'm just wondering if there was a certain rationale behind these two specific numbers or could they have easily been many other sets of numbers?
Edit: And, since the source of the numbers has been answered, any reason why writers of the Boolean hashCode method used those numbers (besides that they're prime)? Would any other set of prime numbers worked just as well?
These numbers come from the official Boolean API.
Hash functions are prone to collisions. The number of collisions can be reduced by using prime numbers (think about the factors prime numbers have). 1231 and 1237 are both prime numbers.
/e1
After doing a little more research I came across this:
Since they most probably will have no common divisors with the hashtable size (unless the prime itself divises the hashtable size), the chances of collision in common hashtable implementations would be minimized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With