A graph is represented by a dictionary: the key is a vertex, the value is a list of vertices which there is an edge to. [This model is attributed to Guido van Rossum]
An arrow is a non-empty sequence of vertices such that for each adjacent pair a, b, there is an edge from a to b. (Note that a sequence of one vertex meets this condition).
16: #line 36 "felix_stdcat2.ipk" 17: class cat_dgraph(category): 18: def __init__(self): 19: self.verticies = {} 20: 21: def add_vertex(self, vertex) 22: self.vertices[vertex]=[] 23: 24: def add_edge(self, v1, v2): 25: self.vertices[v1].append(v2) 26: 27: def is_object(self, object): 28: return self.verticies.has_key(object) 29: 30: def is_arrow(self,seq): 31: if len(seq) == 0: return 0 32: first = seq[0] 33: for second in seq[1:]: 34: if second not in self.vertices[first]: return 0 35: first = second 36: return 1 37: 38: def compose(self, a, b): return a + b 39: 40: de get_objects(self): return self.vertices 41: 42: class cat_graph(cat_dgraph): 43: def add_edge(self, v1, v2): 44: self.vertices[v1].append(v2) 45: self.vertices[v2].append(v1) 46: 47: def inverse(self, arrow): 48: return arrow[:].reverse() 49: 50: class cat_dagraph(cat_dgraph): 51: