Skip to content

Commit

Permalink
refactor: returns value in find_all_overlap
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Feb 29, 2024
1 parent fea938b commit 40f5a1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions crates/utils/src/interval_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>) -> Vec<&Interval<T>> {
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<T>) -> Vec<(&Interval<T>, &V)> {
if self.nref(self.root, Node::is_sentinel) {
Vec::new()
} else {
self.find_all_overlap_inner(self.root, interval)
}
}

Expand Down Expand Up @@ -286,10 +286,10 @@ where
&self,
x: NodeIndex<Ix>,
interval: &Interval<T>,
) -> Vec<&Interval<T>> {
) -> Vec<(&Interval<T>, &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)
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/interval_map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down

0 comments on commit 40f5a1c

Please sign in to comment.