summaryrefslogtreecommitdiff
path: root/lib/git/async/graph.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git/async/graph.py')
-rw-r--r--lib/git/async/graph.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/git/async/graph.py b/lib/git/async/graph.py
index 6386cbaa..9ee0e891 100644
--- a/lib/git/async/graph.py
+++ b/lib/git/async/graph.py
@@ -25,14 +25,24 @@ class Graph(object):
def __init__(self):
self.nodes = list()
+
+ def __del__(self):
+ """Deletes bidericational dependencies"""
+ for node in self.nodes:
+ node.in_nodes = None
+ node.out_nodes = None
+ # END cleanup nodes
+
+ # otherwise the nodes would keep floating around
+
def add_node(self, node):
"""Add a new node to the graph
:return: the newly added node"""
self.nodes.append(node)
return node
- def del_node(self, node):
+ def remove_node(self, node):
"""Delete a node from the graph
:return: self"""
try:
@@ -46,6 +56,8 @@ class Graph(object):
del(outn.in_nodes[outn.in_nodes.index(node)])
for inn in node.in_nodes:
del(inn.out_nodes[inn.out_nodes.index(node)])
+ node.out_nodes = list()
+ node.in_nodes = list()
return self
def add_edge(self, u, v):
@@ -87,25 +99,26 @@ class Graph(object):
return self
- def visit_input_inclusive_depth_first(self, node, visitor=lambda n: True ):
- """Visit all input nodes of the given node, depth first, calling visitor
- for each node on our way. If the function returns False, the traversal
- will not go any deeper, but continue at the next branch
- It will return the actual input node in the end !"""
- nodes = node.in_nodes[:]
+ def input_inclusive_dfirst_reversed(self, node):
+ """Return all input nodes of the given node, depth first,
+ It will return the actual input node last, as it is required
+ like that by the pool"""
+ stack = [node]
seen = set()
# depth first
- while nodes:
- n = nodes.pop()
+ out = list()
+ while stack:
+ n = stack.pop()
if n in seen:
continue
seen.add(n)
+ out.append(n)
# only proceed in that direction if visitor is fine with it
- if visitor(n):
- nodes.extend(n.in_nodes)
+ stack.extend(n.in_nodes)
# END call visitor
# END while walking
- visitor(node)
+ out.reverse()
+ return out