python - Why does hash(None) change across different platforms and in different calls? -
i'm facing weird behavior hash function on python. when run following command on mac os (10.10) different values different calls.
$ python -c "print hash(none)" -9223372036579216774 $ python -c "print hash(none)" -9223372036582852230
in other hand when run same thing on ubuntu 14.04 get:
$ python -c "print hash(none)" 596615 $ python -c "print hash(none)" 596615
for me looks like, in os x, python using memory address somehow , ubuntu not. can see hash function implementation dependent. shouldn't based on "value" of none only? numbers represent? why behave differently on same python version on different os?
none.__hash__
correlates _py_hashpointer
hashing function. pointer of object used hash. none
beeing singleton safe use, not deterministic. pointer cast adequate integer type p
hash value calculated following:
(p >> 4) | (p << (8 * sizeof_void_p - 4))
referring comment in source code states:
bottom 3 or 4 bits 0; rotate y 4 avoid excessive hash collisions dicts , sets
Comments
Post a Comment