summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-06-10 21:38:41 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-06-10 21:38:41 (GMT)
commit27e403ebe914294d307348d2b83c39f96059e133 (patch)
tree418e9e758aa28a8458564a140063f70d6c2acec1 /Objects
parent57c2d930f688ca50248241919bd815c85bf39939 (diff)
downloadcpython-27e403ebe914294d307348d2b83c39f96059e133.zip
cpython-27e403ebe914294d307348d2b83c39f96059e133.tar.gz
cpython-27e403ebe914294d307348d2b83c39f96059e133.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index fbff077..8de0419 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -663,7 +663,7 @@ frozenset_hash(PyObject *self)
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 @@ frozenset_hash(PyObject *self)
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;
}