Source code for elasticai.creator.graph.graph

from abc import abstractmethod
from collections.abc import Hashable, Iterator, Mapping, Set
from typing import Protocol, Self, TypeVar

T = TypeVar("T", bound=Hashable)


[docs] class Graph(Protocol[T]): @property @abstractmethod def nodes(self) -> Set[T]: ...
[docs] @abstractmethod def iter_edges(self) -> Iterator[tuple[T, T]]: ...
[docs] @abstractmethod def add_node(self, node: T) -> Self: ...
[docs] @abstractmethod def add_edge(self, src: T, dst: T) -> Self: ...
@property @abstractmethod def predecessors(self) -> Mapping[T, set[T]]: ... @property @abstractmethod def successors(self) -> Mapping[T, set[T]]: ...
[docs] @abstractmethod def new(self) -> "Graph[T]": ...
[docs] @abstractmethod def copy(self) -> "Graph[T]": ...