diff --git a/libs/util/include/psemek/util/find_path.hpp b/libs/util/include/psemek/util/find_path.hpp index 798f1e69..4857f0b4 100644 --- a/libs/util/include/psemek/util/find_path.hpp +++ b/libs/util/include/psemek/util/find_path.hpp @@ -69,27 +69,31 @@ namespace psemek::util Node step() { - Node const node = *queue.begin(); + Node const node = std::move(*queue.begin()); queue.erase(queue.begin()); auto const node_cost = cost[node]; - node_neighbours(node, [&](Node const & neighbour, Cost const & edge_cost){ + node_neighbours(node, [&](Node neighbour, Cost const & edge_cost, EdgeId const & edge_id = 0){ Cost const new_cost = node_cost + edge_cost; - edge_callback(node, node_cost, neighbour, edge_cost); - auto it = cost.find(neighbour); if (it == cost.end() || new_cost < it->second) { + edge_callback(node, node_cost, neighbour, edge_cost, edge_id, true); + if (it != cost.end()) queue.erase(neighbour); cost[neighbour] = new_cost; priority[neighbour] = new_cost + heuristic(neighbour); previous[neighbour] = node; - queue.insert(neighbour); + queue.insert(std::move(neighbour)); + } + else + { + edge_callback(node, node_cost, neighbour, edge_cost, edge_id, false); } });