Skip to main content

distances_all_with_mode

Function distances_all_with_mode 

Source
pub fn distances_all_with_mode(
    graph: &Graph,
    mode: DistancesMode,
) -> IgraphResult<Vec<Option<u32>>>
Expand description

All-pairs shortest distances with direction control.

For undirected graphs, mode is ignored.

§Examples

use rust_igraph::{Graph, distances_all_with_mode, DistancesMode};

// Directed: 0→1→2
let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let d = distances_all_with_mode(&g, DistancesMode::Out).unwrap();
assert_eq!(d[0 * 3 + 2], Some(2)); // 0→1→2
assert_eq!(d[2 * 3 + 0], None);    // 2 cannot reach 0
let d_in = distances_all_with_mode(&g, DistancesMode::In).unwrap();
assert_eq!(d_in[2 * 3 + 0], Some(2)); // follow incoming from 2