From aba349d2522e65defe886544aab9d9b519c67b49 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Fri, 29 Mar 2024 11:59:54 +0000 Subject: [PATCH] Improve dfa builder Signed-off-by: Sean Young --- irp/src/build_dfa.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/irp/src/build_dfa.rs b/irp/src/build_dfa.rs index 8ac3bca1..9fbb3271 100644 --- a/irp/src/build_dfa.rs +++ b/irp/src/build_dfa.rs @@ -116,24 +116,30 @@ impl<'a> Builder<'a> { length: length.clone(), }; + let actions = self.path_actions(path, flash, length); + if let Some(to) = self.edges.get(&dfa_edge) { - self.nfa_to_dfa.insert(nfa_to, *to); - // FIXME: check path matches - } else { - let to = if let Some(vert_no) = self.nfa_to_dfa.get(&nfa_to) { - *vert_no - } else { - self.add_vertex() - }; + if self.verts[from] + .edges + .iter() + .any(|edge| edge.dest == *to && edge.actions == actions) + { + self.nfa_to_dfa.insert(nfa_to, *to); + return; + } + } - self.nfa_to_dfa.insert(nfa_to, to); + let to = if let Some(vert_no) = self.nfa_to_dfa.get(&nfa_to) { + *vert_no + } else { + self.add_vertex() + }; - self.edges.insert(dfa_edge, to); + self.nfa_to_dfa.insert(nfa_to, to); - let actions = self.path_actions(path, flash, length); + self.edges.insert(dfa_edge, to); - self.verts[from].edges.push(Edge { dest: to, actions }); - } + self.verts[from].edges.push(Edge { dest: to, actions }); } fn path_length(&self, path: &[Path]) -> Option> {