mm: add CONFIG_DEBUG_VM_RB build option
[cascardo/linux.git] / lib / rbtree_test.c
index 66e41d4..268b239 100644 (file)
@@ -1,5 +1,5 @@
 #include <linux/module.h>
-#include <linux/rbtree.h>
+#include <linux/rbtree_augmented.h>
 #include <linux/random.h>
 #include <asm/timex.h>
 
@@ -61,35 +61,35 @@ static inline u32 augment_recompute(struct test_node *node)
        return max;
 }
 
-static void augment_callback(struct rb_node *rb, void *unused)
-{
-       struct test_node *node = rb_entry(rb, struct test_node, rb);
-       node->augmented = augment_recompute(node);
-}
+RB_DECLARE_CALLBACKS(static, augment_callbacks, struct test_node, rb,
+                    u32, augmented, augment_recompute)
 
 static void insert_augmented(struct test_node *node, struct rb_root *root)
 {
-       struct rb_node **new = &root->rb_node, *parent = NULL;
+       struct rb_node **new = &root->rb_node, *rb_parent = NULL;
        u32 key = node->key;
+       u32 val = node->val;
+       struct test_node *parent;
 
        while (*new) {
-               parent = *new;
-               if (key < rb_entry(parent, struct test_node, rb)->key)
-                       new = &parent->rb_left;
+               rb_parent = *new;
+               parent = rb_entry(rb_parent, struct test_node, rb);
+               if (parent->augmented < val)
+                       parent->augmented = val;
+               if (key < parent->key)
+                       new = &parent->rb.rb_left;
                else
-                       new = &parent->rb_right;
+                       new = &parent->rb.rb_right;
        }
 
-       rb_link_node(&node->rb, parent, new);
-       rb_insert_color(&node->rb, root);
-       rb_augment_insert(&node->rb, augment_callback, NULL);
+       node->augmented = val;
+       rb_link_node(&node->rb, rb_parent, new);
+       rb_insert_augmented(&node->rb, root, &augment_callbacks);
 }
 
 static void erase_augmented(struct test_node *node, struct rb_root *root)
 {
-       struct rb_node *deepest = rb_augment_erase_begin(&node->rb);
-       rb_erase(&node->rb, root);
-       rb_augment_erase_end(deepest, augment_callback, NULL);
+       rb_erase_augmented(&node->rb, root, &augment_callbacks);
 }
 
 static void init(void)