Mercurial > hg > cc > cirrus_work
changeset 259:41ed24203e14
remove the testing code, leaving just the class
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Fri, 24 Jan 2025 15:02:57 +0000 |
parents | 1b87a7345e39 |
children | 5b2e675ac556 |
files | lib/python/cc/lmh/db.pyx |
diffstat | 1 files changed, 4 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/python/cc/lmh/db.pyx Fri Jan 24 15:01:42 2025 +0000 +++ b/lib/python/cc/lmh/db.pyx Fri Jan 24 15:02:57 2025 +0000 @@ -1,51 +1,17 @@ -# distutils: extra_objects = cdb_min/libcdb.a +# distutils: sources = [cdb_min/cdb.c, cdb_min/error.c, cdb_min/open_read.c, cdb_min/seek_cur.c, cdb_min/open_trunc.c, cdb_min/seek_set.c, cdb_min/byte_copy.c, cdb_min/byte_diff.c, cdb_min/error_str.c, cdb_min/uint32_unpack.c, cdb_min/cdb_hash.c] +# extra_objects = cdb_min/libcdb.a # distutils: include_dirs = cdb_min -res: int - cimport cdb -import sys, timeit cdef class CCdb: - cdef cdb.Cdb* _c_cdb - def __cinit__(self): self._c_cdb = cdb.cdb_new() - cdef int find(self, p: bytes): + cdef int find(self, bytes p): return cdb.cdb_find(self._c_cdb, p, len(p)) - cdef char[::1] init(self, fno: int): + cdef char[::1] init(self, int fno): cdb.cdb_init(self._c_cdb,fno) cdef char[::1] _mview = <char[:cdb.cdb_msize():1]>(cdb.cdb_mmap()) return _mview - -probe: bytes = sys.argv[2].encode('utf8') - -cdef CCdb CC - -cdef CCdb testMe(): - global probe - res: int - print('testing...') - cd = CCdb() - with open(sys.argv[1],'rb') as dbf: - mv = cd.init(dbf.fileno()) - cdb.cdb_findstart(cd._c_cdb) - if cd.find(probe) > 0: - print(o:=cdb.cdb_pos(), l:=cdb.cdb_len()) - sys.stdout.buffer.write(mv[o:o+l]) - sys.stdout.buffer.write(b'\n') - else: - print(0) - print('tested') - return cd - -def cfind(p: bytes) -> int: - global CC - return cdb.cdb_find(CC._c_cdb, p, len(p)) - -CC = testMe() - -print(timeit.timeit('cfind(probe)', - number=int(sys.argv[3]), globals=globals()))