Skip to main content

density

Function density 

pub fn density(node_count: u64, edge_count: usize) -> f64
Expand description

Density of the behavioral coupling graph: 2·E / (V·(V−1)), in [0, 1].

V is the node count from count_coupling_nodes; E is the count of Fisher-significant coupling pairs (typically the length of the run_coupling result vector). The graph is undirected and each pair is counted once.

Returns 0.0 when V < 2 (a graph with fewer than two nodes has no possible edges). Returns 1.0 when E ≥ V·(V−1)/2 (every possible pair is coupled — fully connected).

Range guidance (empirical, repo-dependent):

  • < 0.01 — sparsely coupled, files change largely independently
  • 0.01 – 0.10 — typical for modular codebases
  • > 0.10 — tightly coupled; candidate for refactoring or a sign of a small/cohesive codebase