24 #ifndef _LINUX_RBTREE_AUGMENTED_H
25 #define _LINUX_RBTREE_AUGMENTED_H
27 #include <linux/compiler.h>
28 #include <linux/rbtree.h>
53 #define RB_DECLARE_CALLBACKS(rbstatic, rbname, rbstruct, rbfield, \
54 rbtype, rbaugmented, rbcompute) \
56 rbname ## _propagate(struct rb_node *rb, struct rb_node *stop) \
58 while (rb != stop) { \
59 rbstruct *node = rb_entry(rb, rbstruct, rbfield); \
60 rbtype augmented = rbcompute(node); \
61 if (node->rbaugmented == augmented) \
63 node->rbaugmented = augmented; \
64 rb = rb_parent(&node->rbfield); \
68 rbname ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \
70 rbstruct *old = rb_entry(rb_old, rbstruct, rbfield); \
71 rbstruct *new = rb_entry(rb_new, rbstruct, rbfield); \
72 new->rbaugmented = old->rbaugmented; \
75 rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
77 rbstruct *old = rb_entry(rb_old, rbstruct, rbfield); \
78 rbstruct *new = rb_entry(rb_new, rbstruct, rbfield); \
79 new->rbaugmented = old->rbaugmented; \
80 old->rbaugmented = rbcompute(old); \
82 rbstatic const struct rb_augment_callbacks rbname = { \
83 rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
90 #define __rb_parent(pc) ((struct rb_node *)(pc & ~3))
92 #define __rb_color(pc) ((pc) & 1)
93 #define __rb_is_black(pc) __rb_color(pc)
94 #define __rb_is_red(pc) (!__rb_color(pc))
95 #define rb_color(rb) __rb_color((rb)->__rb_parent_color)
96 #define rb_is_red(rb) __rb_is_red((rb)->__rb_parent_color)
97 #define rb_is_black(rb) __rb_is_black((rb)->__rb_parent_color)
104 static inline void rb_set_parent_color(
struct rb_node *
rb,
124 void (*augment_rotate)(
struct rb_node *old,
struct rb_node *
new));
131 struct rb_node *parent, *rebalance;
144 __rb_change_child(node, child, parent, root);
155 __rb_change_child(node,
tmp, parent, root);
159 struct rb_node *successor = child, *child2;
173 augment->
copy(node, successor);
196 rb_set_parent(child, successor);
197 augment->
copy(node, successor);
202 rb_set_parent(
tmp, successor);
206 __rb_change_child(node, successor,
tmp, root);
209 rb_set_parent_color(child2, parent,
RB_BLACK);