File indexing completed on 2025-01-18 10:06:50
0001 #ifndef Py_HASH_H
0002
0003 #define Py_HASH_H
0004 #ifdef __cplusplus
0005 extern "C" {
0006 #endif
0007
0008
0009 #ifndef Py_LIMITED_API
0010 PyAPI_FUNC(Py_hash_t) _Py_HashDouble(PyObject *, double);
0011 PyAPI_FUNC(Py_hash_t) _Py_HashPointer(const void*);
0012
0013 PyAPI_FUNC(Py_hash_t) _Py_HashPointerRaw(const void*);
0014 PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t);
0015 #endif
0016
0017
0018 #define _PyHASH_MULTIPLIER 1000003UL
0019
0020
0021
0022
0023
0024 #if SIZEOF_VOID_P >= 8
0025 # define _PyHASH_BITS 61
0026 #else
0027 # define _PyHASH_BITS 31
0028 #endif
0029
0030 #define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
0031 #define _PyHASH_INF 314159
0032 #define _PyHASH_IMAG _PyHASH_MULTIPLIER
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 #ifndef Py_LIMITED_API
0055 typedef union {
0056
0057 unsigned char uc[24];
0058
0059 struct {
0060 Py_hash_t prefix;
0061 Py_hash_t suffix;
0062 } fnv;
0063
0064 struct {
0065 uint64_t k0;
0066 uint64_t k1;
0067 } siphash;
0068
0069 struct {
0070 unsigned char padding[16];
0071 Py_hash_t suffix;
0072 } djbx33a;
0073 struct {
0074 unsigned char padding[16];
0075 Py_hash_t hashsalt;
0076 } expat;
0077 } _Py_HashSecret_t;
0078 PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
0079
0080 #ifdef Py_DEBUG
0081 PyAPI_DATA(int) _Py_HashSecret_Initialized;
0082 #endif
0083
0084
0085
0086 typedef struct {
0087 Py_hash_t (*const hash)(const void *, Py_ssize_t);
0088 const char *name;
0089 const int hash_bits;
0090 const int seed_bits;
0091 } PyHash_FuncDef;
0092
0093 PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
0094 #endif
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 #ifndef Py_HASH_CUTOFF
0109 # define Py_HASH_CUTOFF 0
0110 #elif (Py_HASH_CUTOFF > 7 || Py_HASH_CUTOFF < 0)
0111 # error Py_HASH_CUTOFF must in range 0...7.
0112 #endif
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 #define Py_HASH_EXTERNAL 0
0128 #define Py_HASH_SIPHASH24 1
0129 #define Py_HASH_FNV 2
0130 #define Py_HASH_SIPHASH13 3
0131
0132 #ifndef Py_HASH_ALGORITHM
0133 # ifndef HAVE_ALIGNED_REQUIRED
0134 # define Py_HASH_ALGORITHM Py_HASH_SIPHASH13
0135 # else
0136 # define Py_HASH_ALGORITHM Py_HASH_FNV
0137 # endif
0138 #endif
0139
0140 #ifdef __cplusplus
0141 }
0142 #endif
0143
0144 #endif