8000 Return a slice of all vertices in the graph. · Issue #130 · dominikbraun/graph · GitHub
[go: up one dir, main page]

Skip to content

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

Open

Description

@filiperecharte

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()?

Activity

  1. dominikbraun commented on May 29, 2023

    @dominikbraun
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0