diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2009-11-12 11:30:13 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2009-11-12 11:30:13 +0100 |
commit | 1b4d12cbd2ab6e6e586743df592648faa42fa26e (patch) | |
tree | 3712c032158bbca5d0f6cb75834c2490271f6698 /graph.py | |
parent | 6505d63fb9e53b28ff54b60954f63a9840959905 (diff) | |
download | logilab-common-1b4d12cbd2ab6e6e586743df592648faa42fa26e.tar.gz |
fix has_path returned value to include the destination node, else we get
an empty list which makes think there is no path (test added)
Diffstat (limited to 'graph.py')
-rw-r--r-- | graph.py | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -189,16 +189,16 @@ def has_path(graph_dict, fromnode, tonode, path=None): node has key associated to a list of nodes directly reachable from it. Return None if no path exists to go from `fromnode` to `tonode`, else the - first path found + first path found (as a list including the destination node at last) """ if path is None: path = [] elif fromnode in path: - return False + return None path.append(fromnode) for destnode in graph_dict[fromnode]: if destnode == tonode or has_path(graph_dict, destnode, tonode, path): - return path[1:] + return path[1:] + [tonode] path.pop() return None |