Skip to content

Commit b44c516

Browse files
authored
bpo-26163: Frozenset hash improvement (#5194)
1 parent 94e1696 commit b44c516

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

Objects/setobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ frozenset_hash(PyObject *self)
795795
hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
796796

797797
/* Disperse patterns arising in nested frozensets */
798+
hash ^= (hash >> 11) ^ (~hash >> 25);
798799
hash = hash * 69069U + 907133923UL;
799800

800801
/* -1 is reserved as an error code */

0 commit comments

Comments
 (0)