Created
March 24, 2012 02:57
-
-
Save ayust/2177775 to your computer and use it in GitHub Desktop.
wat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.6.7 (r267:88850, Dec 2 2011, 20:27:26) | |
[GCC 4.4.3] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> a = -1 | |
>>> b = -2 | |
>>> hash(a) == hash(b) | |
True | |
>>> hash(a) | |
-2 | |
>>> hash(b) | |
-2 | |
>>> c = -3 | |
>>> hash(c) | |
-3 | |
>>> hash(b) == hash(c) | |
False | |
>>> |
Yeah, I know why it happens, it's just amusing that they chose to have -1 hash to -2 (along with -2 hashing to -2).
https://github.com/python-git/python/blob/master/Objects/stringobject.c#L1220
-1 is used as the "not yet computed" cached value, so they (unwisely?) coerce any -1 hash to -2 to allow caching ^_^
Cool, @lunixbochs ! Thanks for tracking that down. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's a hash function...