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

Function find_item

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

Source from the content-addressed store, hash-verified

59
60
61static inline PyObject **
62find_item(PyArrayIdentityHash const *tb, PyObject *const *key)
63{
64 Py_hash_t hash = identity_list_hash(key, tb->key_len);
65 npy_uintp perturb = (npy_uintp)hash;
66 npy_intp bucket;
67 npy_intp mask = tb->size - 1 ;
68 PyObject **item;
69
70 bucket = (npy_intp)hash & mask;
71 while (1) {
72 item = &(tb->buckets[bucket * (tb->key_len + 1)]);
73
74 if (item[0] == NULL) {
75 /* The item is not in the cache; return the empty bucket */
76 return item;
77 }
78 if (memcmp(item+1, key, tb->key_len * sizeof(PyObject *)) == 0) {
79 /* This is a match, so return the item/bucket */
80 return item;
81 }
82 /* Hash collision, perturb like Python (must happen rarely!) */
83 perturb >>= 5; /* Python uses the macro PERTURB_SHIFT == 5 */
84 bucket = mask & (bucket * 5 + perturb + 1);
85 }
86}
87
88
89NPY_NO_EXPORT PyArrayIdentityHash *

Callers 2

Calls 1

identity_list_hashFunction · 0.85

Tested by

no test coverage detected