Mercurial > hg > cc > cirrus_work
changeset 270:f88abc69f876 default tip
convert most CCdb methods to cpdef
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 11 Feb 2025 11:25:44 +0000 |
parents | 583baab8ca05 |
children | |
files | lib/python/cc/lmh/db.pxd lib/python/cc/lmh/db.pyx lib/python/cc/lmh/nndb.pyx |
diffstat | 3 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/python/cc/lmh/db.pxd Tue Feb 04 11:17:13 2025 +0000 +++ b/lib/python/cc/lmh/db.pxd Tue Feb 11 11:25:44 2025 +0000 @@ -1,8 +1,11 @@ cimport cdb cdef class CCdb: cdef cdb.Cdb* _c_cdb - cdef void findstart(self) - cdef int find(self, bytes p) - cdef char[::1] init(self, int fno) + cdef char[::1] _c_mv + cpdef char[::1] init(self, int fno) + cpdef void findstart(self) + cpdef int find(self, bytes p) cdef cdb.uint32 pos(self) cdef int len(self) + cpdef long raw(self) + cpdef char[::1] value(self)
--- a/lib/python/cc/lmh/db.pyx Tue Feb 04 11:17:13 2025 +0000 +++ b/lib/python/cc/lmh/db.pyx Tue Feb 11 11:25:44 2025 +0000 @@ -7,16 +7,16 @@ def __cinit__(self): self._c_cdb = cdb.cdb_new() - cdef void findstart(self): + cpdef void findstart(self): cdb.cdb_findstart(self._c_cdb) - cdef int find(self, bytes p): + cpdef int find(self, bytes p): return cdb.cdb_find(self._c_cdb, p, len(p)) - cdef char[::1] init(self, int fno): + cpdef char[::1] init(self, int fno): cdb.cdb_init(self._c_cdb,fno) - cdef char[::1] _mview = <char[:cdb.cdb_msize(self._c_cdb):1]>(cdb.cdb_mmap(self._c_cdb)) - return _mview + self._c_mv = <char[:cdb.cdb_msize(self._c_cdb):1]>(cdb.cdb_mmap(self._c_cdb)) + return self._c_mv cdef cdb.uint32 pos(self): return cdb.cdb_pos(self._c_cdb) @@ -24,5 +24,12 @@ cdef int len(self): return cdb.cdb_len(self._c_cdb) - def raw(self) -> long: + cpdef long raw(self): return <long>(self._c_cdb) + + cpdef char[::1] value(self): + o = cdb.cdb_pos(self._c_cdb) + return self._c_mv[o: o+cdb.cdb_len(self._c_cdb)] + + +
--- a/lib/python/cc/lmh/nndb.pyx Tue Feb 04 11:17:13 2025 +0000 +++ b/lib/python/cc/lmh/nndb.pyx Tue Feb 11 11:25:44 2025 +0000 @@ -22,6 +22,8 @@ if res == 1: print(res,o:=CC.pos(), l:=CC.len()) sys.stdout.buffer.write(mv[o:o+l]) + sys.stdout.buffer.write(b' ') + sys.stdout.buffer.write(CC.value()) sys.stdout.buffer.write(b'\n') else: print('losing %s'%res)