1 #include <ccan/rbtree/rbtree.c>
2 #include <ccan/tap/tap.h>
3 #include <ccan/talloc/talloc.h>
7 #define NUM_ELEMS 10000
9 static bool lookup_all(trbt_tree_t *rb, bool exist)
13 for (i = 0; i < NUM_ELEMS; i++) {
14 int *p = trbt_lookup32(rb, i);
27 static bool add_one(trbt_tree_t *rb, bool exist, unsigned int i)
29 int *p = trbt_insert32(rb, i, talloc_memdup(rb, &i, sizeof(i)));
41 static bool insert_all(trbt_tree_t *rb, bool exist)
45 for (i = 0; i < NUM_ELEMS; i++) {
46 if (!add_one(rb, exist, i))
52 static void delete_all(trbt_tree_t *rb)
56 /* Don't delete them in the obvious order. */
57 for (i = 0; i < NUM_ELEMS / 2; i++) {
61 for (i = NUM_ELEMS-1; i >= NUM_ELEMS / 2; i--) {
69 void *ctx = talloc_init("toplevel");
73 rb = trbt_create(ctx, 0);
76 /* None should be there. */
77 ok1(lookup_all(rb, false));
79 /* Insert, none should be there previously. */
80 ok1(insert_all(rb, false));
83 ok1(lookup_all(rb, true));
86 ok1(insert_all(rb, true));
91 /* One more time... */
92 ok1(lookup_all(rb, false));
93 ok1(insert_all(rb, false));
95 /* All are children of rb, so this is clean. */
98 /* This exits depending on whether all tests passed */