Mercurial > cpython-lru_cache-weakref
diff Objects/setobject.c @ 32319:b9de6b665273 legacy-trunk
Fixups to the hash function for frozensets.
* Non-zero initial value so that hash(frozenset()) != hash(0).
* Final permutation to differentiate nested sets.
* Add logic to make sure that -1 is not a possible hash value.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Thu, 10 Jun 2004 21:38:41 +0000 |
| parents | 679e5c8effae |
| children | 87302ac07255 |
line wrap: on
line diff
--- a/Objects/setobject.c Thu Jun 10 18:42:15 2004 +0000 +++ b/Objects/setobject.c Thu Jun 10 21:38:41 2004 +0000 @@ -663,7 +663,7 @@ PySetObject *so = (PySetObject *)self; PyObject *key, *value; int pos = 0; - long hash = 0; + long hash = 1905176217L; if (so->hash != -1) return so->hash; @@ -676,6 +676,9 @@ collapse to only a handful of distinct hash values. */ hash ^= PyObject_Hash(key) * 3644798167u; } + hash *= 69069L; + if (hash == -1) + hash = 590923713L; so->hash = hash; return hash; }
