graph icon indicating copy to clipboard operation
graph copied to clipboard

BFSWithDepth not calculating depth correctly

Open amengcs opened this issue 2 years ago • 3 comments

The following tree has a single "root" and 5 children attached to that root. I expected the depth to be 2.

BFSWithDepth increments and passes "depth" to the visit function with values as high as 6.

For this case, it increments depth for the root and again for each child attached to the root as it loops through the adjancency graph.

resourceHash := func(r Resource) string { return r.Name() }

s.tree = graph.New(resourceHash, graph.Tree(), graph.Directed(), graph.PreventCycles())
s.tree.AddVertex(NullResource{"root"})
s.tree.AddVertex(NullResource{"A"})
s.tree.AddVertex(NullResource{"B"})
s.tree.AddVertex(NullResource{"C"})
s.tree.AddVertex(NullResource{"D"})
s.tree.AddVertex(NullResource{"E"})
s.tree.AddEdge("root", "A")
s.tree.AddEdge("root", "B")
s.tree.AddEdge("root", "C")
s.tree.AddEdge("root", "D")
s.tree.AddEdge("root", "E")

amengcs avatar Sep 17 '23 16:09 amengcs

Using version 0.23.0 (latest) It seems like it is returning "width + 1" instead of "depth".

amengcs avatar Sep 17 '23 16:09 amengcs

+1 to this 🤕

gcpreston avatar Dec 14 '23 02:12 gcpreston

First of all, sorry for the late response – I'm going to review #153 today.

dominikbraun avatar Feb 28 '24 09:02 dominikbraun