rbtree: Examine rb_add* helpers in rbtree_test
PATCH 1/1 rbtree: Examine rb_add* helpers in rbtree_test
From: RinHizakura <[email protected]>
We had introduced rb_add() and rb_add_cached() helper for the partial-order based rbtree, which may be the most commonly way to use rbtree. We also have rb_add_augmented_cached() for EEVDF now. Since these helpers are actually the same as what rbtree_test examines for, we can reuse these helpers to test them under rbtree_test directly.
This also introduces some correctness test and benchmarking for these generic interface, which means the correctness and performance can be minimally guarantee under the tests. User can choose to use these great rb_add* helpers without extra effort to implement their own one considering the test results.
--- include/linux/rbtree_augmented.h | 21 ++++++++ lib/rbtree_test.c | 82 +++++--------------------------- 2 files changed, 32 insertions(+), 71 deletions(-)
include/linux/rbtree_augmented.h +21 -0
@@ -86,6 +86,27 @@ rb_add_augmented_cached(struct rb_node *node, struct rb_root_cached *tree,return leftmost ? node :NULL ; } +static __always_inline void +rb_add_augmented (struct rb_node *node,struct rb_root *tree, +bool (*less)(struct rb_node *,const struct rb_node *), +const struct rb_augment_callbacks *augment) +{ +struct rb_node **link = &tree->rb_node; +struct rb_node *parent =NULL ; + +while (*link) { + parent = *link; +if (less (node, parent)) + link = &parent->rb_left; +else + link = &parent->rb_right; + } + +rb_link_node (node, parent, link); + augment->propagate (parent,NULL ); +rb_insert_augmented (node, tree, augment); +} +/* * Template for declaring augmented rbtree callbacks (generic case) *
lib/rbtree_test.c +11 -71
105 lines not on this page · raw message
Signature · 1 line
2.34.1