summaryrefslogtreecommitdiff
path: root/lib/git/async/graph.py
blob: 0c0a2137d9a54f4177843a3c5ca300c3c1d61ed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()