summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-01-16 10:27:15 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-01-16 10:27:15 (GMT)
commite7dbd0658304f11daf103d56662656efecad006d (patch)
tree695c10968f5e63a0b5fcc61fc8fbbcf6ad1d49a2
parentb92c159efada05b3a5ff9d0dbce3fcb2334631f6 (diff)
downloadcpython-e7dbd0658304f11daf103d56662656efecad006d.zip
cpython-e7dbd0658304f11daf103d56662656efecad006d.tar.gz
cpython-e7dbd0658304f11daf103d56662656efecad006d.tar.bz2
bpo-26163: Frozenset hash improvement (GH-5194) (#5198)
(cherry picked from commit b44c5169f64178d2ff2914187b315549e7ab0cb6)
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2018-01-14-20-32-47.bpo-26163.xv9Iuv.rst2
-rw-r--r--Objects/setobject.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-01-14-20-32-47.bpo-26163.xv9Iuv.rst b/Misc/NEWS.d/next/Core and Builtins/2018-01-14-20-32-47.bpo-26163.xv9Iuv.rst
new file mode 100644
index 0000000..163b9e0
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-01-14-20-32-47.bpo-26163.xv9Iuv.rst
@@ -0,0 +1,2 @@
+Improved frozenset() hash to create more distinct hash values when faced
+with datasets containing many similar values.
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 24272b4..093a15f 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -790,6 +790,7 @@ frozenset_hash(PyObject *self)
hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
/* Disperse patterns arising in nested frozensets */
+ hash ^= (hash >> 11) ^ (~hash >> 25);
hash = hash * 69069U + 907133923UL;
/* -1 is reserved as an error code */