mirror of
https://github.com/python/cpython.git
synced 2025-10-01 04:42:10 +00:00
bpo-26163: Frozenset hash improvement (GH-5194) (#5198)
(cherry picked from commit b44c5169f6
)
This commit is contained in:
parent
b92c159efa
commit
e7dbd06583
2 changed files with 3 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Improved frozenset() hash to create more distinct hash values when faced
|
||||||
|
with datasets containing many similar values.
|
|
@ -790,6 +790,7 @@ frozenset_hash(PyObject *self)
|
||||||
hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
|
hash ^= ((Py_uhash_t)PySet_GET_SIZE(self) + 1) * 1927868237UL;
|
||||||
|
|
||||||
/* Disperse patterns arising in nested frozensets */
|
/* Disperse patterns arising in nested frozensets */
|
||||||
|
hash ^= (hash >> 11) ^ (~hash >> 25);
|
||||||
hash = hash * 69069U + 907133923UL;
|
hash = hash * 69069U + 907133923UL;
|
||||||
|
|
||||||
/* -1 is reserved as an error code */
|
/* -1 is reserved as an error code */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue