1 #include <ccan/invbloom/invbloom.h>
2 /* Include the C files directly. */
3 #include <ccan/invbloom/invbloom.c>
4 #include <ccan/tap/tap.h>
6 static void singleton_cb(struct invbloom *ib, size_t n, bool before,
9 ok1(ib->count[n] == 1 || ib->count[n] == -1);
16 const tal_t *ctx = tal(NULL, char);
18 unsigned singleton_count[2];
20 /* This is how many tests you plan to run */
21 plan_tests(16 + 6 + NUM_HASHES * 3);
23 /* Single entry ib table keeps it simple. */
24 ib = invbloom_new(ctx, int, 1, 100);
25 invbloom_singleton_cb(ib, singleton_cb, singleton_count);
28 singleton_count[false] = singleton_count[true] = 0;
29 invbloom_insert(ib, &val);
30 ok1(ib->count[0] == NUM_HASHES);
31 ok1(singleton_count[true] == 1);
32 ok1(singleton_count[false] == 1);
33 ok1(!invbloom_empty(ib));
35 /* First delete takes it via singleton. */
36 invbloom_delete(ib, &val);
37 ok1(singleton_count[true] == 2);
38 ok1(singleton_count[false] == 2);
39 ok1(invbloom_empty(ib));
41 /* Second delete creates negative singleton. */
42 invbloom_delete(ib, &val);
43 ok1(singleton_count[true] == 3);
44 ok1(singleton_count[false] == 3);
46 /* Now a larger table: this seed set so entries don't clash */
47 ib = invbloom_new(ctx, int, 1024, 0);
48 singleton_count[false] = singleton_count[true] = 0;
49 invbloom_singleton_cb(ib, singleton_cb, singleton_count);
52 invbloom_insert(ib, &val);
53 ok1(singleton_count[true] == 0);
54 ok1(singleton_count[false] == NUM_HASHES);
56 /* First delete removes singletons. */
57 invbloom_delete(ib, &val);
58 ok1(singleton_count[true] == NUM_HASHES);
59 ok1(singleton_count[false] == NUM_HASHES);
60 ok1(invbloom_empty(ib));
62 /* Second delete creates negative singletons. */
63 invbloom_delete(ib, &val);
64 ok1(singleton_count[true] == NUM_HASHES);
65 ok1(singleton_count[false] == NUM_HASHES * 2);
69 /* This exits depending on whether all tests passed */