diff options
Diffstat (limited to 'include/linux/rbtree_augmented.h')
-rw-r--r-- | include/linux/rbtree_augmented.h | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h index 0f902ccb48b0..179faab29f52 100644 --- a/include/linux/rbtree_augmented.h +++ b/include/linux/rbtree_augmented.h | |||
@@ -30,10 +30,9 @@ struct rb_augment_callbacks { | |||
30 | void (*rotate)(struct rb_node *old, struct rb_node *new); | 30 | void (*rotate)(struct rb_node *old, struct rb_node *new); |
31 | }; | 31 | }; |
32 | 32 | ||
33 | extern void __rb_insert_augmented(struct rb_node *node, | 33 | extern void __rb_insert_augmented(struct rb_node *node, struct rb_root *root, |
34 | struct rb_root *root, | ||
35 | bool newleft, struct rb_node **leftmost, | ||
36 | void (*augment_rotate)(struct rb_node *old, struct rb_node *new)); | 34 | void (*augment_rotate)(struct rb_node *old, struct rb_node *new)); |
35 | |||
37 | /* | 36 | /* |
38 | * Fixup the rbtree and update the augmented information when rebalancing. | 37 | * Fixup the rbtree and update the augmented information when rebalancing. |
39 | * | 38 | * |
@@ -48,7 +47,7 @@ static inline void | |||
48 | rb_insert_augmented(struct rb_node *node, struct rb_root *root, | 47 | rb_insert_augmented(struct rb_node *node, struct rb_root *root, |
49 | const struct rb_augment_callbacks *augment) | 48 | const struct rb_augment_callbacks *augment) |
50 | { | 49 | { |
51 | __rb_insert_augmented(node, root, false, NULL, augment->rotate); | 50 | __rb_insert_augmented(node, root, augment->rotate); |
52 | } | 51 | } |
53 | 52 | ||
54 | static inline void | 53 | static inline void |
@@ -56,8 +55,9 @@ rb_insert_augmented_cached(struct rb_node *node, | |||
56 | struct rb_root_cached *root, bool newleft, | 55 | struct rb_root_cached *root, bool newleft, |
57 | const struct rb_augment_callbacks *augment) | 56 | const struct rb_augment_callbacks *augment) |
58 | { | 57 | { |
59 | __rb_insert_augmented(node, &root->rb_root, | 58 | if (newleft) |
60 | newleft, &root->rb_leftmost, augment->rotate); | 59 | root->rb_leftmost = node; |
60 | rb_insert_augmented(node, &root->rb_root, augment); | ||
61 | } | 61 | } |
62 | 62 | ||
63 | #define RB_DECLARE_CALLBACKS(rbstatic, rbname, rbstruct, rbfield, \ | 63 | #define RB_DECLARE_CALLBACKS(rbstatic, rbname, rbstruct, rbfield, \ |
@@ -150,7 +150,6 @@ extern void __rb_erase_color(struct rb_node *parent, struct rb_root *root, | |||
150 | 150 | ||
151 | static __always_inline struct rb_node * | 151 | static __always_inline struct rb_node * |
152 | __rb_erase_augmented(struct rb_node *node, struct rb_root *root, | 152 | __rb_erase_augmented(struct rb_node *node, struct rb_root *root, |
153 | struct rb_node **leftmost, | ||
154 | const struct rb_augment_callbacks *augment) | 153 | const struct rb_augment_callbacks *augment) |
155 | { | 154 | { |
156 | struct rb_node *child = node->rb_right; | 155 | struct rb_node *child = node->rb_right; |
@@ -158,9 +157,6 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root, | |||
158 | struct rb_node *parent, *rebalance; | 157 | struct rb_node *parent, *rebalance; |
159 | unsigned long pc; | 158 | unsigned long pc; |
160 | 159 | ||
161 | if (leftmost && node == *leftmost) | ||
162 | *leftmost = rb_next(node); | ||
163 | |||
164 | if (!tmp) { | 160 | if (!tmp) { |
165 | /* | 161 | /* |
166 | * Case 1: node to erase has no more than 1 child (easy!) | 162 | * Case 1: node to erase has no more than 1 child (easy!) |
@@ -260,8 +256,7 @@ static __always_inline void | |||
260 | rb_erase_augmented(struct rb_node *node, struct rb_root *root, | 256 | rb_erase_augmented(struct rb_node *node, struct rb_root *root, |
261 | const struct rb_augment_callbacks *augment) | 257 | const struct rb_augment_callbacks *augment) |
262 | { | 258 | { |
263 | struct rb_node *rebalance = __rb_erase_augmented(node, root, | 259 | struct rb_node *rebalance = __rb_erase_augmented(node, root, augment); |
264 | NULL, augment); | ||
265 | if (rebalance) | 260 | if (rebalance) |
266 | __rb_erase_color(rebalance, root, augment->rotate); | 261 | __rb_erase_color(rebalance, root, augment->rotate); |
267 | } | 262 | } |
@@ -270,11 +265,9 @@ static __always_inline void | |||
270 | rb_erase_augmented_cached(struct rb_node *node, struct rb_root_cached *root, | 265 | rb_erase_augmented_cached(struct rb_node *node, struct rb_root_cached *root, |
271 | const struct rb_augment_callbacks *augment) | 266 | const struct rb_augment_callbacks *augment) |
272 | { | 267 | { |
273 | struct rb_node *rebalance = __rb_erase_augmented(node, &root->rb_root, | 268 | if (root->rb_leftmost == node) |
274 | &root->rb_leftmost, | 269 | root->rb_leftmost = rb_next(node); |
275 | augment); | 270 | rb_erase_augmented(node, &root->rb_root, augment); |
276 | if (rebalance) | ||
277 | __rb_erase_color(rebalance, &root->rb_root, augment->rotate); | ||
278 | } | 271 | } |
279 | 272 | ||
280 | #endif /* _LINUX_RBTREE_AUGMENTED_H */ | 273 | #endif /* _LINUX_RBTREE_AUGMENTED_H */ |