Skip to main content

degree_distribution

Function degree_distribution 

Source
pub fn degree_distribution(
    graph: &Graph,
    mode: DegreeMode,
) -> IgraphResult<Vec<u32>>
Expand description

Compute the degree distribution histogram of a graph.

Returns a Vec<u32> of length max_degree + 1 where entry i is the number of vertices with degree i.

  • mode: which degree to use (Out, In, or All). For undirected graphs, all modes are equivalent.
  • loops: if true, self-loops add 2 to the degree of their endpoint (matching igraph convention for undirected). If false, self-loops are still counted once per endpoint in directed mode.

§Examples

use rust_igraph::{Graph, degree_distribution};
use rust_igraph::DegreeMode;

// Triangle (K3): all vertices have degree 2.
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 hist = degree_distribution(&g, DegreeMode::All).unwrap();
// hist = [0, 0, 3] — zero vertices with degree 0 or 1, three with degree 2.
assert_eq!(hist, vec![0, 0, 3]);