Comment #10 on issue 1973 by mattpap: hash(Integer) should return the int
http://code.google.com/p/sympy/issues/detail?id=1973
So we have to deal with hash collisions.
Hash collisions are a natural thing and we have to deal with them from the
very beginning (e.g. this is why we can't implement Eq() as __eq__ operator
for now). Basically, if hashes differ, then the objects differ, otherwise
you can't say anything about the objects (may differ or not). So, hash(-1)
== hash(-2), is a perfectly valid thing, although not that pretty at all.
In [1]: [ hash(2**(32*i)) for i in xrange(10) ]
Out[1]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
In [2]: [ hash(2**(32*i)-1) for i in xrange(10) ]
Out[2]: [0, -2, -2, -2, -2, -2, -2, -2, -2, -2]
I think they should mention the -1 special-case in the hash() docstring.
It's
imho a poor design choice that -1 and -2 have the same hash.
So, what other hash would you suggest? With hash(-1) == -2 at least we see
this special case clearly. Would it be that better to have e.g. hash(-1) ==
0xAFFEBACD?
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.