From afaf1613445728ef65339f1a04ad61d035d4fd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 31 Jul 2026 10:23:47 +0200 Subject: [PATCH] Rename 'weight' parameter in Dijkstra's algorithm to 'weights' --- src/algorithms.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/algorithms.rs b/src/algorithms.rs index e04b4ff..a1e0088 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -64,7 +64,7 @@ pub struct DijkstraResult { /// [Dijkstra's algorithm] with custom edge weights, returns minimum distances and predecessors. /// /// Calculates the shortest paths from `source` to all vertices in `graph` with edge weights given -/// by `weight` function. Returns the distances from `source` to each vertex, and the predecessors +/// by `weights` function. Returns the distances from `source` to each vertex, and the predecessors /// of each vertex on some shortest path from `source` to that vertex. Returns `None` for any vertex /// not connected to `source`. /// @@ -91,13 +91,13 @@ pub struct DijkstraResult { /// ``` /// /// [Dijkstra's algorithm]: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm -pub fn dijkstra(graph: &G, source: G::Vertex, weight: W) -> DijkstraResult +pub fn dijkstra(graph: &G, source: G::Vertex, weights: W) -> DijkstraResult where G: GraphTopology, W: Fn(G::Edge) -> u32, { let mut predecessors = graph.vertex_map(None); - let distances = dijkstra_impl(graph, source, weight, |adjacent, predecessor| { + let distances = dijkstra_impl(graph, source, weights, |adjacent, predecessor| { predecessors[adjacent] = Some(predecessor); }); DijkstraResult { @@ -109,7 +109,7 @@ where /// [Dijkstra's algorithm] with custom edge weights, returns minimum distances. /// /// Calculates the shortest paths from `source` to all vertices in `graph` with edge weights given -/// by `weight` function. Returns the distances from `source` to each vertex. Returns `None` for any +/// by `weights` function. Returns the distances from `source` to each vertex. Returns `None` for any /// vertex not connected to `source`. /// /// # Panics @@ -137,13 +137,13 @@ where pub fn dijkstra_distances( graph: &G, source: G::Vertex, - weight: W, + weights: W, ) -> EntityMap> where G: GraphTopology, W: Fn(G::Edge) -> u32, { - dijkstra_impl(graph, source, weight, |_, _| {}) + dijkstra_impl(graph, source, weights, |_, _| {}) } /// [Dijkstra's algorithm] with unit edge weights, returns minimum distances and predecessors. @@ -223,7 +223,7 @@ where fn dijkstra_impl( graph: &G, source: G::Vertex, - weight: W, + weights: W, mut on_relax: F, ) -> EntityMap> where @@ -242,7 +242,7 @@ where while let Some(v) = heap.pop() { for incidence in graph.incidences(v.vertex) { - let new_distance = distances[v.vertex].unwrap() + weight(incidence.1); + let new_distance = distances[v.vertex].unwrap() + weights(incidence.1); if match distances[incidence.0] { None => true, Some(old_distance) if old_distance > new_distance => true,