For 64-bit platforms, it seems that ints and longs with the
same value don't necessarily give the same hash key.
An example is below; the phenomenon seems to occur
for a range of numbers between 2**32 and 2**64.
I assume this is unintentional? It looks suspiciously as
though the function long_hash in Objects/longobject.c
has 32-bitness hard-coded. Lines 1288-1289 of that file
in the Python 2.2.2 source read:
/* Force a 32-bit circular shift */
x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) &
MASK);
And here's the Python example:
Python 2.2.2 (#22, Dec 23 2002, 12:02:55)
[GCC 3.0.3] on sunos5
Type "help", "copyright", "credits" or "license" for more
information.
>>> x = 4503599627370496L
>>> y = 4503599627370496
>>> h = {x: 'anything', y: 'something else'}
>>> h[x]
'anything'
>>> h[y]
'something else'
>>> x == y
1
All the best,
Mark
|