Skip to content

Commit 22f55bb

Browse files
_combine_hashes better mixing
1 parent 745b3b9 commit 22f55bb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Objects/dictobject.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8222,17 +8222,23 @@ frozendict_repr(PyObject *self)
82228222
return res;
82238223
}
82248224

8225-
// based on boost's old hash_combine
82268225
static inline Py_uhash_t
82278226
_combine_hashes(Py_uhash_t h1, Py_uhash_t h2)
82288227
{
8229-
// 2^sizeof(Py_hash_t) / phi
82308228
#if SIZEOF_PY_HASH_T == 8
8229+
// 2^sizeof(Py_hash_t) / phi
82318230
const Py_uhash_t GOLDEN_C = 0x9e3779b97f4a7c15ULL;
8231+
h1 += GOLDEN_C;
8232+
h1 ^= h2;
8233+
h1 ^= (h1 << 13) + (h1 >> 3);
8234+
h1 ^= h1 >> 33;
82328235
#else
82338236
const Py_uhash_t GOLDEN_C = 0x9e3779b9UL;
8237+
h1 += GOLDEN_C;
8238+
h1 ^= h2;
8239+
h1 ^= (h1 << 6) + (h1 >> 2);
8240+
h1 ^= h1 >> 16;
82348241
#endif
8235-
h1 ^= h2 + GOLDEN_C + (h1 << 6) + (h1 >> 2);
82368242
return h1;
82378243
}
82388244

0 commit comments

Comments
 (0)