]> granicus.if.org Git - python/commitdiff
bpo-26163: Frozenset hash improvement (#5194)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Tue, 16 Jan 2018 09:30:26 +0000 (01:30 -0800)
committerGitHub <noreply@github.com>
Tue, 16 Jan 2018 09:30:26 +0000 (01:30 -0800)
Misc/NEWS.d/next/Core and Builtins/2018-01-14-20-32-47.bpo-26163.xv9Iuv.rst [new file with mode: 0644]
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 (file)
index 0000000..163b9e0
--- /dev/null
@@ -0,0 +1,2 @@
+Improved frozenset() hash to create more distinct hash values when faced
+with datasets containing many similar values.
index c920fb9853406b2bdaff01e87e9d2fc450bb9801..4bc1020d56f77a741a19cd9191994890161ac6b0 100644 (file)
@@ -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 */