from __future__ import annotations

from collections.abc import Hashable

import igraph  # type: ignore[import-untyped]

from graph.exploration.algorithms.in_memory.graph_features.common import FeatureRowsByKey


def apply_pagerank(
    rows_by_key: FeatureRowsByKey,
    graph: igraph.Graph,
    ordered_nodes: list[Hashable],
    *,
    directed: bool,
) -> None:
    values = graph.pagerank(directed=directed)
    for node_key, value in zip(ordered_nodes, values):
        rows_by_key[node_key]["pagerank"] = float(value)
