pub fn local_scan_k(
graph: &Graph,
k: u32,
weights: Option<&[f64]>,
) -> IgraphResult<Vec<f64>>Expand description
For each vertex, count edges within its closed k-neighborhood.
The closed k-neighborhood of vertex v is the set of all vertices
reachable from v in at most k hops. This function counts all
edges that have both endpoints in that set.
For undirected graphs, each edge is counted once.
For directed graphs with IGRAPH_ALL mode equivalent, edges are
counted once per direction observed.
k: radius of the neighborhood (must be ≥ 0). k=0 counts only
self-loops at each vertex. k=1 is equivalent to local_scan_1.
weights: optional edge weights (length must equal ecount()).
When provided, sums edge weights instead of counting edges.
Returns a vector of length vcount().
§Examples
use rust_igraph::{Graph, local_scan_k};
// Triangle: k=1 neighborhood of each vertex is the whole graph.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let s = local_scan_k(&g, 1, None).unwrap();
assert!((s[0] - 3.0).abs() < 1e-10);
// Path 0-1-2-3-4 with k=2:
// N_2[0] = {0,1,2}, edges {0-1,1-2} → 2
// N_2[2] = {0,1,2,3,4}, all 4 edges → 4
let mut g = Graph::with_vertices(5);
for i in 0..4u32 { g.add_edge(i, i+1).unwrap(); }
let s = local_scan_k(&g, 2, None).unwrap();
assert!((s[0] - 2.0).abs() < 1e-10);
assert!((s[2] - 4.0).abs() < 1e-10);