den-run-ai / yapgvb

Automatically exported from code.google.com/p/yapgvb
0 stars 0 forks source link

Add node to graph not operating as per docs #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In Digraph.add_node, it says "If a node of this name exists already, it 
will be returned and no new node will be created." . However, no check of 
this kind is made and new nodes are always created. Therefore one needs to 
keep an external dictionary to work around when one needs this 
functionality.

Original issue reported on code.google.com by pythonol...@octave.demon.co.uk on 6 May 2009 at 8:33

GoogleCodeExporter commented 9 years ago
Here's a workaround implementation:

###############################################################################

class Digraph(yapgvb.Digraph):
    def __init__(self, *args, **kwargs):
        yapgvb.Digraph.__init__(self, *args, **kwargs)
        self._node_dict = {}

    def add_node(self, **kwargs):
        name = kwargs.get('name', None)
        if name:
            node = self._node_dict.get(name, None)
            if node:
                return node
        node = yapgvb.Digraph.add_node(self, **kwargs)
        name = node.name
        self._node_dict[name] = node
        return node

###############################################################################

Original comment by pythonol...@octave.demon.co.uk on 6 May 2009 at 9:28

GoogleCodeExporter commented 9 years ago
This workaround works for me. It would be great when it is added to the main 
release. 

Original comment by holke.vi...@gmail.com on 24 Jan 2011 at 8:29