Skip to main content

distances_from_with_mode

Function distances_from_with_mode 

Source
pub fn distances_from_with_mode(
    graph: &Graph,
    sources: &[VertexId],
    mode: DistancesFromMode,
) -> IgraphResult<Vec<Option<u32>>>
Expand description

Compute shortest-path distances from multiple sources with direction control.

For undirected graphs, mode is ignored.

§Errors

  • InvalidArgument if any source vertex is out of range.

§Examples

use rust_igraph::{Graph, distances_from_with_mode, DistancesFromMode};

// Directed: 0→1→2→3
let mut g = Graph::new(4, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
let d = distances_from_with_mode(&g, &[0, 3], DistancesFromMode::Out).unwrap();
let n = 4;
assert_eq!(d[3], Some(3));     // 0→1→2→3
assert_eq!(d[n], None);        // 3 cannot reach 0 (Out)
let d_in = distances_from_with_mode(&g, &[3], DistancesFromMode::In).unwrap();
assert_eq!(d_in[0], Some(3));  // follow incoming from 3 back to 0