From 9c3a795a6140e5380fd3982b1940a3d1b8128b76 Mon Sep 17 00:00:00 2001 From: janis Date: Tue, 4 Aug 2026 18:16:37 +0200 Subject: [PATCH] rbtree: remove_node, pop_min --- crates/rbtree/src/raw_node.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/rbtree/src/raw_node.rs b/crates/rbtree/src/raw_node.rs index 40b3a00..ae0f66f 100644 --- a/crates/rbtree/src/raw_node.rs +++ b/crates/rbtree/src/raw_node.rs @@ -835,6 +835,13 @@ impl RBTree { None } + #[must_use] + pub fn pop_min(&mut self) -> Option> { + let min = self.root_handle().minimum_of()?; + + self.remove_node(min) + } + #[must_use] pub fn remove(&mut self, key: &Q) -> Option> where @@ -845,6 +852,11 @@ impl RBTree { return None; }; + self.remove_node(z) + } + + #[must_use] + fn remove_node(&mut self, z: Handle) -> Option> { // 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).