parent
781581bd26
commit
10346678ba
51
pep-0456.txt
51
pep-0456.txt
|
@ -310,31 +310,43 @@ hash function
|
|||
|
||||
function prototype::
|
||||
|
||||
typedef Py_hash_t (*PyHash_Func)(const void *, Py_ssize_t);
|
||||
typedef Py_hash_t (*PyHash_Func_t)(const void *, Py_ssize_t);
|
||||
|
||||
|
||||
hash function table
|
||||
-------------------
|
||||
hash function selection
|
||||
-----------------------
|
||||
|
||||
type definition::
|
||||
|
||||
#define PY_HASH_SIPHASH24 0x53495024
|
||||
#define PY_HASH_FNV 0x464E56
|
||||
|
||||
#ifndef PY_HASH_ALGORITHM
|
||||
#if defined(PY_UINT64_T) && defined(PY_UINT32_T)
|
||||
#define PY_HASH_ALGORITHM PY_HASH_SIPHASH24
|
||||
#else
|
||||
#define PY_HASH_ALGORITHM PY_HASH_FNV
|
||||
#endif /* uint64_t && uint32_t */
|
||||
#endif /* PY_HASH_ALGORITHM */
|
||||
|
||||
typedef struct {
|
||||
PyHash_Func hash; /* function pointer */
|
||||
PyHash_Func_t hash; /* function pointer */
|
||||
char *name; /* name of the hash algorithm and variant */
|
||||
int hash_bits; /* internal size of hash value */
|
||||
int seed_bits; /* size of seed input */
|
||||
} _PyHash_FuncDef;
|
||||
} PyHash_FuncDef;
|
||||
|
||||
PyAPI_DATA(_PyHash_FuncDef *) _PyHash_Func;
|
||||
PyAPI_DATA(PyHash_FuncDef) PyHash_Func;
|
||||
|
||||
Implementation::
|
||||
|
||||
#ifndef PY_HASH_FUNC
|
||||
#ifdef PY_UINT64_T
|
||||
_PyHash_Func = {siphash24, "sip24", 64, 128}
|
||||
#else
|
||||
_PyHash_Func = {fnv, "fnv", 8 * sizeof(Py_hash_t), 16 * sizeof(Py_hash_t)}
|
||||
#if PY_HASH_ALGORITHM == PY_HASH_FNV
|
||||
PyHash_FuncDef PyHash_Func = {fnv, "fnv", 8 * sizeof(Py_hash_t),
|
||||
16 * sizeof(Py_hash_t)};
|
||||
#endif
|
||||
|
||||
#if PY_HASH_ALGORITHM == PY_HASH_SIPHASH24
|
||||
PyHash_FuncDef PyHash_Func = {siphash24, "siphash24", 64, 128};
|
||||
#endif
|
||||
|
||||
TODO: select hash algorithm with autoconf variable
|
||||
|
@ -346,14 +358,19 @@ Python API addition
|
|||
sys module
|
||||
----------
|
||||
|
||||
The sys module grows a new struct member with information about the select
|
||||
algorithm as well as all available algorithms.
|
||||
The sys module already has a hash_info struct sequence. More fields are added
|
||||
to the object to reflect the active hash algorithm and its properties.
|
||||
|
||||
::
|
||||
|
||||
sys.hash_info(algorithm='siphash24',
|
||||
sys.hash_info(width=64,
|
||||
modulus=2305843009213693951,
|
||||
inf=314159,
|
||||
nan=0,
|
||||
imag=1000003,
|
||||
# new fields:
|
||||
algorithm='siphash24',
|
||||
hash_bits=64,
|
||||
hash_output=64, # 8 * sizeof(Py_hash_t)
|
||||
seed_bits=128)
|
||||
|
||||
|
||||
|
@ -411,8 +428,8 @@ multiplied with the size of the internal unicode kind::
|
|||
|
||||
if (PyUnicode_READY(u) == -1)
|
||||
return -1;
|
||||
x = _PyHash_Func->hash(PyUnicode_DATA(u),
|
||||
PyUnicode_GET_LENGTH(u) * PyUnicode_KIND(u));
|
||||
x = PyHash_Func.hash(PyUnicode_DATA(u),
|
||||
PyUnicode_GET_LENGTH(u) * PyUnicode_KIND(u));
|
||||
|
||||
|
||||
generic_hash (Modules/_datetimemodule.c)
|
||||
|
|
Loading…
Reference in New Issue