Debian Codegraph @

src/operations.rs

raw symbols SCIP
1 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
2 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::{FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#, Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#};
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#, RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#};
4
5 /// Trait to determine the ordering of the start and end of a range.
6 trait RangeOrderrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder# {
7 /// Ordering of start value
8 fn order_startrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder#order_start().(&self, other: &Self) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
9
10 /// Ordering of end value
11 fn order_endrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder#order_end().(&self, other: &Self) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
12 }
13
14 impl<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#> RangeOrderrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder# for Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<T> {
15 fn order_startrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeOrder]order_start().(&self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeOrder]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
16 self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#cmp().(&other.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.)
17 }
18
19 fn order_endrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeOrder]order_end().(&self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeOrder]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
20 self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#cmp().(&other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.)
21 }
22 }
23
24 impl<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#> RangeOrderrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder# for RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<T> {
25 fn order_startrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeOrder]order_start().(&self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeOrder]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
26 self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#cmp().(other.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().())
27 }
28
29 fn order_endrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeOrder]order_end().(&self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeOrder]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
30 self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#cmp().(other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().())
31 }
32 }
33
34 /// Range which can be merged with a next range if they overlap.
35 trait RangeMergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
36 /// Merges this range and the next range, if they overlap.
37 fn mergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge#merge().(&mut self, next: &Self) -> bool;
38 }
39
40 impl<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> RangeMergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge# for Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<T> {
41 fn mergerust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeMerge]merge().(&mut self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeMerge]) -> bool {
42 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`]contains().(&other.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.) {
43 return false;
44 }
45
46 if other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. {
47 self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. = other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
48 }
49
50 true
51 }
52 }
53
54 impl<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> RangeMergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge# for RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<T> {
55 fn mergerust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeMerge]merge().(&mut self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeMerge]) -> bool {
56 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(other.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().()) {
57 return false;
58 }
59
60 if other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() {
61 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
62 }
63
64 true
65 }
66 }
67
68 /// Range which can be merged with a next range if they overlap.
69 trait RangeIntersectrust-analyzer cargo rangemap 1.7.1 operations/RangeIntersect#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
70 /// Attempt to merge the next range into the current range, if they overlap.
71 fn intersectrust-analyzer cargo rangemap 1.7.1 operations/RangeIntersect#intersect().(&self, next: &Self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self>;
72 }
73
74 impl<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> RangeIntersectrust-analyzer cargo rangemap 1.7.1 operations/RangeIntersect# for Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<T> {
75 fn intersectrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeIntersect]intersect().(&self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeIntersect]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeIntersect]> {
76 let start = (&self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.).maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(&other.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.);
77 let end = (&self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(&other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.);
78
79 if start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]ge().end {
80 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
81 }
82
83 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().())
84 }
85 }
86
87 impl<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> RangeIntersectrust-analyzer cargo rangemap 1.7.1 operations/RangeIntersect# for RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<T> {
88 fn intersectrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeIntersect]intersect().(&self, other: &Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeIntersect]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`RangeInclusive<T>`][RangeIntersect]> {
89 let start = self.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().().maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(other.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().());
90 let end = self.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().().minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(other.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().());
91
92 if start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().end {
93 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
94 }
95
96 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#end.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().())
97 }
98 }
99
100 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
101 fn test_intersectrust-analyzer cargo rangemap 1.7.1 operations/test_intersect().() {
102 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((0..5).intersectrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeIntersect]intersect().(&(0..3)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0..3));
103 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((0..3).intersectrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeIntersect]intersect().(&(0..5)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0..3));
104 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((0..3).intersectrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Range<T>`][RangeIntersect]intersect().(&(3..3)), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
105 }
106
107 /// Iterator that produces the union of two iterators of sorted ranges.
108 pub struct Unionrust-analyzer cargo rangemap 1.7.1 operations/Union#<'a, T, L, R = L>
109 where
110 T: 'a,
111 L: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
112 R: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
113 {
114 leftrust-analyzer cargo rangemap 1.7.1 operations/Union#left.: Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<L>,
115 rightrust-analyzer cargo rangemap 1.7.1 operations/Union#right.: Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<R>,
116 }
117
118 impl<'a, T, L, R> Unionrust-analyzer cargo rangemap 1.7.1 operations/Union#<'a, T, L, R>
119 where
120 T: 'a,
121 L: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
122 R: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
123 {
124 /// Create new Union iterator.
125 ///
126 /// Requires that the two iterators produce sorted ranges.
127 pub fn newrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Union<'a, T, L, R>`]new().(left: L, right: R) -> Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Union<'a, T, L, R>`] {
128 Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Union<'a, T, L, R>`] {
129 leftrust-analyzer cargo rangemap 1.7.1 operations/Union#left.: left.peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(),
130 rightrust-analyzer cargo rangemap 1.7.1 operations/Union#right.: right.peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(),
131 }
132 }
133 }
134
135 impl<'a, R, I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Unionrust-analyzer cargo rangemap 1.7.1 operations/Union#<'a, R, I>
136 where
137 R: RangeOrderrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder# + RangeMergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
138 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a R>,
139 {
140 type Itemrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Union<'a, R, I>`][Iterator]Item# = R;
141
142 fn nextrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Union<'a, R, I>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Union<'a, R, I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
143 // get start range
144 let mut range = match (self.leftrust-analyzer cargo rangemap 1.7.1 operations/Union#left..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().(), self.rightrust-analyzer cargo rangemap 1.7.1 operations/Union#right..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().()) {
145 // if there is only one possible range, pick that
146 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => self.leftrust-analyzer cargo rangemap 1.7.1 operations/Union#left..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
147 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_)) => self.rightrust-analyzer cargo rangemap 1.7.1 operations/Union#right..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
148 // when there are two ranges, pick the one with the earlier start
149 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(left), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right)) => {
150 if left.order_startrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder#order_start().(right).is_ltrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]is_lt().() {
151 self.leftrust-analyzer cargo rangemap 1.7.1 operations/Union#left..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
152 } else {
153 self.rightrust-analyzer cargo rangemap 1.7.1 operations/Union#right..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
154 }
155 }
156 // otherwise we are done
157 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
158 }
159 .clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
160
161 // peek into next value of iterator and merge if it is contiguous
162 let mut join = |iter: &mut Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<I>| {
163 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next) = iter.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
164 if range.mergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge#merge().(next) {
165 iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
166 return true;
167 }
168 }
169 false
170 };
171
172 // keep merging ranges as long as we can
173 loop {
174 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(join(&mut self.leftrust-analyzer cargo rangemap 1.7.1 operations/Union#left.) || join(&mut self.rightrust-analyzer cargo rangemap 1.7.1 operations/Union#right.)) {
175 break;
176 }
177 }
178
179 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(range)
180 }
181 }
182
183 impl<'a, R, I> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Unionrust-analyzer cargo rangemap 1.7.1 operations/Union#<'a, R, I>
184 where
185 R: RangeOrderrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder# + RangeMergerust-analyzer cargo rangemap 1.7.1 operations/RangeMerge# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
186 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a R>,
187 {
188 }
189
190 /// Iterator that produces the union of two iterators of sorted ranges.
191 pub struct Intersectionrust-analyzer cargo rangemap 1.7.1 operations/Intersection#<'a, T, L, R = L>
192 where
193 T: 'a,
194 L: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
195 R: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
196 {
197 leftrust-analyzer cargo rangemap 1.7.1 operations/Intersection#left.: Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<L>,
198 rightrust-analyzer cargo rangemap 1.7.1 operations/Intersection#right.: Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<R>,
199 }
200
201 impl<'a, T, L, R> Intersectionrust-analyzer cargo rangemap 1.7.1 operations/Intersection#<'a, T, L, R>
202 where
203 T: 'a,
204 L: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
205 R: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a T>,
206 {
207 /// Create new Intersection iterator.
208 ///
209 /// Requires that the two iterators produce sorted ranges.
210 pub fn newrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Intersection<'a, T, L, R>`]new().(left: L, right: R) -> Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Intersection<'a, T, L, R>`] {
211 Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Intersection<'a, T, L, R>`] {
212 leftrust-analyzer cargo rangemap 1.7.1 operations/Intersection#left.: left.peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(),
213 rightrust-analyzer cargo rangemap 1.7.1 operations/Intersection#right.: right.peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(),
214 }
215 }
216 }
217
218 impl<'a, R, I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Intersectionrust-analyzer cargo rangemap 1.7.1 operations/Intersection#<'a, R, I>
219 where
220 R: RangeOrderrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder# + RangeIntersectrust-analyzer cargo rangemap 1.7.1 operations/RangeIntersect# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
221 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a R>,
222 {
223 type Itemrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Intersection<'a, R, I>`][Iterator]Item# = R;
224
225 fn nextrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Intersection<'a, R, I>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo rangemap 1.7.1 operations/impl#[`Intersection<'a, R, I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
226 loop {
227 // if we don't have at least two ranges, there cannot be an intersection
228 let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(left), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right)) = (self.leftrust-analyzer cargo rangemap 1.7.1 operations/Intersection#left..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().(), self.rightrust-analyzer cargo rangemap 1.7.1 operations/Intersection#right..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().()) else {
229 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
230 };
231
232 let intersection = left.intersectrust-analyzer cargo rangemap 1.7.1 operations/RangeIntersect#intersect().(right);
233
234 // pop the range that ends earlier
235 if left.order_endrust-analyzer cargo rangemap 1.7.1 operations/RangeOrder#order_end().(right).is_ltrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impl#[Ordering]is_lt().() {
236 self.leftrust-analyzer cargo rangemap 1.7.1 operations/Intersection#left..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
237 } else {
238 self.rightrust-analyzer cargo rangemap 1.7.1 operations/Intersection#right..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
239 }
240
241 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(intersection) = intersection {
242 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(intersection);
243 }
244 }
245 }
246 }