1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::*;
impl<I: IntCO> IntCOSet<I> {
/// Iterates over all canonical intervals intersecting `query`.
///
/// The iterator yields original intervals stored in the set,
/// not clipped intersection segments.
///
/// Complexity: `O(log n + k)`, where `k` is the number of
/// returned intervals.
#[inline]
pub fn intervals_intersecting(&self, query: I) -> impl Iterator<Item = I> + '_ {
let i = self
.intervals
.partition_point(|iv| iv.end_excl() <= query.start());
self.intervals[i..]
.iter()
.copied()
.take_while(move |iv| iv.start() < query.end_excl())
}
}
impl<I: IntCO> IntCOSet<I> {
/// Returns the unique interval containing `x`, if any.
///
/// Because the set is canonical, at most one interval can
/// contain a single point.
///
/// Complexity: `O(log n)`.
#[inline]
pub fn interval_containing_point(&self, x: I::CoordType) -> Option<I> {
let i = self.intervals.partition_point(|iv| iv.start() <= x);
if i == 0 {
return None;
}
let iv = self.intervals[i - 1];
iv.contains(x).then_some(iv)
}
}
#[cfg(test)]
mod tests_for_interval_containing_point;
#[cfg(test)]
mod tests_for_intervals_intersecting;