int_interval_stack/int_co_stack/
impls_for_iter.rs1use super::*;
2
3impl<I> IntCOStack<I>
4where
5 I: IntCO,
6{
7 #[inline]
8 pub fn iter_intervals(&self) -> impl Iterator<Item = (I, usize)> {
9 self.points.windows(2).filter_map(|w| {
10 let start = w[0].at;
11 let end_excl = w[1].at;
12 let height = w[0].height_after;
13
14 (height != 0).then_some((unsafe { I::new_unchecked(start, end_excl) }, height))
15 })
16 }
17
18 #[inline]
19 pub fn iter_intervals_at_least(&self, min_height: usize) -> impl Iterator<Item = (I, usize)> {
20 self.points.windows(2).filter_map(move |w| {
21 let start = w[0].at;
22 let end_excl = w[1].at;
23 let height = w[0].height_after;
24
25 (height != 0 && height >= min_height)
26 .then_some((unsafe { I::new_unchecked(start, end_excl) }, height))
27 })
28 }
29 #[inline]
30 pub fn iter_intervals_at_most(&self, max_height: usize) -> impl Iterator<Item = (I, usize)> {
31 self.points.windows(2).filter_map(move |w| {
32 let start = w[0].at;
33 let end_excl = w[1].at;
34 let height = w[0].height_after;
35
36 (height != 0 && height <= max_height)
37 .then_some((unsafe { I::new_unchecked(start, end_excl) }, height))
38 })
39 }
40
41 #[inline]
42 pub fn iter_intervals_exactly(&self, target_height: usize) -> impl Iterator<Item = (I, usize)> {
43 self.points.windows(2).filter_map(move |w| {
44 let start = w[0].at;
45 let end_excl = w[1].at;
46 let height = w[0].height_after;
47
48 (height != 0 && height == target_height)
49 .then_some((unsafe { I::new_unchecked(start, end_excl) }, height))
50 })
51 }
52
53 #[inline]
54 pub fn iter_intervals_between(
55 &self,
56 min_height: usize,
57 max_height: usize,
58 ) -> impl Iterator<Item = (I, usize)> {
59 self.points.windows(2).filter_map(move |w| {
60 let start = w[0].at;
61 let end_excl = w[1].at;
62 let height = w[0].height_after;
63
64 (height != 0 && height >= min_height && height <= max_height)
65 .then_some((unsafe { I::new_unchecked(start, end_excl) }, height))
66 })
67 }
68
69 #[inline]
70 pub fn peak_intervals(&self) -> impl Iterator<Item = (I, usize)> {
71 let max_height = self.max_height();
72
73 self.iter_intervals()
74 .filter(move |(_, height)| *height == max_height)
75 }
76}
77
78#[cfg(test)]
79mod tests_for_iter;