aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rbtree_test.c
diff options
context:
space:
mode:
authorMichel Lespinasse <walken@google.com>2012-10-08 19:31:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-09 03:22:38 -0400
commit3908836aa77e3621aaf2101f2920e01d7c8460d6 (patch)
tree3e8f5b619f9e093d9d53180bb6f496319ddeb946 /lib/rbtree_test.c
parent9d9e6f9703bbd642f3f2f807e6aaa642a4cbcec9 (diff)
rbtree: add RB_DECLARE_CALLBACKS() macro
As proposed by Peter Zijlstra, this makes it easier to define the augmented rbtree callbacks. Signed-off-by: Michel Lespinasse <walken@google.com> Cc: Rik van Riel <riel@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/rbtree_test.c')
-rw-r--r--lib/rbtree_test.c34
1 files changed, 2 insertions, 32 deletions
diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c
index e28345df09bf..b20e99969b0f 100644
--- a/lib/rbtree_test.c
+++ b/lib/rbtree_test.c
@@ -61,38 +61,8 @@ static inline u32 augment_recompute(struct test_node *node)
61 return max; 61 return max;
62} 62}
63 63
64static void augment_propagate(struct rb_node *rb, struct rb_node *stop) 64RB_DECLARE_CALLBACKS(static, augment_callbacks, struct test_node, rb,
65{ 65 u32, augmented, augment_recompute)
66 while (rb != stop) {
67 struct test_node *node = rb_entry(rb, struct test_node, rb);
68 u32 augmented = augment_recompute(node);
69 if (node->augmented == augmented)
70 break;
71 node->augmented = augmented;
72 rb = rb_parent(&node->rb);
73 }
74}
75
76static void augment_copy(struct rb_node *rb_old, struct rb_node *rb_new)
77{
78 struct test_node *old = rb_entry(rb_old, struct test_node, rb);
79 struct test_node *new = rb_entry(rb_new, struct test_node, rb);
80 new->augmented = old->augmented;
81}
82
83static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
84{
85 struct test_node *old = rb_entry(rb_old, struct test_node, rb);
86 struct test_node *new = rb_entry(rb_new, struct test_node, rb);
87
88 /* Rotation doesn't change subtree's augmented value */
89 new->augmented = old->augmented;
90 old->augmented = augment_recompute(old);
91}
92
93static const struct rb_augment_callbacks augment_callbacks = {
94 augment_propagate, augment_copy, augment_rotate
95};
96 66
97static void insert_augmented(struct test_node *node, struct rb_root *root) 67static void insert_augmented(struct test_node *node, struct rb_root *root)
98{ 68{