-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
added Vertices() to Graph interface #149
base: main
Are you sure you want to change the base?
added Vertices() to Graph interface #149
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Yes, a Vertex
type would be more convenient for the use case where all full vertex instances should be retrieved, but that's a too large of a change right now. If one really needs this functionality, this should do the job:
for hash, _ := range g.AdjacencyMap() {
vertex, properties, _ := g.VertexWithProperties(hash)
}
@@ -88,6 +88,10 @@ type Graph[K comparable, T any] interface { | |||
// doesn't exist. | |||
Vertex(hash K) (T, error) | |||
|
|||
// Vertices returns a slice of all vertices in the graph. These vertices are of type | |||
// Vertice[K] and hence will contain the vertex hashes, not the vertex values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this read K
rather than Vertice[K]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this read
K
rather thanVertice[K]
?
@alexnguyenatwork Yes. There is no Vertex
type (let alone Vertice
).
Hey @dominikbraun, |
@dominikbraun another friendly ping wondering if it's possible to merge this yet? I'm able to get the vertices by doing something like adjMap, err := g.graph.AdjacencyMap()
if err != nil {
return nil, err
}
vertices := make(K, 0, len(adjMap))
i := 0
for hash := range adjMap {
vertex, err := g.graph.Vertex(hash)
if err != nil {
return nil, err
}
vertices[i] = vertex
i++
} but it'd be nice to get this with a function public in the API |
This is a proposed solution to #130. Alternatively I could see renaming this to ListVertices() and adding a Vertices() that returns the actual vertices, though that might be more challenging since there is currently no Vertex type so conveying the VertexProperties would not happen as it does with Edges() and their corresponding EdgeProperties.
Building on the earlier idea, it might be beneficial to introduce a Vertex type:
Then this would enable the ability to create a Vertices() like this: