Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to do BFS on a graph of City #182

Open
riberr opened this issue Oct 22, 2024 · 1 comment
Open

Not possible to do BFS on a graph of City #182

riberr opened this issue Oct 22, 2024 · 1 comment

Comments

@riberr
Copy link

riberr commented Oct 22, 2024

Hi,

This example is not possible:

type City struct {
    Name string
}

cityHash := func(c City) string {
    return c.Name
}

g := graph.New(cityHash)

//...

f := func(c City) bool {
    return c.Name == "London"
}

graph.DFS(g, "Paris", f)

Warning: "Cannot use 'f' (type func(c City) bool) as the type func(string) bool"

Am I missing something? Because the docs says this should be possible.

@GeorgeMac
Copy link

GeorgeMac commented Nov 12, 2024

@riberr The DFS visit function takes K (the generic type for the hash, as opposed to the contained vertex type).
So you would need to do the following to start at Paris and descend until London:

f := func(name string) bool {
    return name == "London"
}

graph.DFS(g, "Paris", f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants