pub fn overlapping<A, B, T, Fsa, Fea, Fsb, Feb>(
start_a: Fsa,
end_a: Fea,
start_b: Fsb,
end_b: Feb,
) -> OverlappingJoiner<Fsa, Fea, Fsb, Feb, T>Expand description
Creates a joiner that matches when two intervals overlap.
Two intervals [start_a, end_a) and [start_b, end_b) overlap if:
- start_a < end_b AND start_b < end_a
This uses half-open intervals: the start is inclusive, the end is exclusive.
ยงExample
use solverforge_scoring::stream::joiner::{Joiner, overlapping};
#[derive(Clone)]
struct Shift { start: i64, end: i64 }
let overlap = overlapping(
|s: &Shift| s.start,
|s: &Shift| s.end,
|s: &Shift| s.start,
|s: &Shift| s.end
);
// Overlapping shifts: [0, 10) and [5, 15) overlap at [5, 10)
assert!(overlap.matches(
&Shift { start: 0, end: 10 },
&Shift { start: 5, end: 15 }
));
// Non-overlapping shifts: [0, 10) and [10, 20) touch but don't overlap
assert!(!overlap.matches(
&Shift { start: 0, end: 10 },
&Shift { start: 10, end: 20 }
));
// Non-overlapping shifts: [0, 5) and [10, 15) are disjoint
assert!(!overlap.matches(
&Shift { start: 0, end: 5 },
&Shift { start: 10, end: 15 }
));