diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-11 14:59:02 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-11 14:59:02 +0200 |
commit | f606937a7a21237c866efafcad33675e6539c103 (patch) | |
tree | 13ba7731de4798b2c9bfa24ccc893e4d8e5b8e8d /lib/git/async/graph.py | |
parent | 257a8a9441fca9a9bc384f673ba86ef5c3f1715d (diff) | |
parent | 18e3252a1f655f09093a4cffd5125342a8f94f3b (diff) | |
download | gitpython-f606937a7a21237c866efafcad33675e6539c103.tar.gz |
Merge branch 'taskdep' into async
Diffstat (limited to 'lib/git/async/graph.py')
-rw-r--r-- | lib/git/async/graph.py | 37 |
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 |