• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_CPYTHON_HASH_H
2 #  error "this header file must not be included directly"
3 #endif
4 
5 /* Prime multiplier used in string and various other hashes. */
6 #define PyHASH_MULTIPLIER 1000003UL  /* 0xf4243 */
7 
8 /* Parameters used for the numeric hash implementation.  See notes for
9    _Py_HashDouble in Python/pyhash.c.  Numeric hashes are based on
10    reduction modulo the prime 2**_PyHASH_BITS - 1. */
11 
12 #if SIZEOF_VOID_P >= 8
13 #  define PyHASH_BITS 61
14 #else
15 #  define PyHASH_BITS 31
16 #endif
17 
18 #define PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
19 #define PyHASH_INF 314159
20 #define PyHASH_IMAG PyHASH_MULTIPLIER
21 
22 /* Aliases kept for backward compatibility with Python 3.12 */
23 #define _PyHASH_MULTIPLIER PyHASH_MULTIPLIER
24 #define _PyHASH_BITS PyHASH_BITS
25 #define _PyHASH_MODULUS PyHASH_MODULUS
26 #define _PyHASH_INF PyHASH_INF
27 #define _PyHASH_IMAG PyHASH_IMAG
28 
29 /* Helpers for hash functions */
30 PyAPI_FUNC(Py_hash_t) _Py_HashDouble(PyObject *, double);
31 
32 // Kept for backward compatibility
33 #define _Py_HashPointer Py_HashPointer
34 
35 
36 /* hash function definition */
37 typedef struct {
38     Py_hash_t (*const hash)(const void *, Py_ssize_t);
39     const char *name;
40     const int hash_bits;
41     const int seed_bits;
42 } PyHash_FuncDef;
43 
44 PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
45 
46 PyAPI_FUNC(Py_hash_t) Py_HashPointer(const void *ptr);
47 PyAPI_FUNC(Py_hash_t) PyObject_GenericHash(PyObject *);
48