pub fn distances_from(
graph: &Graph,
sources: &[VertexId],
) -> IgraphResult<Vec<Option<u32>>>Expand description
Compute shortest-path distances from multiple sources to all vertices.
Returns a flat Vec<Option<u32>> of length sources.len() * n in
row-major order, where result[i * n + j] is the shortest-path
distance from sources[i] to vertex j. None means unreachable.
For directed graphs, follows outgoing edges by default. Use
distances_from_with_mode for direction control.
§Errors
InvalidArgumentif any source vertex is out of range.
§Examples
use rust_igraph::{Graph, distances_from};
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
let d = distances_from(&g, &[0, 2]).unwrap();
let n = 5;
// Row 0 (from vertex 0):
assert_eq!(d[0], Some(0));
assert_eq!(d[4], Some(4));
// Row 1 (from vertex 2):
assert_eq!(d[n + 2], Some(0));
assert_eq!(d[n], Some(2)); // vertex 2 to vertex 0