Skip to content

Commit 61180f4

Browse files
wedsonaffbq
authored andcommitted
rust: rbtree: add red-black tree implementation backed by the C version
The rust rbtree exposes a map-like interface over keys and values, backed by the kernel red-black tree implementation. Values can be inserted, deleted, and retrieved from a `RBTree` by key. This base abstraction is used by binder to store key/value pairs and perform lookups, for example the patch "[PATCH RFC 03/20] rust_binder: add threading support" in the binder RFC [1]. Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-3-08ba9197f637@google.com/ [1] Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Tested-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Matt Gilbride <mattgilbride@google.com> Link: https://lore.kernel.org/r/20240819-b4-rbtree-v10-1-3b3b2c4d73af@google.com
1 parent a0532e4 commit 61180f4

File tree

4 files changed

+443
-0
lines changed

4 files changed

+443
-0
lines changed

rust/helpers/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "kunit.c"
1616
#include "mutex.c"
1717
#include "page.c"
18+
#include "rbtree.c"
1819
#include "refcount.c"
1920
#include "signal.c"
2021
#include "slab.c"

rust/helpers/rbtree.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/rbtree.h>
4+
5+
void rust_helper_rb_link_node(struct rb_node *node, struct rb_node *parent,
6+
struct rb_node **rb_link)
7+
{
8+
rb_link_node(node, parent, rb_link);
9+
}

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub mod net;
4343
pub mod page;
4444
pub mod prelude;
4545
pub mod print;
46+
pub mod rbtree;
4647
mod static_assert;
4748
#[doc(hidden)]
4849
pub mod std_vendor;

0 commit comments

Comments
 (0)