MCPcopy Create free account
hub / github.com/numpy/numpy / identity_list_hash

Function identity_list_hash

numpy/core/src/common/npy_hashtable.c:38–54  ·  view source on GitHub ↗

* This hashing function is basically the Python tuple hash with the type * identity hash inlined. The tuple hash itself is a reduced version of xxHash. * * Users cannot control pointers, so we do not have to worry about DoS attacks? */

Source from the content-addressed store, hash-verified

36 * Users cannot control pointers, so we do not have to worry about DoS attacks?
37 */
38static inline Py_hash_t
39identity_list_hash(PyObject *const *v, int len)
40{
41 Py_uhash_t acc = _NpyHASH_XXPRIME_5;
42 for (int i = 0; i < len; i++) {
43 /*
44 * Lane is the single item hash, which for us is the rotated pointer.
45 * Identical to the python type hash (pointers end with 0s normally).
46 */
47 size_t y = (size_t)v[i];
48 Py_uhash_t lane = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4));
49 acc += lane * _NpyHASH_XXPRIME_2;
50 acc = _NpyHASH_XXROTATE(acc);
51 acc *= _NpyHASH_XXPRIME_1;
52 }
53 return acc;
54}
55#undef _NpyHASH_XXPRIME_1
56#undef _NpyHASH_XXPRIME_2
57#undef _NpyHASH_XXPRIME_5

Callers 1

find_itemFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected