diff --git a/lib/graph/graph_algorithms.hpp b/lib/graph/graph_algorithms.hpp index 3042a9d..e928d1c 100644 --- a/lib/graph/graph_algorithms.hpp +++ b/lib/graph/graph_algorithms.hpp @@ -54,15 +54,16 @@ dijkstra_shortest_path_to(const Graph& graph, const V& dest, std::function distanceCompute) { - std::unordered_map dist; /// @todo into std::priority_queue> + std::unordered_map dist; std::unordered_map prev; dist.emplace(source, W()); - std::unordered_set q; - q.insert(source); - const std::vector& s_n = graph.neighboursOf(source); - std::copy(s_n.begin(), s_n.end(), std::inserter(q, q.end())); + for (const auto& v : graph.neighboursOf(source)) { + q.insert(v); + dist[v] = distanceCompute(source, v); + prev[v] = source; + } while (!q.empty()) { const V& u = closestNode(q, dist);