Initial release #1
+1
-14
@@ -35,14 +35,7 @@ pub fn dijkstra(graph: &Graph, source: Vertex) -> (Vec<Option<u32>>, Vec<Option<
|
|||||||
distance: 0,
|
distance: 0,
|
||||||
});
|
});
|
||||||
while let Some(v) = heap.pop() {
|
while let Some(v) = heap.pop() {
|
||||||
// TODO: Simplify with a neighbor iterator.
|
for neighbor in graph.neighbors(v.vertex) {
|
||||||
// Finds the first neighbor of v.
|
|
||||||
let Some(mut incidence) = graph.incidence_headers[v.vertex.0].first_incidence else {
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
loop {
|
|
||||||
// Processes one neighbor of v.
|
|
||||||
let neighbor = graph.incidence_vertices[incidence.0];
|
|
||||||
// TODO: Add a way to provide custom edge weights for Dijkstra's algorithm.
|
// TODO: Add a way to provide custom edge weights for Dijkstra's algorithm.
|
||||||
let edge_weight = 1;
|
let edge_weight = 1;
|
||||||
let new_distance = distances[v.vertex.0].unwrap() + edge_weight;
|
let new_distance = distances[v.vertex.0].unwrap() + edge_weight;
|
||||||
@@ -58,12 +51,6 @@ pub fn dijkstra(graph: &Graph, source: Vertex) -> (Vec<Option<u32>>, Vec<Option<
|
|||||||
distance: new_distance,
|
distance: new_distance,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds next neighbor of v.
|
|
||||||
let Some(next) = graph.next_incidences[incidence.0] else {
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
incidence = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(distances, predecessors)
|
(distances, predecessors)
|
||||||
|
|||||||
Reference in New Issue
Block a user