From 5fb4fe6522d5a909a6d52df5da6eabdf289d1592 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sun, 27 Jun 2021 15:56:42 -0700 Subject: [PATCH] Store an optional Node --- src/ucs.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ucs.rs b/src/ucs.rs index 2da0d71c8..4864c0b7d 100644 --- a/src/ucs.rs +++ b/src/ucs.rs @@ -9,8 +9,8 @@ use Action::*; struct GraphNode<'a> { distance: u64, action: Action, - lhs_next: &'a Node<'a>, - rhs_next: &'a Node<'a>, + lhs_next: Option<&'a Node<'a>>, + rhs_next: Option<&'a Node<'a>>, lhs_idx: Vec, rhs_idx: Vec, } @@ -46,16 +46,16 @@ fn next_graph_nodes<'a>(gn: &GraphNode<'a>) -> Vec> { if gn.lhs_next == gn.rhs_next { // Both nodes are equal, the happy case. - let new_lhs_next = next_node(gn.lhs_next, gn.lhs_idx.clone()); - let new_rhs_next = next_node(gn.rhs_next, gn.rhs_idx.clone()); + let new_lhs_next = next_node(gn.lhs_next.unwrap(), gn.lhs_idx.clone()); + let new_rhs_next = next_node(gn.rhs_next.unwrap(), gn.rhs_idx.clone()); match (new_lhs_next, new_rhs_next) { (Some((new_lhs_next, new_lhs_idx)), Some((new_rhs_next, new_rhs_idx))) => { let action = UnchangedNode; res.push(GraphNode { action, distance: gn.distance + action.cost(), - lhs_next: new_lhs_next, - rhs_next: new_rhs_next, + lhs_next: Some(new_lhs_next), + rhs_next: Some(new_rhs_next), lhs_idx: new_lhs_idx, rhs_idx: new_rhs_idx, }); @@ -64,8 +64,8 @@ fn next_graph_nodes<'a>(gn: &GraphNode<'a>) -> Vec> { } } - let new_lhs_next = next_node(gn.lhs_next, gn.lhs_idx.clone()); - let new_rhs_next = next_node(gn.rhs_next, gn.rhs_idx.clone()); + let new_lhs_next = next_node(gn.lhs_next.unwrap(), gn.lhs_idx.clone()); + let new_rhs_next = next_node(gn.rhs_next.unwrap(), gn.rhs_idx.clone()); // New atom on LHS. // TODO: step into list. if let Some((new_lhs_next, new_lhs_idx)) = &new_lhs_next { @@ -73,7 +73,7 @@ fn next_graph_nodes<'a>(gn: &GraphNode<'a>) -> Vec> { res.push(GraphNode { action, distance: gn.distance + action.cost(), - lhs_next: new_lhs_next, + lhs_next: Some(new_lhs_next), rhs_next: gn.rhs_next, lhs_idx: new_lhs_idx.to_vec(), rhs_idx: gn.rhs_idx.clone(), @@ -88,7 +88,7 @@ fn next_graph_nodes<'a>(gn: &GraphNode<'a>) -> Vec> { action, distance: gn.distance + action.cost(), lhs_next: gn.rhs_next, - rhs_next: new_rhs_next, + rhs_next: Some(new_rhs_next), lhs_idx: gn.lhs_idx.clone(), rhs_idx: new_rhs_idx.to_vec(), });