[issue5186] Reduce hash collisions for objects with no __hash__ method

Adam Olsen report at bugs.python.org
Wed Feb 11 10:02:22 CET 2009


Adam Olsen <rhamph at gmail.com> added the comment:

The alignment requirements (long double) make it impossible to have
anything in those bits.

Hypothetically, a custom allocator could lower the alignment
requirements to sizeof(void *).  However, rotating to the high bits is
pointless as they're the least likely to be used — impossible in this
case, as only the 2 highest bits would contain anything, and for that
you'd need a dictionary with at least 2 billion entries on 32bit, which
is more than the 32bit address space.  64-bit is similar.

Note that mixing the bits back in, via XOR or similar, is actually more
likely to hurt than help.  It's just like ints and strings, who's hash
values are very sequential, a simple shift tends to get us sequential
hashes.  This gives us a far lower collision rate than a statistically
random hash.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5186>
_______________________________________


More information about the Python-bugs-list mailing list