rbtree: remove_node, pop_min
This commit is contained in:
parent
80ffe15e6c
commit
9c3a795a61
|
|
@ -835,6 +835,13 @@ impl<N: UnsafeNode> RBTree<N> {
|
||||||
None
|
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]
|
#[must_use]
|
||||||
pub fn remove<Q>(&mut self, key: &Q) -> Option<NonNull<N>>
|
pub fn remove<Q>(&mut self, key: &Q) -> Option<NonNull<N>>
|
||||||
where
|
where
|
||||||
|
|
@ -845,6 +852,11 @@ impl<N: UnsafeNode> RBTree<N> {
|
||||||
return None;
|
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
|
// 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
|
// one child, or Y is Z's successor which is guaranteed to have at most one
|
||||||
// child (the right child).
|
// child (the right child).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue