5 #include <freeradius-devel/util/rb.c>
6 #include <freeradius-devel/util/rand.h>
13 static int8_t
comp(
void const *a,
void const *b)
17 return CMP(our_a->
num, our_b->num);
27 static int print_cb(
void *i,
UNUSED void *
uctx)
56 int count, count_expect;
68 while (
n->left !=
NIL) {
69 if (
n->colour ==
RED) {
70 if (
n->left->colour !=
BLACK ||
n->right->colour !=
BLACK) {
79 if (
n->right !=
NIL) {
80 if (
n->colour ==
RED) {
81 if (
n->left->colour !=
BLACK ||
n->right->colour !=
BLACK) {
90 if ((
n->left !=
NIL) || (
n->right !=
NIL)) {
93 if (count_expect < 0) {
98 fprintf(stderr,
"Expected %i got %i\n", count_expect,
count);
103 if (
n->parent ==
NIL)
return count_expect;
104 while (
n->parent->right ==
n) {
106 if (!
n->parent)
return count_expect;
111 if (
n->parent->left ==
n) {
112 if (
n->parent->right !=
NIL) {
113 n =
n->parent->right;
117 if (!
n->parent)
return count_expect;
142 memset(&vals, 0,
sizeof(vals));
148 if (!--rep)
return 0;
155 fprintf(stderr,
"filter = %x mask = %x n = %i\n", thresh.
num,
mask,
n);
158 for (i = 0; i <
n; i++) {
168 fprintf(stderr,
"After insert rbcount is %i\n", i);
188 fprintf(stderr,
"After delete rbcount is %i\n", i);
198 for (j = i = 0; i <
n; i++) {
199 if (i && (vals[i-1].num == vals[i].num))
continue;
201 if (vals[i].num !=
rvals[j].num)
goto bad;
205 fprintf(stderr,
"matched OK\n");
210 for (j = i = 0; i <
n; i++) {
211 if (i && vals[i-1].num == vals[i].num)
continue;
213 fprintf(stderr,
"%i: %x %x\n", j, vals[i].num,
rvals[j].num);
216 fprintf(stderr,
"skipped %x\n", vals[i].num);
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
fr_dcursor_eval_t void const * uctx
uint32_t fr_rand(void)
Return a 32-bit random number.
void fr_rb_iter_delete_inorder(fr_rb_iter_inorder_t *iter)
Remove the current node from the tree.
void * fr_rb_iter_next_inorder(fr_rb_iter_inorder_t *iter)
Return the next node.
void * fr_rb_iter_init_inorder(fr_rb_iter_inorder_t *iter, fr_rb_tree_t *tree)
Initialise an in-order iterator.
#define fr_rb_inline_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black tree.
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
fr_rb_node_t * root
Root of the rbtree.
Iterator structure for in-order traversal of an rbtree.
The main red black tree structure.
static int filter_cb(void *i, void *uctx)
static int8_t comp(void const *a, void const *b)
static fr_rb_tree_test_node_t rvals[MAXSIZE]
static int qsort_comp(void const *a, void const *b)
int main(UNUSED int argc, UNUSED char *argv[])
static void freenode(void *data)
static int rbcount(fr_rb_tree_t *t)