Skip to main content

distances_cutoff

Function distances_cutoff 

Source
pub fn distances_cutoff(
    graph: &Graph,
    source: VertexId,
    cutoff: Option<u32>,
) -> IgraphResult<Vec<Option<u32>>>
Expand description

Unweighted shortest-path lengths from source to every vertex, ignoring paths longer than cutoff.

Vertices beyond the cutoff (or in a different component) get None. cutoff == None behaves identically to super::distances::distances.

Counterpart of igraph_distances_cutoff(_, NULL, _, source, all, IGRAPH_OUT, cutoff).

§Examples

use rust_igraph::{Graph, distances_cutoff};

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_cutoff(&g, 0, Some(2)).unwrap();
assert_eq!(d, vec![Some(0), Some(1), Some(2), None, None]);

// No cutoff — same as `distances`.
let d_all = distances_cutoff(&g, 0, None).unwrap();
assert_eq!(d_all, vec![Some(0), Some(1), Some(2), Some(3), Some(4)]);