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.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/git/async/graph.py b/lib/git/async/graph.py
new file mode 100644
index 00000000..0c0a2137
--- /dev/null
+++ b/lib/git/async/graph.py
@@ -0,0 +1,36 @@
+"""Simplistic implementation of a graph"""
+
+class Node(object):
+ """A quick and dirty to the point implementation of a simple, and slow ascyclic graph.
+ Its not designed to support big graphs, and sports only the functionality
+ we need"""
+ __slots__ = ('in_nodes', 'out_nodes')
+
+
+class Graph(object):
+ """A simple graph implementation, keeping nodes and providing basic access and
+ editing functions"""
+ __slots__ = "nodes"
+
+ def __init__(self):
+ self.nodes = list()
+
+ def add_node(self, node):
+ """Add a new node to the graph"""
+ raise NotImplementedError()
+
+ def del_node(self, node):
+ """Delete a node from the graph"""
+ raise NotImplementedError()
+
+ def add_edge(self, u, v):
+ """Add an undirected edge between the given nodes u and v.
+ :raise ValueError: If the new edge would create a cycle"""
+ raise NotImplementedError()
+
+ def visit_input_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"""
+ raise NotImplementedError()
+