From: Maria Matejka Date: Wed, 17 Apr 2019 11:00:54 +0000 (+0200) Subject: Trie index: fixed walk macro, added a test X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7bf5c5b8de809901e2be3adfd9f172cc4183aa1;p=thirdparty%2Fbird.git Trie index: fixed walk macro, added a test --- diff --git a/lib/tindex.h b/lib/tindex.h index b51cb8915..7da4b90ef 100644 --- a/lib/tindex.h +++ b/lib/tindex.h @@ -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. diff --git a/lib/tindex_test.c b/lib/tindex_test.c index 48f591a7c..7a3a65215 100644 --- a/lib/tindex_test.c +++ b/lib/tindex_test.c @@ -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