graphstore

package
v0.15.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package graph implements a graph data structure for the mesh network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStore

NewStore creates a new Graph storage instance.

Types

type GraphStore

type GraphStore struct {
	storage.MeshStorage
	// contains filtered or unexported fields
}

GraphStore implements the Store.

func (*GraphStore) AddEdge

func (g *GraphStore) AddEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error

AddEdge should add an edge between the vertices with the given source and target hashes.

If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex. If the edge already exists, ErrEdgeAlreadyExists should be returned.

func (*GraphStore) AddVertex

func (g *GraphStore) AddVertex(nodeID types.NodeID, node types.MeshNode, props graph.VertexProperties) error

AddVertex should add the given vertex with the given hash value and vertex properties to the graph. If the vertex already exists, it is up to you whether ErrVertexAlreadyExists or no error should be returned.

func (*GraphStore) Edge

func (g *GraphStore) Edge(sourceNode, targetNode types.NodeID) (graph.Edge[types.NodeID], error)

Edge should return the edge joining the vertices with the given hash values. It should exclusively look for an edge between the source and the target vertex, not vice versa. The graph implementation does this for undirected graphs itself.

Note that unlike Graph.Edge, this function is supposed to return an Edge[K], i.e. an edge that only contains the vertex hashes instead of the vertices themselves.

If the edge doesn't exist, ErrEdgeNotFound should be returned.

func (*GraphStore) ListEdges

func (g *GraphStore) ListEdges() ([]graph.Edge[types.NodeID], error)

ListEdges should return all edges in the graph in a slice.

func (*GraphStore) ListVertices

func (g *GraphStore) ListVertices() ([]types.NodeID, error)

ListVertices should return all vertices in the graph in a slice.

func (*GraphStore) RemoveEdge

func (g *GraphStore) RemoveEdge(sourceNode, targetNode types.NodeID) error

RemoveEdge should remove the edge between the vertices with the given source and target hashes.

If either vertex doesn't exist, it is up to you whether ErrVertexNotFound or no error should be returned. If the edge doesn't exist, it is up to you whether ErrEdgeNotFound or no error should be returned.

func (*GraphStore) RemoveVertex

func (g *GraphStore) RemoveVertex(nodeID types.NodeID) error

RemoveVertex should remove the vertex with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned. If the vertex has edges to other vertices, ErrVertexHasEdges should be returned.

func (*GraphStore) Subscribe added in v0.11.0

Subscribe subscribes to changes in the graph.

func (*GraphStore) UpdateEdge

func (g *GraphStore) UpdateEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error

UpdateEdge should update the edge between the given vertices with the data of the given Edge instance. If the edge doesn't exist, ErrEdgeNotFound should be returned.

func (*GraphStore) Vertex

func (g *GraphStore) Vertex(nodeID types.NodeID) (node types.MeshNode, props graph.VertexProperties, err error)

Vertex should return the vertex and vertex properties with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned.

func (*GraphStore) VertexCount

func (g *GraphStore) VertexCount() (int, error)

VertexCount should return the number of vertices in the graph. This should be equal to the length of the slice returned by ListVertices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL