diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-07-23 16:43:57 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-07-23 16:43:57 +0000 |
commit | dd6bb6c6b8298ebeff2d1882becb36580b969d6f (patch) | |
tree | 3d922a5791e7e34e2b041ea5f3489360bfa798e1 /src/libstddjb/cdb_findnext.c | |
parent | 122f9363682e5de8ce4056c4c05c1eaf8935cf19 (diff) | |
download | skalibs-dd6bb6c6b8298ebeff2d1882becb36580b969d6f.tar.xz |
New 2.11.0.0 branch with several modifications
- libbiguint removed
- cdb_make changed to cdbmake (because different ui)
- cdb redesigned
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/cdb_findnext.c')
-rw-r--r-- | src/libstddjb/cdb_findnext.c | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/src/libstddjb/cdb_findnext.c b/src/libstddjb/cdb_findnext.c deleted file mode 100644 index 536013b..0000000 --- a/src/libstddjb/cdb_findnext.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/cdb.h> - -static int match (struct cdb *c, char const *key, unsigned int len, uint32_t pos) -{ - char buf[1024] ; - while (len > 0) - { - unsigned int n = 1024 ; - if (n > len) n = len ; - if (cdb_read(c, buf, n, pos) < 0) return -1 ; - if (memcmp(buf, key, n)) return 0 ; - pos += n ; key += n ; len -= n ; - } - return 1 ; -} - -int cdb_findnext (struct cdb *c, char const *key, unsigned int len) -{ - char buf[8] ; - uint32_t pos ; - uint32_t u ; - - if (!c->loop) - { - u = cdb_hash(key, len) ; - if (cdb_read(c, buf, 8, (u << 3) & 2047) < 0) return -1 ; - uint32_unpack(buf + 4, &c->hslots) ; - if (!c->hslots) return 0 ; - uint32_unpack(buf, &c->hpos) ; - c->khash = u ; - u >>= 8 ; - u %= c->hslots ; - u <<= 3 ; - c->kpos = c->hpos + u ; - } - - while (c->loop < c->hslots) - { - if (cdb_read(c, buf, 8, c->kpos) < 0) return -1 ; - uint32_unpack(buf + 4, &pos) ; - if (!pos) return 0 ; - c->loop++ ; - c->kpos += 8 ; - if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos ; - uint32_unpack(buf, &u) ; - if (u == c->khash) - { - if (cdb_read(c, buf, 8, pos) < 0) return -1 ; - uint32_unpack(buf, &u) ; - if (u == len) - switch (match(c, key, len, pos + 8)) - { - case -1: - return -1 ; - case 1: - uint32_unpack(buf + 4, &c->dlen) ; - c->dpos = pos + 8 + len ; - return 1 ; - } - } - } - return 0 ; -} |