Closed yuxuanyuan closed 2 years ago
Hello! Could you provide a bit more context, i.e. what function(s) are you looking at?
Thanks for your reply. What I'm looking for is a function which can return all overlapped intervals in a list of intervals. The function is someting like:
fn intersect_intervals(intervals:Vec<Iv>) -> Vec<Iv> {}
Ah, I see. I think you could use the primitives in lapper to do that already in a not terribly inefficient way. I think there are more efficient ways to do this though, possibly involving HashSets. Realistically I probably won't be doing much work on rust-lapper
in the near future to add Hash
to Interval, or add a specific function for doing intersect_intervals
.
However, if you wanted to make a PR adding Hash
, or adding a truly efficient intersect_intervals
method I'd be totally open to that!
use rust_lapper::{Interval, Lapper};
fn main() {
let mut intervals = (0..100)
.step_by(5)
.map(|x| Interval {
start: x,
stop: x + 2,
val: true,
})
.collect::<Vec<Interval<usize, bool>>>();
intervals.push(Interval {
start: 96,
stop: 98,
val: true,
});
let lapper = Lapper::new(intervals);
let mut found = Vec::new();
let mut cursor = 0;
for i in lapper.iter() {
if lapper.seek(i.start, i.stop, &mut cursor).count() > 1 {
found.push(i);
}
}
eprintln!("{:?}", found);
}
Closing for now, feel free to re-open with any further questions.
Hi, Would it be possible to report the merged or overalapped intervals rather than the length?