1 #include "ejdb2_internal.h"
2
jbi_full_scanner(struct _JBEXEC * ctx,JB_SCAN_CONSUMER consumer)3 iwrc jbi_full_scanner(struct _JBEXEC *ctx, JB_SCAN_CONSUMER consumer) {
4 bool matched;
5 IWKV_cursor cur;
6 int64_t step = 1;
7 iwrc rc = iwkv_cursor_open(ctx->jbc->cdb, &cur, ctx->cursor_init, 0);
8 RCRET(rc);
9
10 IWKV_cursor_op cursor_reverse_step = (ctx->cursor_step == IWKV_CURSOR_NEXT)
11 ? IWKV_CURSOR_PREV : IWKV_CURSOR_NEXT;
12
13 while (step && !(rc = iwkv_cursor_to(cur, step > 0 ? ctx->cursor_step : cursor_reverse_step))) {
14 if (step > 0) {
15 --step;
16 } else if (step < 0) {
17 ++step; // -V547
18 }
19 if (!step) {
20 size_t sz;
21 int64_t id;
22 rc = iwkv_cursor_copy_key(cur, &id, sizeof(id), &sz, 0);
23 RCBREAK(rc);
24 if (sz != sizeof(id)) {
25 rc = IWKV_ERROR_CORRUPTED;
26 iwlog_ecode_error3(rc);
27 break;
28 }
29 step = 1;
30 matched = false;
31 rc = consumer(ctx, cur, id, &step, &matched, 0);
32 RCBREAK(rc);
33 }
34 }
35 if (rc == IWKV_ERROR_NOTFOUND) {
36 rc = 0;
37 }
38 iwkv_cursor_close(&cur);
39 return consumer(ctx, 0, 0, 0, 0, rc);
40 }
41