bpo-26163: Frozenset hash improvement (GH-5194) (#5198) · python/cpython@e7dbd06 (original) (raw)

File tree

2 files changed

lines changed

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +Improved frozenset() hash to create more distinct hash values when faced
2 +with datasets containing many similar values.
Original file line number Diff line number Diff line change
@@ -790,6 +790,7 @@ frozenset_hash(PyObject *self)
790 790 hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
791 791
792 792 /* Disperse patterns arising in nested frozensets */
793 +hash ^= (hash >> 11) ^ (~hash >> 25);
793 794 hash = hash * 69069U + 907133923UL;
794 795
795 796 /* -1 is reserved as an error code */