diff --git a/src/include/resource/kv-store.h b/src/include/resource/kv-store.h index e9af79cd..162a52ce 100644 --- a/src/include/resource/kv-store.h +++ b/src/include/resource/kv-store.h @@ -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 diff --git a/src/resource/kv-store.c b/src/resource/kv-store.c index 6e2a794b..f2af8534 100644 --- a/src/resource/kv-store.c +++ b/src/resource/kv-store.c @@ -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; @@ -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)