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

added Vertices() to Graph interface #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonbrandenburg
Copy link
Contributor

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:

type Vertex[T any] struct {
    Value T
    Properties VertexProperties
}

Then this would enable the ability to create a Vertices() like this:

func Vertices() ([]Vertex[T], error)

@dominikbraun dominikbraun self-requested a review July 17, 2023 05:43
Copy link
Owner

@dominikbraun dominikbraun left a 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.

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]?

Copy link
Owner

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]?

@alexnguyenatwork Yes. There is no Vertex type (let alone Vertice).

@AkashKumar7902
Copy link

AkashKumar7902 commented Feb 9, 2024

Hey @dominikbraun,
can this be merged ? I want this method more than ever.

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

Successfully merging this pull request may close these issues.

None yet

4 participants