mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Issue #8188: Introduce a new scheme for computing hashes of numbers
(instances of int, float, complex, decimal.Decimal and fractions.Fraction) that makes it easy to maintain the invariant that hash(x) == hash(y) whenever x and y have equal value.
This commit is contained in:
parent
03721133a6
commit
dc787d2055
14 changed files with 566 additions and 137 deletions
|
@ -126,6 +126,20 @@ Used in: PY_LONG_LONG
|
|||
#endif
|
||||
#endif
|
||||
|
||||
/* Parameters used for the numeric hash implementation. See notes for
|
||||
_PyHash_Double in Objects/object.c. Numeric hashes are based on
|
||||
reduction modulo the prime 2**_PyHASH_BITS - 1. */
|
||||
|
||||
#if SIZEOF_LONG >= 8
|
||||
#define _PyHASH_BITS 61
|
||||
#else
|
||||
#define _PyHASH_BITS 31
|
||||
#endif
|
||||
#define _PyHASH_MODULUS ((1UL << _PyHASH_BITS) - 1)
|
||||
#define _PyHASH_INF 314159
|
||||
#define _PyHASH_NAN 0
|
||||
#define _PyHASH_IMAG 1000003UL
|
||||
|
||||
/* uintptr_t is the C9X name for an unsigned integral type such that a
|
||||
* legitimate void* can be cast to uintptr_t and then back to void* again
|
||||
* without loss of information. Similarly for intptr_t, wrt a signed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue