from __future__ import annotations from dataclasses import dataclass, field from typing import Any @dataclass class Node: id: str payload: dict[str, Any] edges: set[str] = field(default_factory=set) class HolographicDAG: def __init__(self) -> None: self.nodes: dict[str, Node] = {} def add(self, node_id: str, payload: dict[str, Any]) -> Node: node = self.nodes.setdefault(node_id, Node(node_id, payload)) return node def link(self, source: str, target: str) -> None: if source not in self.nodes or target not in self.nodes: raise KeyError("Both nodes must exist before linking") self.nodes[source].edges.add(target) def neighborhood(self, node_id: str) -> list[Node]: node = self.nodes[node_id] return [self.nodes[e] for e in node.edges]