graph icon indicating copy to clipboard operation
graph copied to clipboard

dfsTree does not preserve contexts of the original graph

Open jhrcek opened this issue 7 years ago • 4 comments

I've got an issue with dfsTree: The tree it outputs does not preserve contexts of the original graph.

Please check this minimalistic example from elm repl: The example creates graph with 2 nodes and 1 directed edge from 1 to 2. Then calls dfsTree starting from node 1.

Expected: the context.incoming of node 2 should contain node 1. Actual: the context.incoming of node 2 is empty (underlined).

Is this expected / correct behavior? In my use case I have to work around this, by looking up the missing info in the original graph, It would be nice if the tree itself contained the same contexts as the original graph.

example

jhrcek avatar May 13 '18 18:05 jhrcek

I don't think this is unique to dfsTree, e.g. all traversals have this wart. At the time of writing the code, I think I didn't want to do unnecessary graph lookups in the original graph. But I'd be happy to accept a PR that changes this, I guess.

sgraf812 avatar May 14 '18 16:05 sgraf812

See this: https://github.com/elm-community/graph/blob/c66f59ac9513f656649c59ef55202f70a63fb816/src/Graph.elm#L994

It would basically take an explicit set of visited nodes or a lookup in the original graph before every visit.

sgraf812 avatar May 14 '18 17:05 sgraf812

Just made you a collaborator. I'm not actually using this library, so you are probably in a much better position to (co-)maintain this library.

sgraf812 avatar May 15 '18 08:05 sgraf812

Ok. I'll look into this in some more details hopefully this week.

jhrcek avatar May 15 '18 10:05 jhrcek