diff options
Diffstat (limited to 'nfa/src/default/nfa.rs')
-rw-r--r-- | nfa/src/default/nfa.rs | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/nfa/src/default/nfa.rs b/nfa/src/default/nfa.rs index d2fe88e..e38a1a9 100644 --- a/nfa/src/default/nfa.rs +++ b/nfa/src/default/nfa.rs @@ -20,7 +20,7 @@ pub struct DefaultNFA<T: GraphLabel> { graph: DLGraph<T>, } -impl<T: GraphLabel + Display> Default for DefaultNFA<T> { +impl<T: GraphLabel> Default for DefaultNFA<T> { fn default() -> Self { Self { graph: Default::default(), @@ -85,10 +85,9 @@ impl<T: GraphLabel> LabelExtGraph<T> for DefaultNFA<T> { } impl<T: GraphLabel> Nfa<T> for DefaultNFA<T> { - type FromRegex<S: GraphLabel + Display + Default> = DefaultNFA<S>; + type FromRegex<S: GraphLabel + Default> = DefaultNFA<S>; - // Reminder: This is an adopted version of Thompson's - // construction. + // NOTE: This is an adopted version of Thompson's construction. fn to_nfa( regexps: &[impl Regex<RegexType<T>>], sub_pred: impl Fn(T) -> Result<SoC<T>, Error>, @@ -107,10 +106,6 @@ impl<T: GraphLabel> Nfa<T> for DefaultNFA<T> { builder.add_vertices(nfa_len); - // for _ in 0..nfa_len { - // builder.add_vertex(); - // } - let default = LabelType::new(DOption(default), total_regexps_len, false); // add a default edge @@ -122,7 +117,7 @@ impl<T: GraphLabel> Nfa<T> for DefaultNFA<T> { result.push(0); for regexp in regexps.iter().take(regexps.len() - 1) { - result.push(result.last().unwrap() + regexp.nodes_len() * 2); + result.push(*result.last().unwrap() + regexp.nodes_len() * 2); } result @@ -137,14 +132,14 @@ impl<T: GraphLabel> Nfa<T> for DefaultNFA<T> { } ); - /// Get offset from `accumulators` without checking bounds. - macro_rules! get_offset_unsafe ( - ($num:expr) => { - { unsafe { *accumulators.get_unchecked($num) } } - } - ); + // /// Get offset from `accumulators` without checking bounds. + // macro_rules! get_offset_unsafe ( + // ($num:expr) => { + // { unsafe { *accumulators.get_unchecked($num) } } + // } + // ); - for (index, regex) in regexps.iter().enumerate() { + for (regex, offset) in regexps.iter().zip(accumulators.iter().copied()) { let root = if let Some(root) = regex.root() { root } else { @@ -155,11 +150,6 @@ impl<T: GraphLabel> Nfa<T> for DefaultNFA<T> { let regex_len = regex.nodes_len(); - // It is safe here to call `get_offset_unsafe`, as `index` - // is guaranteed to be strictly less than the length of - // `accumulators` by an assertion above. - let offset = get_offset_unsafe!(index); - let mut stack: Vec<usize> = Vec::with_capacity(regex_len); stack.push(root); |