Skip to main content

path_length_hist

Function path_length_hist 

Source
pub fn path_length_hist(
    graph: &Graph,
    directed: bool,
) -> IgraphResult<PathLengthHistResult>
Expand description

Compute a histogram of all shortest-path lengths.

For every vertex pair (u, v) the function determines the shortest-path length and adds it to the histogram. Self-loops and multi-edges are traversed by the BFS; self-pairs (distance 0) are not counted.

When directed is false (or the graph is undirected), both edge endpoints participate symmetrically and each unordered pair is counted once. When directed is true (on a directed graph), traversal follows out-edges and each ordered pair is counted.

§Examples

use rust_igraph::{Graph, path_length_hist};

// Undirected path 0-1-2.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let r = path_length_hist(&g, false).unwrap();
// Pairs at distance 1: {0,1}, {1,2} → 2
// Pairs at distance 2: {0,2}         → 1
assert_eq!(r.hist, vec![2.0, 1.0]);
assert_eq!(r.unconnected, 0.0);