Re: [PATCH] rbtree: rust: add RBTree::is_empty
From: Benno Lossin
Date: Tue Jun 17 2025 - 03:30:25 EST
On Mon Jun 16, 2025 at 12:36 PM CEST, Alice Ryhl wrote:
> In Rust Binder I need to be able to determine whether a red/black tree
> is empty. Thus, add a method for that operation to replace
>
> rbtree.iter().next().is_none()
>
> This is terrible, so add a method for this purpose. We do not add a
> RBTree::len method because computing the number of elements requires
> iterating the entire tree, but checking whether it is empty can be done
> cheaply.
>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Reviewed-by: Benno Lossin <lossin@xxxxxxxxxx>
---
Cheers,
Benno
> ---
> rust/kernel/rbtree.rs | 6 ++++++
> 1 file changed, 6 insertions(+)