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

Method canonicalize

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

Converts this set into a canonical ordering.

(&mut self)

Source from the content-addressed store, hash-verified

271
272 /// Converts this set into a canonical ordering.
273 fn canonicalize(&mut self) {
274 if self.is_canonical() {
275 return;
276 }
277 self.ranges.sort();
278 assert!(!self.ranges.is_empty());
279
280 // Is there a way to do this in-place with constant memory? I couldn't
281 // figure out a way to do it. So just append the canonicalization to
282 // the end of this range, and then drain it before we're done.
283 let drain_end = self.ranges.len();
284 for oldi in 0..drain_end {
285 // If we've added at least one new range, then check if we can
286 // merge this range in the previously added range.
287 if self.ranges.len() > drain_end {
288 let (last, rest) = self.ranges.split_last_mut().unwrap();
289 if let Some(union) = last.union(&rest[oldi]) {
290 *last = union;
291 continue;
292 }
293 }
294 let range = self.ranges[oldi];
295 self.ranges.push(range);
296 }
297 self.ranges.drain(..drain_end);
298 }
299
300 /// Returns true if and only if this class is in a canonical ordering.
301 fn is_canonical(&self) -> bool {

Callers 4

newMethod · 0.45
pushMethod · 0.45
case_fold_simpleMethod · 0.45
unionMethod · 0.45

Calls 5

is_canonicalMethod · 0.80
unwrapMethod · 0.80
lenMethod · 0.45
unionMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected