[issue8188] Unified hash for numeric types.
Mark Dickinson
report at bugs.python.org
Wed Apr 21 15:47:38 CEST 2010
Mark Dickinson <dickinsm at gmail.com> added the comment:
> Regarding a hash function for complex types, I think documenting the
> existing behavior for PyComplex is sufficient. The magic number 1000003 > could be documented in hash_info as 'multiplier' and _PyHASH_MULTIPLIER.
Seems reasonable; I'm tempted to call the constant it hash_info.imaginary and _PyHASH_IMAGINARY, though. :)
There's also an implicit parameter in this algorithm, namely the size of a C long; I think this should go into sys.hash_info, too.
complex_hash does need fixing in one respect: it currently depends on signed overflow wrapping modulo 2**BIT_IN_LONG, but that's undefined behaviour; it should use unsigned arithmetic instead.
> I think hash(m/P) should preserve sign. It just seems more symmetrical. :)
Agreed. Along similar lines, I think I'm also going to get rid of _PyHASH_NINF and just use -PyHASH_INF instead.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8188>
_______________________________________
More information about the Python-bugs-list
mailing list