bpo-26163: Frozenset hash improvement (#5194) · python/cpython@b44c516 (original) (raw)
File tree
2 files changed
lines changed
- Misc/NEWS.d/next/Core and Builtins
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 |
---|---|---|
@@ -795,6 +795,7 @@ frozenset_hash(PyObject *self) | ||
795 | 795 | hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL; |
796 | 796 | |
797 | 797 | /* Disperse patterns arising in nested frozensets */ |
798 | +hash ^= (hash >> 11) ^ (~hash >> 25); | |
798 | 799 | hash = hash * 69069U + 907133923UL; |
799 | 800 | |
800 | 801 | /* -1 is reserved as an error code */ |