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

Return a slice of all vertices in the graph. #130

Open
filiperecharte opened this issue May 29, 2023 · 1 comment
Open

Return a slice of all vertices in the graph. #130

filiperecharte opened this issue May 29, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@filiperecharte
Copy link

filiperecharte commented May 29, 2023

I want to iterate through the vertices of a graph, but the graph type does not have that method, and visiting each one using DFS does not work since, during runtime, I have vertices with no edges connected.
Even if I had, I could only iterate through edges and then access Vertices, using the method Edges() of the graph, but that will not make me go through a vertice only once. Is there any way I can get a slice of them like the method that exists in type Store ListVertices()?

@dominikbraun dominikbraun added the enhancement New feature or request label May 29, 2023
@dominikbraun
Copy link
Owner

Hi! You can iterate over all vertices like so:

adjacencyMap, _ := g.AdjacencyMap()

for vertex := range adjacencyMap {
    // Do something with vertex.
}

The adjacency map is guaranteed to contain all vertices in the graph. If you want them as a slice, you can build it yourself – but it is likely that there will be a Vertices method in the future.

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

No branches or pull requests

2 participants