From ea7fa6da930b16484bfe54d89e691537cd67509a Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sun, 27 Jun 2021 17:23:58 -0700 Subject: [PATCH] Terminate when we reach the end of the AST --- src/ucs.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ucs.rs b/src/ucs.rs index baaeb04e0..e92572988 100644 --- a/src/ucs.rs +++ b/src/ucs.rs @@ -23,6 +23,10 @@ impl<'a> GraphNode<'a> { fn rhs_next_node(&self) -> Option<&'a Node<'a>> { 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. @@ -118,6 +122,11 @@ fn find_route<'a>(start: GraphNode<'a>) { let gn = egn.gn; for new_gn in next_graph_nodes(&gn) { + if new_gn.is_end() { + println!("Success!"); + break; + } + heap.push(OrderedGraphNode { gn: new_gn }); }