MCPcopy Create free account
hub / github.com/davidblewett/rure-python / intersect

Method intersect

regex/regex-syntax/src/hir/interval.rs:92–127  ·  view source on GitHub ↗

Intersect this set with the given set, in place.

(&mut self, other: &IntervalSet<I>)

Source from the content-addressed store, hash-verified

90
91 /// Intersect this set with the given set, in place.
92 pub fn intersect(&mut self, other: &IntervalSet<I>) {
93 if self.ranges.is_empty() {
94 return;
95 }
96 if other.ranges.is_empty() {
97 self.ranges.clear();
98 return;
99 }
100
101 // There should be a way to do this in-place with constant memory,
102 // but I couldn't figure out a simple way to do it. So just append
103 // the intersection to the end of this range, and then drain it before
104 // we're done.
105 let drain_end = self.ranges.len();
106
107 let mut ita = (0..drain_end).into_iter();
108 let mut itb = (0..other.ranges.len()).into_iter();
109 let mut a = ita.next().unwrap();
110 let mut b = itb.next().unwrap();
111 loop {
112 if let Some(ab) = self.ranges[a].intersect(&other.ranges[b]) {
113 self.ranges.push(ab);
114 }
115 let (it, aorb) =
116 if self.ranges[a].upper() < other.ranges[b].upper() {
117 (&mut ita, &mut a)
118 } else {
119 (&mut itb, &mut b)
120 };
121 match it.next() {
122 Some(v) => *aorb = v,
123 None => break,
124 }
125 }
126 self.ranges.drain(..drain_end);
127 }
128
129 /// Subtract the given set from this set, in place.
130 pub fn difference(&mut self, other: &IntervalSet<I>) {

Callers 2

symmetric_differenceMethod · 0.45
symmetric_differenceMethod · 0.45

Calls 8

unwrapMethod · 0.80
upperMethod · 0.80
is_emptyMethod · 0.45
clearMethod · 0.45
lenMethod · 0.45
into_iterMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected