from __future__ import annotations

from collections.abc import Hashable
from typing import cast

import networkx as nx

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


def apply_triangles(rows_by_key: FeatureRowsByKey, graph: nx.Graph) -> None:
    for node_key, value in cast(dict[Hashable, int], nx.triangles(graph)).items():
        rows_by_key[node_key]["triangles"] = int(value)
