Skip to content

Commit

Permalink
res: kvs: add sid_kvs_iter_reset_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
prajnoha committed Jun 25, 2024
1 parent 58167eb commit 2126616
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/include/resource/kv-store.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const char *sid_kvs_iter_current_key(sid_kvs_iter_t *iter);
void *sid_kvs_iter_current(sid_kvs_iter_t *iter, size_t *size, sid_kvs_val_fl_t *flags);
void *sid_kvs_iter_next(sid_kvs_iter_t *iter, size_t *size, const char **return_key, sid_kvs_val_fl_t *flags);
void sid_kvs_iter_reset(sid_kvs_iter_t *iter, const char *key_start, const char *key_end);
void sid_kvs_iter_reset_prefix(sid_kvs_iter_t *kv_store_res, const char *prefix);
void sid_kvs_iter_destroy(sid_kvs_iter_t *iter);

#ifdef __cplusplus
Expand Down
21 changes: 19 additions & 2 deletions src/resource/kv-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ void *sid_kvs_iter_next(sid_kvs_iter_t *iter, size_t *size, const char **return_
return sid_kvs_iter_current(iter, size, flags);
}

void sid_kvs_iter_reset(sid_kvs_iter_t *iter, const char *key_start, const char *key_end)
void _do_sid_kvs_iter_reset(sid_kvs_iter_t *iter, kvs_iter_method_t method, const char *key_start, const char *key_end)
{
if (!iter)
return;
Expand All @@ -1308,11 +1308,28 @@ void sid_kvs_iter_reset(sid_kvs_iter_t *iter, const char *key_start, const char
break;

case SID_KVS_BACKEND_BPTREE:
bptree_iter_reset(iter->bpt.iter, key_start, key_end);
switch (method) {
case ITER_EXACT:
bptree_iter_reset(iter->bpt.iter, key_start, key_end);
break;
case ITER_PREFIX:
bptree_iter_reset_prefix(iter->bpt.iter, key_start);
break;
}
break;
}
}

void sid_kvs_iter_reset(sid_kvs_iter_t *iter, const char *key_start, const char *key_end)
{
_do_sid_kvs_iter_reset(iter, ITER_EXACT, key_start, key_end);
}

void sid_kvs_iter_reset_prefix(sid_kvs_iter_t *iter, const char *prefix)
{
_do_sid_kvs_iter_reset(iter, ITER_PREFIX, prefix, NULL);
}

void sid_kvs_iter_destroy(sid_kvs_iter_t *iter)
{
if (!iter)
Expand Down

0 comments on commit 2126616

Please sign in to comment.