24 #include <linux/rbtree_augmented.h>
25 #include <linux/export.h>
47 static inline void rb_set_black(
struct rb_node *
rb)
68 rb_set_parent_color(old,
new, color);
69 __rb_change_child(old,
new, parent, root);
92 gparent = rb_red_parent(parent);
94 tmp = gparent->rb_right;
110 rb_set_parent_color(tmp, gparent,
RB_BLACK);
111 rb_set_parent_color(parent, gparent,
RB_BLACK);
114 rb_set_parent_color(node, parent,
RB_RED);
135 rb_set_parent_color(tmp, parent,
137 rb_set_parent_color(parent, node,
RB_RED);
138 augment_rotate(parent, node);
152 gparent->rb_left =
tmp;
155 rb_set_parent_color(tmp, gparent,
RB_BLACK);
156 __rb_rotate_set_parents(gparent, parent, root,
RB_RED);
157 augment_rotate(gparent, parent);
160 tmp = gparent->rb_left;
163 rb_set_parent_color(tmp, gparent,
RB_BLACK);
164 rb_set_parent_color(parent, gparent,
RB_BLACK);
167 rb_set_parent_color(node, parent,
RB_RED);
177 rb_set_parent_color(tmp, parent,
179 rb_set_parent_color(parent, node,
RB_RED);
180 augment_rotate(parent, node);
186 gparent->rb_right =
tmp;
189 rb_set_parent_color(tmp, gparent,
RB_BLACK);
190 __rb_rotate_set_parents(gparent, parent, root,
RB_RED);
191 augment_rotate(gparent, parent);
212 if (node != sibling) {
223 parent->
rb_right = tmp1 = sibling->rb_left;
224 sibling->rb_left = parent;
225 rb_set_parent_color(tmp1, parent,
RB_BLACK);
226 __rb_rotate_set_parents(parent, sibling, root,
228 augment_rotate(parent, sibling);
231 tmp1 = sibling->rb_right;
233 tmp2 = sibling->rb_left;
250 rb_set_parent_color(sibling, parent,
253 rb_set_black(parent);
274 sibling->rb_left = tmp1 = tmp2->rb_right;
275 tmp2->rb_right = sibling;
278 rb_set_parent_color(tmp1, sibling,
280 augment_rotate(sibling, tmp2);
296 parent->
rb_right = tmp2 = sibling->rb_left;
297 sibling->rb_left = parent;
298 rb_set_parent_color(tmp1, sibling,
RB_BLACK);
300 rb_set_parent(tmp2, parent);
301 __rb_rotate_set_parents(parent, sibling, root,
303 augment_rotate(parent, sibling);
309 parent->
rb_left = tmp1 = sibling->rb_right;
310 sibling->rb_right = parent;
311 rb_set_parent_color(tmp1, parent,
RB_BLACK);
312 __rb_rotate_set_parents(parent, sibling, root,
314 augment_rotate(parent, sibling);
317 tmp1 = sibling->rb_left;
319 tmp2 = sibling->rb_right;
322 rb_set_parent_color(sibling, parent,
325 rb_set_black(parent);
335 sibling->rb_right = tmp1 = tmp2->rb_left;
336 tmp2->rb_left = sibling;
339 rb_set_parent_color(tmp1, sibling,
341 augment_rotate(sibling, tmp2);
346 parent->
rb_left = tmp2 = sibling->rb_right;
347 sibling->rb_right = parent;
348 rb_set_parent_color(tmp1, sibling,
RB_BLACK);
350 rb_set_parent(tmp2, parent);
351 __rb_rotate_set_parents(parent, sibling, root,
353 augment_rotate(parent, sibling);
368 static inline void dummy_copy(
struct rb_node *old,
struct rb_node *
new) {}
369 static inline void dummy_rotate(
struct rb_node *old,
struct rb_node *
new) {}
372 dummy_propagate, dummy_copy, dummy_rotate
377 __rb_insert(node, root, dummy_rotate);
383 rb_erase_augmented(node, root, &dummy_callbacks);
397 __rb_insert(node, root, augment_rotate);
497 __rb_change_child(victim,
new, parent, root);
499 rb_set_parent(victim->
rb_left,
new);
501 rb_set_parent(victim->
rb_right,
new);