def _search_hkey(self, hkey):
hi = self.index_elements
lo = 0
if cython.compiled:
dtype = self._dtype
if dtype is npuint64 or dtype is npuint32:
#lint:disable
PyObject_GetBuffer(self.index, cython.address(indexbuf), PyBUF_STRIDED_RO)
try:
if ( indexbuf.strides == cython.NULL
or indexbuf.len < hi * indexbuf.strides[0] ):
raise ValueError("Invalid buffer state")
pindex = cython.cast(cython.p_char, indexbuf.buf)
stride0 = indexbuf.strides[0]
if dtype is npuint64:
# A quick guess assuming uniform distribution of keys over the 64-bit value range
hint = (((hkey >> 32) * (hi-lo)) >> 32) + lo
return _c_search_hkey_ui64(hkey, pindex, stride0, hi, hint)
elif dtype is npuint32:
# A quick guess assuming uniform distribution of keys over the 64-bit value range
hint = ((hkey * (hi-lo)) >> 32) + lo
return _c_search_hkey_ui32(hkey, pindex, stride0, hi, hint)
else:
raise AssertionError("Internal error")
finally:
PyBuffer_Release(cython.address(indexbuf))
#lint:enable
else:
dtype = self.dtype
struct_dt = numpy.dtype([
('key_hash', dtype),
('key_offset', dtype),
('value', dtype),
])
return self.index.view(struct_dt).reshape(self.index.shape[0]).searchsorted(
numpy.array([(hkey,0,0)],dtype=struct_dt))[0]
评论列表
文章目录