diff --git a/directed.go b/directed.go index 95d67f5..8448066 100644 --- a/directed.go +++ b/directed.go @@ -62,6 +62,10 @@ func (d *directed[K, T]) Vertex(hash K) (T, error) { return vertex, err } +func (d *directed[K, T]) Vertices() ([]K, error) { + return d.store.ListVertices() +} + func (d *directed[K, T]) VertexWithProperties(hash K) (T, VertexProperties, error) { vertex, properties, err := d.store.Vertex(hash) if err != nil { diff --git a/graph.go b/graph.go index 9376eb5..f243b8b 100644 --- a/graph.go +++ b/graph.go @@ -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. + Vertices() ([]K, error) + // VertexWithProperties returns the vertex with the given hash along with // its properties or ErrVertexNotFound if it doesn't exist. VertexWithProperties(hash K) (T, VertexProperties, error) diff --git a/undirected.go b/undirected.go index 37d320c..0586bf2 100644 --- a/undirected.go +++ b/undirected.go @@ -43,6 +43,10 @@ func (u *undirected[K, T]) Vertex(hash K) (T, error) { return vertex, err } +func (u *undirected[K, T]) Vertices() ([]K, error) { + return u.store.ListVertices() +} + func (u *undirected[K, T]) VertexWithProperties(hash K) (T, VertexProperties, error) { vertex, prop, err := u.store.Vertex(hash) if err != nil {