diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2021-09-22 00:10:20 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2022-01-14 00:15:51 -0800 |
commit | f84dbb27999bcac0c698d5c54b3bbffe6bdb1788 (patch) | |
tree | 40bf66506175120757236b59577dca7a552e74af | |
parent | 25ac84cb24a30f639dd4826cf5e23781db58cd94 (diff) |
Fix compilationa_star_module
-rw-r--r-- | src/a_star.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/a_star.rs b/src/a_star.rs index 99b61ae9a..7b3f5712f 100644 --- a/src/a_star.rs +++ b/src/a_star.rs @@ -109,11 +109,11 @@ pub fn shortest_path(start: Vertex) -> Vec<(Edge, Vertex)> { if !heap_full || !cost_too_high { predecessors - .insert(next.clone(), (distance_to_next, current.clone(), edge)); + .insert(next.clone(), (distance_to_next, current.clone(), *edge)); heap.push(OrdVertex { distance: distance_to_next, - current: next, + current: next.clone(), total_estimate, }); } @@ -162,6 +162,7 @@ pub fn shortest_path_greedy(start: Vertex) -> Vec<(Edge, Vertex)> { // usage. let mut predecessors: FxHashMap<Vertex, (u64, Vertex, Edge)> = FxHashMap::default(); + let mut neighbour_buf = [None, None, None, None, None, None, None, None, None, None]; let end; loop { match heap.pop() { @@ -175,17 +176,18 @@ pub fn shortest_path_greedy(start: Vertex) -> Vec<(Edge, Vertex)> { break; } - for (edge, next) in neighbours(¤t) { + neighbours(¤t, &mut neighbour_buf); + for (edge, next) in neighbour_buf.iter().flatten() { if predecessors.get(&next).is_none() { let distance_to_next = distance + edge.cost(); predecessors - .insert(next.clone(), (distance_to_next, current.clone(), edge)); + .insert(next.clone(), (distance_to_next, current.clone(), *edge)); let total_estimate = distance_to_next + estimated_distance_remaining(&next); heap.push(Reverse(OrdVertex { distance: distance_to_next, - current: next, + current: next.clone(), total_estimate, })); } |