Skip to content

Commit 1c75925

Browse files
wedsonafmatthewtgilbride
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/[email protected]/ [1] Signed-off-by: Wedson Almeida Filho <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Tested-by: Alice Ryhl <[email protected]> Signed-off-by: Matt Gilbride <[email protected]>
1 parent 89a3e93 commit 1c75925

File tree

3 files changed

+445
-0
lines changed

3 files changed

+445
-0
lines changed

rust/helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ void rust_helper_init_work_with_key(struct work_struct *work, work_func_t func,
157157
}
158158
EXPORT_SYMBOL_GPL(rust_helper_init_work_with_key);
159159

160+
void rust_helper_rb_link_node(struct rb_node *node, struct rb_node *parent,
161+
struct rb_node **rb_link)
162+
{
163+
rb_link_node(node, parent, rb_link);
164+
}
165+
EXPORT_SYMBOL_GPL(rust_helper_rb_link_node);
166+
160167
/*
161168
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
162169
* use it in contexts where Rust expects a `usize` like slice (array) indices.

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub mod kunit;
3737
pub mod net;
3838
pub mod prelude;
3939
pub mod print;
40+
pub mod rbtree;
4041
mod static_assert;
4142
#[doc(hidden)]
4243
pub mod std_vendor;

0 commit comments

Comments
 (0)