[core] dfsToProcess: stop branch visit when discovering a computed node

This commit is contained in:
Yann Lanthony 2018-07-18 16:21:44 +02:00
parent ab4e82aa88
commit 89dd55f43b

View file

@ -637,14 +637,24 @@ class Graph(BaseObject):
def dfsToProcess(self, startNodes=None):
"""
:param startNodes: list of starting nodes. Use all leaves if empty.
:return: visited nodes and edges that are not already computed (node.status != SUCCESS).
The order is defined by the visit and finishVertex event.
Return the full list of predecessor nodes to process in order to compute the given nodes.
Args:
startNodes: list of starting nodes. Use all leaves if empty.
Returns:
visited nodes and edges that are not already computed (node.status != SUCCESS).
The order is defined by the visit and finishVertex event.
"""
nodes = []
edges = []
visitor = Visitor()
def discoverVertex(vertex, graph):
if vertex.hasStatus(Status.SUCCESS):
# stop branch visit if discovering a node already computed
raise StopBranchVisit()
def finishVertex(vertex, graph):
chunksToProcess = []
for chunk in vertex.chunks:
@ -665,6 +675,7 @@ class Graph(BaseObject):
visitor.finishVertex = finishVertex
visitor.finishEdge = finishEdge
visitor.discoverVertex = discoverVertex
self.dfs(visitor=visitor, startNodes=startNodes)
return nodes, edges