pruning
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, TypeVar
|
||||||
|
|
||||||
from .util import ensure_set
|
from .util import ensure_set
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .dag import DAG
|
from .dag import DAG
|
||||||
from .typing import dictset
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
@@ -32,12 +31,3 @@ def transitive_closure(graph: DAG[T], sub: T | Iterable[T], *, include_self: boo
|
|||||||
seen.update(sub)
|
seen.update(sub)
|
||||||
|
|
||||||
return seen
|
return seen
|
||||||
|
|
||||||
|
|
||||||
def slice_subgraph(graph: DAG, sub: Any) -> dictset:
|
|
||||||
closure = transitive_closure(graph, sub)
|
|
||||||
return {n: d & closure for n in closure if (d := set(graph[n]))}
|
|
||||||
|
|
||||||
|
|
||||||
def topological_sort(graph: DAG, *, reverse: bool = False) -> list:
|
|
||||||
return list(graph.keys())
|
|
||||||
|
|||||||
Reference in New Issue
Block a user