1 #include <linux/module.h>
2 #include <linux/rbtree_augmented.h>
3 #include <linux/random.h>
7 #define PERF_LOOPS 100000
8 #define CHECK_LOOPS 100
37 rb_link_node(&node->
rb, parent,
new);
46 static inline u32 augment_recompute(
struct test_node *node)
49 if (node->
rb.rb_left) {
52 if (max < child_augmented)
53 max = child_augmented;
55 if (node->
rb.rb_right) {
58 if (max < child_augmented)
59 max = child_augmented;
65 u32, augmented, augment_recompute)
79 if (key < parent->key)
80 new = &parent->
rb.rb_left;
82 new = &parent->
rb.rb_right;
85 node->augmented =
val;
87 rb_insert_augmented(&node->rb, root, &augment_callbacks);
92 rb_erase_augmented(&node->
rb, root, &augment_callbacks);
95 static void init(
void)
98 for (i = 0; i <
NODES; i++) {
109 static int black_path_count(
struct rb_node *
rb)
113 count += !is_red(rb);
117 static void check(
int nr_nodes)
130 blacks = black_path_count(rb);
133 blacks != black_path_count(rb));
134 prev_key = node->
key;
140 static void check_augmented(
int nr_nodes)
151 static int rbtree_test_init(
void)
158 prandom32_seed(&
rnd, 3141592653589793238ULL);
164 for (j = 0; j <
NODES; j++)
165 insert(nodes + j, &root);
166 for (j = 0; j <
NODES; j++)
167 erase(nodes + j, &root);
171 time = time2 - time1;
173 time = div_u64(time, PERF_LOOPS);
174 printk(
" -> %llu cycles\n", (
unsigned long long)time);
178 for (j = 0; j <
NODES; j++) {
180 insert(nodes + j, &root);
182 for (j = 0; j <
NODES; j++) {
184 erase(nodes + j, &root);
196 for (j = 0; j <
NODES; j++)
197 insert_augmented(nodes + j, &root);
198 for (j = 0; j <
NODES; j++)
199 erase_augmented(nodes + j, &root);
203 time = time2 - time1;
205 time = div_u64(time, PERF_LOOPS);
206 printk(
" -> %llu cycles\n", (
unsigned long long)time);
210 for (j = 0; j <
NODES; j++) {
212 insert_augmented(nodes + j, &root);
214 for (j = 0; j <
NODES; j++) {
215 check_augmented(NODES - j);
216 erase_augmented(nodes + j, &root);
224 static void rbtree_test_exit(
void)