From b80192ace6202c3d7d7d7cf7de3ec06d2d0888d6 Mon Sep 17 00:00:00 2001 From: Jon Brandenburg Date: Sun, 16 Jul 2023 22:05:45 -0400 Subject: [PATCH] added Vertices() to Graph interface --- directed.go | 4 ++++ graph.go | 4 ++++ undirected.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/directed.go b/directed.go index 95d67f52..8448066b 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 9376eb5f..f243b8be 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 37d320c6..0586bf25 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 {