Skip to content

Commit e7dbd06

Browse files
miss-islingtonrhettinger
authored andcommitted
bpo-26163: Frozenset hash improvement (GH-5194) (#5198)
(cherry picked from commit b44c516)
1 parent b92c159 commit e7dbd06

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
@@ -790,6 +790,7 @@ frozenset_hash(PyObject *self)
790790
hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
791791

792792
/* Disperse patterns arising in nested frozensets */
793+
hash ^= (hash >> 11) ^ (~hash >> 25);
793794
hash = hash * 69069U + 907133923UL;
794795

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

0 commit comments

Comments
 (0)