Documentation ¶
Overview ¶
Package graph implements a graph data structure for the mesh network.
Index ¶
- func NewStore(st storage.MeshStorage) storage.GraphStore
- type GraphStore
- func (g *GraphStore) AddEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error
- func (g *GraphStore) AddVertex(nodeID types.NodeID, node types.MeshNode, props graph.VertexProperties) error
- func (g *GraphStore) Edge(sourceNode, targetNode types.NodeID) (graph.Edge[types.NodeID], error)
- func (g *GraphStore) ListEdges() ([]graph.Edge[types.NodeID], error)
- func (g *GraphStore) ListVertices() ([]types.NodeID, error)
- func (g *GraphStore) RemoveEdge(sourceNode, targetNode types.NodeID) error
- func (g *GraphStore) RemoveVertex(nodeID types.NodeID) error
- func (g *GraphStore) Subscribe(ctx context.Context, fn storage.PeerSubscribeFunc) (context.CancelFunc, error)
- func (g *GraphStore) UpdateEdge(sourceNode, targetNode types.NodeID, edge graph.Edge[types.NodeID]) error
- func (g *GraphStore) Vertex(nodeID types.NodeID) (node types.MeshNode, props graph.VertexProperties, err error)
- func (g *GraphStore) VertexCount() (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStore ¶
func NewStore(st storage.MeshStorage) storage.GraphStore
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 ¶
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) 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
func (g *GraphStore) Subscribe(ctx context.Context, fn storage.PeerSubscribeFunc) (context.CancelFunc, error)
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.