Terminate when we reach the end of the AST

pull/25/head
Wilfred Hughes 2021-06-27 17:23:58 +07:00
parent 1669405e43
commit ea7fa6da93
1 changed files with 9 additions and 0 deletions

@ -23,6 +23,10 @@ impl<'a> GraphNode<'a> {
fn rhs_next_node(&self) -> Option<&'a Node<'a>> { fn rhs_next_node(&self) -> Option<&'a Node<'a>> {
self.rhs_next.as_ref().map(|(n, _)| *n) self.rhs_next.as_ref().map(|(n, _)| *n)
} }
fn is_end(&self) -> bool {
self.lhs_next.is_none() && self.rhs_next.is_none()
}
} }
// Rust requires that PartialEq, PartialOrd and Ord agree. // Rust requires that PartialEq, PartialOrd and Ord agree.
@ -118,6 +122,11 @@ fn find_route<'a>(start: GraphNode<'a>) {
let gn = egn.gn; let gn = egn.gn;
for new_gn in next_graph_nodes(&gn) { for new_gn in next_graph_nodes(&gn) {
if new_gn.is_end() {
println!("Success!");
break;
}
heap.push(OrderedGraphNode { gn: new_gn }); heap.push(OrderedGraphNode { gn: new_gn });
} }