0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

Trie index: fixed walk macro, added a test

This commit is contained in:
Maria Matejka 2019-04-17 13:00:54 +02:00
parent cdb1bff49a
commit b7bf5c5b8d
2 changed files with 32 additions and 1 deletions

View File

@ -83,7 +83,7 @@ void tindex_walk_free(struct tindex_walk *ctx);
#define TINDEX_WALK(ti, twp) \
for (struct tindex_walk *_ti_ctx = tindex_walk_init(ti, twp); _ti_ctx; _ti_ctx = NULL) \
for (u64 idx; idx = tindex_walk_next(ti, _ti_ctx); )
for (u64 idx; idx = tindex_walk_next(_ti_ctx); )
/**
* Dump the index. Useful for debugging.

View File

@ -79,6 +79,37 @@ t_simple(void)
test_trie_get(&tt, i * mul + add, 1);
}
u32 data[2];
uint dlen;
struct tindex_walk_params twp = {
.begin = 1,
.maxlen = TINDEX_WALK_NOMAXLEN,
.data = data,
.dlen = &dlen,
};
uint cnt = 0;
u32 seen[max / 32];
memset(seen, 0, sizeof(seen));
TINDEX_WALK(tt.ti, &twp) {
bt_assert(dlen == 64);
u64 num = ((u64) data[0] << 32) + ((u64) data[1]);
if (num < max) {
bt_assert((seen[num / 32] & (1 << (num % 32))) == 0);
seen[num / 32] |= 1 << (num % 32);
} else
cnt++;
dlen = 42; /* Mess it for testing purposes. */
}
bt_assert(cnt == max);
for (u64 i=0; i<sizeof(seen)/sizeof(u32); i++)
bt_assert(!~seen[i]);
/*
for (u64 i = 0; i < 20; i++)
test_trie_remove(&tt, i);