From 002f2b7cf9bf803f957777d72b3d9bdf9e7cdc83 Mon Sep 17 00:00:00 2001 From: bsbds <69835502+bsbds@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:21:00 +0800 Subject: [PATCH] refactor: reduce some cases that don't need to update max Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com> --- crates/utils/src/interval_map/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/utils/src/interval_map/mod.rs b/crates/utils/src/interval_map/mod.rs index 16ba372d2..63fba44ae 100644 --- a/crates/utils/src/interval_map/mod.rs +++ b/crates/utils/src/interval_map/mod.rs @@ -261,17 +261,21 @@ where if self.left_ref(z, Node::is_sentinel) { x = self.node_ref(z, Node::right); self.transplant(z, x); + self.update_max_bottom_up(self.node_ref(z, Node::parent)); } else if self.right_ref(z, Node::is_sentinel) { x = self.node_ref(z, Node::left); self.transplant(z, x); + self.update_max_bottom_up(self.node_ref(z, Node::parent)); } else { y = self.tree_minimum(self.node_ref(z, Node::right)); + let mut p = y; y_orig_color = self.node_ref(y, Node::color); x = self.node_ref(y, Node::right); if self.node_ref(y, Node::parent) == z { self.node_mut(x, Node::set_parent(y)); } else { self.transplant(y, x); + p = self.node_ref(y, Node::parent); self.node_mut(y, Node::set_right(self.node_ref(z, Node::right))); self.right_mut(y, Node::set_parent(y)); } @@ -280,7 +284,7 @@ where self.left_mut(y, Node::set_parent(y)); self.node_mut(y, Node::set_color(self.node_ref(z, Node::color))); - self.update_max_bottom_up(y); + self.update_max_bottom_up(p); } if matches!(y_orig_color, Color::Black) { @@ -587,7 +591,6 @@ where } else { self.parent_mut(u, Node::set_right(v)); } - self.update_max_bottom_up(self.node_ref(u, Node::parent)); } self.node_mut(v, Node::set_parent(self.node_ref(u, Node::parent))); }