Skip to content

added Vertices() to Graph interface - #149

Open
jonbrandenburg wants to merge 1 commit into
dominikbraun:mainfrom
jonbrandenburg:vertices-function-for-graph-interface
Open

jonbrandenburg wants to merge 1 commit into
dominikbraun:mainfrom
jonbrandenburg:vertices-function-for-graph-interface

Conversation

@jonbrandenburg

Copy link
Copy Markdown
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

@dominikbraun dominikbraun left a comment

Copy link
Copy Markdown
Owner

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)
}

Comment thread graph.go
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.

Copy link
Copy Markdown

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
Copy Markdown
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

AkashKumar7902 commented Feb 9, 2024

Copy link
Copy Markdown

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

@trstruth

Copy link
Copy Markdown

@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

@zhulik

zhulik commented May 1, 2025

Copy link
Copy Markdown

Hi @dominikbraun can we have this one merged? Thanks!

@BolajiOlajide

Copy link
Copy Markdown

Hey @dominikbraun

Gentle nudge on this. It'll be nice to get this merged.

stryan added a commit to stryan/graph that referenced this pull request May 28, 2026
Merges dominikbraun#149 , albeit with
`ListVertices`, to save `Vertices` for a future Vertex type.
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.

7 participants