From d9c8ca8f64839128d2fd3ae04a19ba73c1125b7b Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 24 Aug 2015 12:35:47 +0200 Subject: monkey.graph.graphviz: use id() to reference nodes --- monkey/graph.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/monkey/graph.py b/monkey/graph.py index cbe44f7..20a8a98 100644 --- a/monkey/graph.py +++ b/monkey/graph.py @@ -47,10 +47,10 @@ class Node(object): def graphviz(nodes, label=str, pos=None, node_attr=None, edge_attr=None): # Generate node descriptions. node_str = '' - node_id = {} + gv_nodes = {} for node in nodes: - node_id[node] = len(node_id) - node_str += '\t{} [label="{}"'.format(node_id[node], label(node).replace('"', '\\"')) + gv_nodes[id(node)] = len(gv_nodes) + node_str += '\t{} [label="{}"'.format(gv_nodes[id(node)], label(node).replace('"', '\\"')) if pos: node_str += ', ' + 'pos="{},{}"'.format(*pos(node)) if node_attr: @@ -60,9 +60,9 @@ def graphviz(nodes, label=str, pos=None, node_attr=None, edge_attr=None): # Generate edge descriptions (breadth-first). edge_str = '' for node in nodes: - a = node_id[node] + a = gv_nodes[id(node)] for child in node.eout: - b = node_id[child] + b = gv_nodes[id(child)] edge_str += '\t{} -> {}'.format(a, b) if edge_attr: edge_str += ' [' + edge_attr(node, child) + ']' -- cgit v1.2.1