Skip to content

Commit

Permalink
Improve dfa builder
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Mar 29, 2024
1 parent 64ee4e3 commit aba349d
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions irp/src/build_dfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rc<Expression>> {
Expand Down

0 comments on commit aba349d

Please sign in to comment.