rust: rbtree: add `RBTree::entry`
authorAlice Ryhl <aliceryhl@google.com>
Thu, 22 Aug 2024 16:37:57 +0000 (16:37 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Sat, 31 Aug 2024 15:36:20 +0000 (17:36 +0200)
commita335e95914046c6bed45c0d17cabcd483682cf5e
treee2454458acbe0a4e5e6e5c1d83e14b17721d4ed9
parent98c14e40e07a077827f6842e8f31d191cb82576c
rust: rbtree: add `RBTree::entry`

This mirrors the entry API [1] from the Rust standard library on
`RBTree`. This API can be used to access the entry at a specific key and
make modifications depending on whether the key is vacant or occupied.
This API is useful because it can often be used to avoid traversing the
tree multiple times.

This is used by binder to look up and conditionally access or insert a
value, depending on whether it is there or not [2].

Link: https://doc.rust-lang.org/stable/std/collections/btree_map/enum.Entry.html
Link: https://android-review.googlesource.com/c/kernel/common/+/2849906
Signed-off-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/20240822-b4-rbtree-v12-5-014561758a57@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/rbtree.rs