relationship to the parent, the relationship is left as hard."""
if node not in self.nodes:
- self.nodes[node] = ({}, {})
+ self.nodes[node] = ({}, {}, node)
self.order.append(node)
if not parent:
return
if parent not in self.nodes:
- self.nodes[parent] = ({}, {})
+ self.nodes[parent] = ({}, {}, parent)
self.order.append(parent)
if parent in self.nodes[node][1]:
return node in self.nodes
def get(self, key, default=None):
- return self.nodes.get(key, default)
+ node_data = self.nodes.get(key, self)
+ if node_data is self:
+ return default
+ return node_data[2]
def all_nodes(self):
"""Return a list of all nodes in the graph"""
clone = digraph()
clone.nodes = {}
for k, v in self.nodes.iteritems():
- clone.nodes[k] = (v[0].copy(), v[1].copy())
+ clone.nodes[k] = (v[0].copy(), v[1].copy(), v[2])
clone.order = self.order[:]
return clone