]> git.hungrycats.org Git - linux/commit
rbtree: Add generic add and find helpers
authorPeter Zijlstra <peterz@infradead.org>
Wed, 29 Apr 2020 15:03:22 +0000 (17:03 +0200)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 5 Dec 2021 08:11:11 +0000 (03:11 -0500)
commitbb7ae277e3d1993982fa84e3a3a988a155f34fed
tree145c6434130dd01d2945bfec2cd5d95310bf11e3
parentd48fca16a0912b8c3143d10f43a0e29fe26985b7
rbtree: Add generic add and find helpers

I've always been bothered by the endless (fragile) boilerplate for
rbtree, and I recently wrote some rbtree helpers for objtool and
figured I should lift them into the kernel and use them more widely.

Provide:

partial-order; less() based:
 - rb_add(): add a new entry to the rbtree
 - rb_add_cached(): like rb_add(), but for a rb_root_cached

total-order; cmp() based:
 - rb_find(): find an entry in an rbtree
 - rb_find_add(): find an entry, and add if not found

 - rb_find_first(): find the first (leftmost) matching entry
 - rb_next_match(): continue from rb_find_first()
 - rb_for_each(): iterate a sub-tree using the previous two

Inlining and constant propagation should see the compiler inline the
whole thing, including the various compare functions.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Michel Lespinasse <walken@google.com>
Acked-by: Davidlohr Bueso <dbueso@suse.de>
(cherry picked from commit 2d24dd5798d0474d9bf705bfca8725e7d20f9d54)
(cherry picked from commit cf3bd7e3763449ba03f9354bd299224be5ec6421)
include/linux/rbtree.h
tools/include/linux/rbtree.h
tools/objtool/elf.c