diff options
Diffstat (limited to 'nfa/src/default/nfa.rs')
-rw-r--r-- | nfa/src/default/nfa.rs | 56 |
1 files changed, 7 insertions, 49 deletions
diff --git a/nfa/src/default/nfa.rs b/nfa/src/default/nfa.rs index 6b1e56f..d2fe88e 100644 --- a/nfa/src/default/nfa.rs +++ b/nfa/src/default/nfa.rs @@ -12,8 +12,10 @@ use crate::{ use core::fmt::{Debug, Display}; +use graph_macro::Graph; + /// Default NFA implementation. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Graph)] pub struct DefaultNFA<T: GraphLabel> { graph: DLGraph<T>, } @@ -31,51 +33,7 @@ impl<T: GraphLabel + Display> Default for DefaultNFA<T> { // I deliberately avoid using [`Deref`][std::ops::Deref] here, as I do // not want to dereference an NFA to a Graph. -impl<T: GraphLabel + Display> Graph for DefaultNFA<T> { - type Iter<'a> = <DLGraph<T> as Graph>::Iter<'a> where T: 'a; - - #[inline] - fn is_empty(&self) -> bool { - self.graph.is_empty() - } - - #[inline] - fn nodes_len(&self) -> usize { - self.graph.nodes_len() - } - - #[inline] - fn children_of(&self, node_id: usize) -> Result<Self::Iter<'_>, GError> { - self.graph.children_of(node_id) - } - - #[inline] - fn degree(&self, node_id: usize) -> Result<usize, GError> { - self.graph.degree(node_id) - } - - #[inline] - fn is_empty_node(&self, node_id: usize) -> Result<bool, GError> { - self.graph.is_empty_node(node_id) - } - - #[inline] - fn has_edge(&self, source: usize, target: usize) -> Result<bool, GError> { - self.graph.has_edge(source, target) - } - - #[inline] - fn print_viz(&self, filename: &str) -> Result<(), std::io::Error> { - self.graph.print_viz(filename) - } - - #[inline] - fn replace_by_builder(&mut self, _builder: impl Builder<Result = Self>) { - unimplemented!() - } -} - -impl<T: GraphLabel + Display> LabelGraph<T> for DefaultNFA<T> { +impl<T: GraphLabel> LabelGraph<T> for DefaultNFA<T> { type Iter<'a> = <DLGraph<T> as LabelGraph<T>>::Iter<'a> where T: 'a; type LabelIter<'a> = <DLGraph<T> as LabelGraph<T>>::LabelIter<'a> where T: 'a; @@ -119,14 +77,14 @@ impl<T: GraphLabel + Display> LabelGraph<T> for DefaultNFA<T> { } } -impl<T: GraphLabel + Display> LabelExtGraph<T> for DefaultNFA<T> { +impl<T: GraphLabel> LabelExtGraph<T> for DefaultNFA<T> { #[inline] fn extend(&mut self, edges: impl IntoIterator<Item = (T, usize)>) -> Result<usize, GError> { self.graph.extend(edges) } } -impl<T: GraphLabel + Display> Nfa<T> for DefaultNFA<T> { +impl<T: GraphLabel> Nfa<T> for DefaultNFA<T> { type FromRegex<S: GraphLabel + Display + Default> = DefaultNFA<S>; // Reminder: This is an adopted version of Thompson's @@ -484,7 +442,7 @@ impl<T: GraphLabel + Display> Nfa<T> for DefaultNFA<T> { } } -impl<T: GraphLabel + Display + Debug> Display for DefaultNFA<T> { +impl<T: GraphLabel> Display for DefaultNFA<T> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { Debug::fmt(self, f) } |