We modify the Pearce-Kelly algorithm that maintains a topological ordering for a directed acyclic graph in order to allow cycles to be tolerated. Cycles make topological orderings moot, of course, however tolerating them is useful in practice. A user may mistakenly introduce a cyclic dependency in their project,, for example, and then subsequently fix their mistake. In these cases it is better to maintain the relevant data structures so that if and when the directed graph becomes acyclic again, a topological ordering can be instantly recovered. It turns out that adding this functionality costs us little, only small modifications and some attention to detail are needed.
翻译:我们修改了Pearce-Kelly算法,该算法用于维护有向无环图的拓扑排序,以允许对环进行容错。虽然环本身使得拓扑排序失去意义,但在实际应用中,对环进行容错是很有用的。例如,用户可能错误地在项目中引入了循环依赖,随后又纠正了这个错误。在这种情况下,最好维护相关的数据结构,以便当有向图再次变为无环图时,可以立即恢复拓扑排序。结果表明,添加这一功能代价很小,仅需进行少量修改并注意一些细节即可。