mirror of
https://github.com/torvalds/linux.git
synced 2026-05-28 09:04:39 +02:00
rust: rbtree: add RBTree::is_empty
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@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250616-rbtree-is-empty-v1-1-61f7cfb012e3@google.com [ Adjusted title. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
0303584766
commit
fbcd4b7bf5
|
|
@ -191,6 +191,12 @@ pub fn new() -> Self {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns true if this tree is empty.
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.root.rb_node.is_null()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the tree nodes, sorted by key.
|
||||
pub fn iter(&self) -> Iter<'_, K, V> {
|
||||
Iter {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user