Why does Ruby hash an integer n
to 2 * n + 1
?
>> [0,1,2,3].each {|x| puts x.hash}
1
3
5
7
I can see that you don't always need to have complicated hashes, especially for simple objects. But why the 'double and add 1' rule as opposed to doing what Python does, which is to hash integers to themselves?
>>> map(hash,[0,1,2,3])
[0, 1, 2, 3]
Is there a reason?