pub fn distances(
graph: &Graph,
source: VertexId,
) -> IgraphResult<Vec<Option<u32>>>Expand description
Unweighted shortest-path lengths from source to every vertex.
result[v] == Some(d) if v is reachable from source in d
edges (d == 0 for the source itself); None if v is in a
different connected component (undirected) or has no out-path from
source (directed).
Counterpart of igraph_distances(_, NULL, _, single_from, all_to, IGRAPH_OUT). For directed graphs traversal follows out-edges
(matching IGRAPH_OUT); for undirected graphs every edge counts
both ways.
ยงExamples
use rust_igraph::{Graph, distances};
// Undirected path 0-1-2-3, plus an isolated vertex 4.
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();
let d = distances(&g, 0).unwrap();
assert_eq!(d, vec![Some(0), Some(1), Some(2), Some(3), None]);