[Python-checkins] bpo-26163: Frozenset hash improvement (#5194)

Raymond Hettinger webhook-mailer at python.org
Tue Jan 16 04:30:29 EST 2018


https://github.com/python/cpython/commit/b44c5169f64178d2ff2914187b315549e7ab0cb6
commit: b44c5169f64178d2ff2914187b315549e7ab0cb6
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-01-16T01:30:26-08:00
summary:

bpo-26163: Frozenset hash improvement (#5194)

files:
A Misc/NEWS.d/next/Core and Builtins/2018-01-14-20-32-47.bpo-26163.xv9Iuv.rst
M Objects/setobject.c

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 00000000000..163b9e02c5a
--- /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 c920fb98534..4bc1020d56f 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -795,6 +795,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 */



More information about the Python-checkins mailing list