From ba5422d8ac64ca864dca168780a957a92f22a5d0 Mon Sep 17 00:00:00 2001 From: bpc2003 Date: Tue, 22 Apr 2025 16:45:36 -0400 Subject: Add utils.h and moved batch operations into their own files --- src/lib/getkeys.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/lib/getkeys.c') diff --git a/src/lib/getkeys.c b/src/lib/getkeys.c index 98442a3..cdba202 100644 --- a/src/lib/getkeys.c +++ b/src/lib/getkeys.c @@ -4,8 +4,9 @@ #include #include "mdb.h" +#include "utils.h" -extern tabidx_t getkey(tablist_t *list, int id, char *key); +static tabidx_t getkey(tablist_t *list, int id, char *key); static int getkeys_helper(void *data); @@ -89,3 +90,16 @@ static struct params *pass(tablist_t *list, tablist_t *ret, char **keys, int len p->pid = pid; return p; } + +static tabidx_t getkey(tablist_t *list, int id, char *key) +{ + int idx = hash(key); + if (list[id].tab[idx].key == NULL) + return (tabidx_t) { .key = NULL, .flag = 0, .value = { 0 } }; + + while (strcmp(list[id].tab[idx].key, key) && idx < TABLEN) + idx++; + if (idx >= TABLEN) + return (tabidx_t) { .key = NULL, .flag = 0, .value = { 0 } }; + return list[id].tab[idx]; +} -- cgit v1.2.3