From 40f5a1c281d9f8cd570cb1c6e5cd79db9ab1f8e9 Mon Sep 17 00:00:00 2001 From: bsbds <69835502+bsbds@users.noreply.github.com> Date: Wed, 28 Feb 2024 21:06:48 +0800 Subject: [PATCH] refactor: returns value in find_all_overlap Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com> --- crates/utils/src/interval_map/mod.rs | 12 ++++++------ crates/utils/src/interval_map/tests.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/utils/src/interval_map/mod.rs b/crates/utils/src/interval_map/mod.rs index 86ab27abd..b5f230a28 100644 --- a/crates/utils/src/interval_map/mod.rs +++ b/crates/utils/src/interval_map/mod.rs @@ -77,11 +77,11 @@ where /// Finds all intervals in the map that overlaps with the given interval. #[inline] - pub fn find_all_overlap(&self, interval: &Interval) -> Vec<&Interval> { - if !self.nref(self.root, Node::is_sentinel) { - self.find_all_overlap_inner(self.root, interval) - } else { + pub fn find_all_overlap(&self, interval: &Interval) -> Vec<(&Interval, &V)> { + if self.nref(self.root, Node::is_sentinel) { Vec::new() + } else { + self.find_all_overlap_inner(self.root, interval) } } @@ -286,10 +286,10 @@ where &self, x: NodeIndex, interval: &Interval, - ) -> Vec<&Interval> { + ) -> Vec<(&Interval, &V)> { let mut list = vec![]; if self.nref(x, Node::interval).overlap(interval) { - list.push(self.nref(x, Node::interval)); + list.push(self.nref(x, |nx| (nx.interval(), nx.value()))); } if self .left_ref(x, Node::sentinel) diff --git a/crates/utils/src/interval_map/tests.rs b/crates/utils/src/interval_map/tests.rs index c449b4121..aeebea1dc 100644 --- a/crates/utils/src/interval_map/tests.rs +++ b/crates/utils/src/interval_map/tests.rs @@ -258,7 +258,7 @@ fn find_all_overlap() { result.sort_unstable(); assert_eq!(expect.len(), result.len()); for (e, r) in expect.into_iter().zip(result.into_iter()) { - assert_eq!(e, r); + assert_eq!(e, r.0); } } });