|
@@ -41,7 +41,9 @@ struct rb_augment_callbacks {
|
|
|
void (*rotate)(struct rb_node *old, struct rb_node *new);
|
|
|
};
|
|
|
|
|
|
-extern void __rb_insert_augmented(struct rb_node *node, struct rb_root *root,
|
|
|
+extern void __rb_insert_augmented(struct rb_node *node,
|
|
|
+ struct rb_root *root,
|
|
|
+ bool newleft, struct rb_node **leftmost,
|
|
|
void (*augment_rotate)(struct rb_node *old, struct rb_node *new));
|
|
|
/*
|
|
|
* Fixup the rbtree and update the augmented information when rebalancing.
|
|
@@ -57,7 +59,16 @@ static inline void
|
|
|
rb_insert_augmented(struct rb_node *node, struct rb_root *root,
|
|
|
const struct rb_augment_callbacks *augment)
|
|
|
{
|
|
|
- __rb_insert_augmented(node, root, augment->rotate);
|
|
|
+ __rb_insert_augmented(node, root, false, NULL, augment->rotate);
|
|
|
+}
|
|
|
+
|
|
|
+static inline void
|
|
|
+rb_insert_augmented_cached(struct rb_node *node,
|
|
|
+ struct rb_root_cached *root, bool newleft,
|
|
|
+ const struct rb_augment_callbacks *augment)
|
|
|
+{
|
|
|
+ __rb_insert_augmented(node, &root->rb_root,
|
|
|
+ newleft, &root->rb_leftmost, augment->rotate);
|
|
|
}
|
|
|
|
|
|
#define RB_DECLARE_CALLBACKS(rbstatic, rbname, rbstruct, rbfield, \
|
|
@@ -150,6 +161,7 @@ extern void __rb_erase_color(struct rb_node *parent, struct rb_root *root,
|
|
|
|
|
|
static __always_inline struct rb_node *
|
|
|
__rb_erase_augmented(struct rb_node *node, struct rb_root *root,
|
|
|
+ struct rb_node **leftmost,
|
|
|
const struct rb_augment_callbacks *augment)
|
|
|
{
|
|
|
struct rb_node *child = node->rb_right;
|
|
@@ -157,6 +169,9 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
|
|
|
struct rb_node *parent, *rebalance;
|
|
|
unsigned long pc;
|
|
|
|
|
|
+ if (leftmost && node == *leftmost)
|
|
|
+ *leftmost = rb_next(node);
|
|
|
+
|
|
|
if (!tmp) {
|
|
|
/*
|
|
|
* Case 1: node to erase has no more than 1 child (easy!)
|
|
@@ -256,9 +271,21 @@ static __always_inline void
|
|
|
rb_erase_augmented(struct rb_node *node, struct rb_root *root,
|
|
|
const struct rb_augment_callbacks *augment)
|
|
|
{
|
|
|
- struct rb_node *rebalance = __rb_erase_augmented(node, root, augment);
|
|
|
+ struct rb_node *rebalance = __rb_erase_augmented(node, root,
|
|
|
+ NULL, augment);
|
|
|
if (rebalance)
|
|
|
__rb_erase_color(rebalance, root, augment->rotate);
|
|
|
}
|
|
|
|
|
|
+static __always_inline void
|
|
|
+rb_erase_augmented_cached(struct rb_node *node, struct rb_root_cached *root,
|
|
|
+ const struct rb_augment_callbacks *augment)
|
|
|
+{
|
|
|
+ struct rb_node *rebalance = __rb_erase_augmented(node, &root->rb_root,
|
|
|
+ &root->rb_leftmost,
|
|
|
+ augment);
|
|
|
+ if (rebalance)
|
|
|
+ __rb_erase_color(rebalance, &root->rb_root, augment->rotate);
|
|
|
+}
|
|
|
+
|
|
|
#endif /* _LINUX_RBTREE_AUGMENTED_H */
|