| 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 |
|
| 33 |
/* hash function definition */ |
| 34 |
typedef struct { |
| 35 |
Py_hash_t (*const hash)(const void *, Py_ssize_t); |
| 36 |
const char *name; |
| 37 |
const int hash_bits; |
| 38 |
const int seed_bits; |
| 39 |
} PyHash_FuncDef; |
| 40 |
|
| 41 |
PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void); |
| 42 |
|
| 43 |
PyAPI_FUNC(Py_hash_t) Py_HashPointer(const void *ptr); |
| 44 |
|
| 45 |
// Deprecated alias kept for backward compatibility |
| 46 |
Py_DEPRECATED(3.14) static inline Py_hash_t |
| 47 |
_Py_HashPointer(const void *ptr) |
| 48 |
{ |
| 49 |
return Py_HashPointer(ptr); |
| 50 |
} |
| 51 |
|
| 52 |
PyAPI_FUNC(Py_hash_t) PyObject_GenericHash(PyObject *); |
| 53 |
|
| 54 |
PyAPI_FUNC(Py_hash_t) Py_HashBuffer(const void *ptr, Py_ssize_t len); |