dominikbraun / graph

A library for creating generic graph data structures and modifying, analyzing, and visualizing them.
https://graph.dominikbraun.io
Apache License 2.0
1.8k stars 94 forks source link

feat: BFS with depth #120

Closed williamfzc closed 1 year ago

williamfzc commented 1 year ago

Thanks for your awesome project :)

This PR enhances current hook function for controlling BFS processing. Such as, stop BFS at a specfic depth level.

I am not pretty sure if there is a existed way to achieve this. But currently I have to walk the whole graph even I only need the first 3 layers.

dominikbraun commented 1 year ago

Thanks for your PR! That makes perfectly sense. I only have one suggestion: Because the DFS and DFSWithDepth implementations are the same, you could remove the DFS function body and replace it with a call to DFSWithDepth:

ignoreDepth := func(vertex K, _ int) {
    visit(vertex)
}

return DFSWithDepth(g, start, ignoreDepth)

... or something like that.

williamfzc commented 1 year ago

Thanks for your PR! That makes perfectly sense. I only have one suggestion: Because the DFS and DFSWithDepth implementations are the same, you could remove the DFS function body and replace it with a call to DFSWithDepth:

ignoreDepth := func(vertex K, _ int) {
    visit(vertex)
}

return DFSWithDepth(g, start, ignoreDepth)

... or something like that.

Sorry I have forgot leaving a comment for notification :) Already modified.

dominikbraun commented 1 year ago

This change has been released in graph v0.21.0.