Skip to main content

neighborhood_size_with_mode

Function neighborhood_size_with_mode 

Source
pub fn neighborhood_size_with_mode(
    graph: &Graph,
    order: i32,
    mode: NeighborhoodMode,
    mindist: i32,
) -> IgraphResult<Vec<u32>>
Expand description

Full mode-aware k-hop neighbourhood size with mindist filter.

For each source vertex v returns the number of vertices w such that mindist <= dist(v, w) <= order (or dist(v, w) >= mindist when order < 0, treating order as infinity). Direction follows mode on directed graphs and is ignored on undirected graphs.

mindist = 0 includes v itself; mindist = 1 excludes v but counts immediate neighbours; mindist = k excludes vertices reached in fewer than k hops.

Counterpart of igraph_neighborhood_size(graph, _, igraph_vss_all(), order, mode, mindist).

§Errors

§Examples

use rust_igraph::{Graph, neighborhood_size_with_mode, NeighborhoodMode};

// Directed star: 0->1, 0->2, 0->3.
let mut g = Graph::new(4, true).unwrap();
for v in [1, 2, 3] { g.add_edge(0, v).unwrap(); }

// Out: 0 reaches all; leaves only see themselves.
assert_eq!(
    neighborhood_size_with_mode(&g, -1, NeighborhoodMode::Out, 0).unwrap(),
    vec![4, 1, 1, 1]
);
// In: leaves can reach 0 via reversed edges (in-mode walks against arc).
assert_eq!(
    neighborhood_size_with_mode(&g, -1, NeighborhoodMode::In, 0).unwrap(),
    vec![1, 2, 2, 2]
);
// mindist=1 excludes the vertex itself.
assert_eq!(
    neighborhood_size_with_mode(&g, 1, NeighborhoodMode::All, 1).unwrap(),
    vec![3, 1, 1, 1]
);