# HG changeset patch # User Henry S. Thompson # Date 1737730977 0 # Node ID 41ed24203e14c9baf5f156c4c551972cf9637234 # Parent 1b87a7345e392830095d01492887930e54aabf27 remove the testing code, leaving just the class diff -r 1b87a7345e39 -r 41ed24203e14 lib/python/cc/lmh/db.pyx --- 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 = (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()))