[issue37807] Make hash() return a non-negative number
Serhiy Storchaka
report at bugs.python.org
Sat Aug 10 14:32:40 EDT 2019
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
Currently the hash for integers and several other types uses 62 bits of 64 (on 64-bit platform). The domain of values is continuous:
-sys.hash_info.modulus < h < sys.hash_info.modulus
If interpret Py_hash_t as Py_uhash_t, it will no longer be continuous:
0 <= h < sys.hash_info.modulus or 2**sys.hash_info.width-sys.hash_info.modulus < h < 2**sys.hash_info.width
The hash for tuples is written in term of signed hashes of elements. If write it in Python it will look more complicated for unsigned hashes.
What are problems with using negative hash values? In hash tables you squeeze it to valid range by evaluating `h % size` of `h & mask`. Both expressions give non-negative result.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37807>
_______________________________________
More information about the Python-bugs-list
mailing list