Best practice for caching hash

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Mar 16 02:36:16 EDT 2022


On 16/03/22 6:58 pm, Chris Angelico wrote:
> And Python's own integers hash to themselves, 
 > which isn't what I'd call "widely distributed", but which
 > works well in practice.
Not exactly, they seem to be limited to 60 bits:
 >>> hex(hash(0xfffffffffffffff))
'0xfffffffffffffff'
 >>> hex(hash(0x1fffffffffffffff))
'0x0'
And up to that limit they're as widely distributed as you
can get -- each integer hashes to a unique value!
But keep in mind that the hash value itself is not directly
used to locate a dict slot -- there is extra scrambling that
goes on in the dict code.
-- 
Greg


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /