summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-08-07 07:43:39 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-08-07 07:43:39 (GMT)
commit4148195c45862fb62df97943591e9771b5638156 (patch)
tree9a2f77bf4eefe2f67ca1d8befcd29aff7d5f26a8 /Objects/setobject.c
parentb501a27ad8ec4b531a9c1057952d8f7c6ef8cb77 (diff)
downloadcpython-4148195c45862fb62df97943591e9771b5638156.zip
cpython-4148195c45862fb62df97943591e9771b5638156.tar.gz
cpython-4148195c45862fb62df97943591e9771b5638156.tar.bz2
Move the active entry multiplication to later in the hash calculation
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 0a065cc..03bb230 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -760,15 +760,12 @@ static Py_hash_t
frozenset_hash(PyObject *self)
{
PySetObject *so = (PySetObject *)self;
- Py_uhash_t hash = 1927868237UL;
+ Py_uhash_t hash = 0;
setentry *entry;
if (so->hash != -1)
return so->hash;
- /* Initial dispersion based on the number of active entries */
- hash *= (Py_uhash_t)PySet_GET_SIZE(self) + 1;
-
/* Xor-in shuffled bits from every entry's hash field because xor is
commutative and a frozenset hash should be independent of order.
@@ -790,6 +787,9 @@ frozenset_hash(PyObject *self)
if ((so->fill - so->used) & 1)
hash ^= _shuffle_bits(-1);
+ /* Factor in the number of active entries */
+ hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
+
/* Disperse patterns arising in nested frozensets */
hash = hash * 69069U + 907133923UL;