pub fn neighbor_sample(
graph: &Graph,
seeds: &[VertexId],
fan_out: &[usize],
seed: u64,
) -> IgraphResult<NeighborSampleResult>Expand description
Sample k-hop neighborhoods around seed vertices.
For each hop from 1 to fan_out.len(), samples at most fan_out[hop-1]
neighbors per frontier vertex. Sampling is uniform without replacement
when the number of neighbors exceeds the fan-out; otherwise all
neighbors are included.
§Parameters
graph— The input graph.seeds— Starting vertices (the “batch”).fan_out— Number of neighbors to sample at each hop. Length determines the number of hops.seed— PRNG seed for deterministic sampling.
§Returns
A NeighborSampleResult with layers and inter-layer edges.
§Examples
use rust_igraph::{Graph, neighbor_sample};
// Star graph: center 0 connected to 1,2,3,4
let g = Graph::from_edges(
&[(0,1),(0,2),(0,3),(0,4)], false, Some(5)
).unwrap();
// 1-hop sampling from vertex 0, fan_out=2
let result = neighbor_sample(&g, &[0], &[2], 42).unwrap();
assert_eq!(result.layers[0], vec![0]);
assert_eq!(result.layers[1].len(), 2); // sampled 2 of 4 neighbors
assert_eq!(result.edges[0].len(), 2);