]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Trie index: fixed walk macro, added a test
authorMaria Matejka <mq@ucw.cz>
Wed, 17 Apr 2019 11:00:54 +0000 (13:00 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 17 Apr 2019 11:00:54 +0000 (13:00 +0200)
lib/tindex.h
lib/tindex_test.c

index b51cb89159405551ababa7bd0e7f44478745283d..7da4b90ef88f55c3f14b958656d22252d3066d4f 100644 (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.
index 48f591a7cda6eb1229485a901eb00aeda948042d..7a3a6521544d3ab2f68b776cbefdba9893821ee0 100644 (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);