Skip to main content

neighborhood

Function neighborhood 

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

k-hop neighbourhood vertex list for every vertex (mode = All, mindist = 0).

For each vertex v returns the list of vertices w within order hops (inclusive), in BFS visitation order with v first. Negative order means infinity.

Counterpart of igraph_neighborhood(graph, _, igraph_vss_all(), order, IGRAPH_ALL, /*mindist=*/0).

§Errors

Same as neighborhood_with_mode.

§Examples

use rust_igraph::{Graph, neighborhood};

// Path P5: 0-1-2-3-4
let mut g = Graph::with_vertices(5);
for (u, v) in [(0, 1), (1, 2), (2, 3), (3, 4)] {
    g.add_edge(u, v).unwrap();
}
// Order 1: each vertex's 1-hop ball.
let n1 = neighborhood(&g, 1).unwrap();
assert_eq!(n1[0], vec![0, 1]);
assert_eq!(n1[2], vec![2, 1, 3]);