mapped_struct.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:sharedbuffers 作者: jampp 项目源码 文件源码
def hinted_bsearch(a, hkey, hint):
        hi = len(a)
        lo = 0
        if hi <= lo:
            return lo
        elif hkey < a[0]:
            return lo
        elif hkey > a[hi-1]:
            return hi

        #lint:disable
        PyObject_GetBuffer(a, 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]
            #lint:enable
            dtype = cython.cast('char*', a.dtype.char)[0]
            if dtype == 'L' or dtype == 'Q':
                # TO-DO: better hints?
                return _c_search_hkey_ui64(hkey, pindex, stride0, hi, hint)
            elif dtype == 'I':
                # TO-DO: better hints?
                return _c_search_hkey_ui32(hkey, pindex, stride0, hi, hint)
            elif dtype == 'l' or dtype == 'q':
                # TO-DO: better hints?
                return _c_search_hkey_i64(hkey, pindex, stride0, hi, hint)
            elif dtype == 'i':
                # TO-DO: better hints?
                return _c_search_hkey_i32(hkey, pindex, stride0, hi, hint)
            elif dtype == 'd':
                # TO-DO: better hints?
                return _c_search_hkey_f64(hkey, pindex, stride0, hi, hint)
            elif dtype == 'f':
                # TO-DO: better hints?
                return _c_search_hkey_f32(hkey, pindex, stride0, hi, hint)
            else:
                raise NotImplementedError("Unsupported array type %s" % (chr(dtype),))
        finally:
            PyBuffer_Release(cython.address(indexbuf)) #lint:ok
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号