Skip to main content

pagerank

Function pagerank 

Source
pub fn pagerank<N: Clone + Ord>(
    nodes: &[N],
    edges: &[(N, N, Weight)],
    damping: f64,
    max_iterations: usize,
) -> Vec<(N, f64)>
Expand description

PageRank over an abstract undirected, unweighted graph.

Edges are treated as UNDIRECTED — each edge contributes an out-link in both directions. damping is the classic teleport factor (0.85 at the call site); max_iterations caps the sweeps. Rank mass from dangling nodes (degree 0) is redistributed uniformly each iteration, so the returned scores always sum to 1.0. Every score is strictly positive (≥ the teleport floor (1−damping)/n), so an isolated node receives exactly that boundary share.

Output: one (node, score) pair per distinct node, ordered by node ascending. Deterministic: fixed uniform start, ascending sweep order, fixed iteration cap. Identical input always produces identical output.