* 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? */
| 36 | * Users cannot control pointers, so we do not have to worry about DoS attacks? |
| 37 | */ |
| 38 | static inline Py_hash_t |
| 39 | identity_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 |