refine comments

This commit is contained in:
geekan 2024-01-31 17:36:04 +08:00
parent 54388d0a87
commit ad1edf6092

View file

@ -11,7 +11,7 @@ from __future__ import annotations
class ActionGraph:
"""ActionGraph: 用于定义一个图,图中的节点是 ActionNode 实例,节点间的依赖关系是有向边。"""
"""ActionGraph: a directed graph to represent the dependency between actions."""
def __init__(self):
self.nodes = {}
@ -19,18 +19,11 @@ class ActionGraph:
self.execution_order = []
def add_node(self, node):
"""
添加一个节点到图中
:param node: ActionNode 实例
"""
"""Add a node to the graph"""
self.nodes[node.key] = node
def add_edge(self, from_node: "ActionNode", to_node: "ActionNode"):
"""
定义节点间的依赖关系
:param from_node: 节点标识
:param to_node: 节点标识
"""
"""Add an edge to the graph"""
if from_node.key not in self.edges:
self.edges[from_node.key] = []
self.edges[from_node.key].append(to_node.key)
@ -38,9 +31,7 @@ class ActionGraph:
to_node.add_prev(from_node)
def topological_sort(self):
"""
实现拓扑排序来确定执行顺序
"""
"""Topological sort the graph"""
visited = set()
stack = []