rbtree: remove_node, pop_min

This commit is contained in:
janis 2026-08-04 18:16:37 +02:00
parent 80ffe15e6c
commit 9c3a795a61
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8

View file

@ -835,6 +835,13 @@ impl<N: UnsafeNode> RBTree<N> {
None
}
#[must_use]
pub fn pop_min(&mut self) -> Option<NonNull<N>> {
let min = self.root_handle().minimum_of()?;
self.remove_node(min)
}
#[must_use]
pub fn remove<Q>(&mut self, key: &Q) -> Option<NonNull<N>>
where
@ -845,6 +852,11 @@ impl<N: UnsafeNode> RBTree<N> {
return None;
};
self.remove_node(z)
}
#[must_use]
fn remove_node(&mut self, z: Handle<N>) -> Option<NonNull<N>> {
// Y is either Z, the removed node in the case that Z has at most
// one child, or Y is Z's successor which is guaranteed to have at most one
// child (the right child).