graph

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package graph provides a simple adjacency map graph for network-graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save

func Save(g *Graph) (string, error)

Save serializes the graph to a string.

Types

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph maintains nodes and adjacency edges.

func FromMatrix

func FromMatrix(matrix [][]bool, bidirectional bool) *Graph

FromMatrix creates a new graph from a boolean adjacency matrix.

func Load

func Load(data string) (*Graph, error)

Load deserializes the graph from a string.

func New

func New(bidirectional bool) *Graph

New creates and returns an empty Graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to node.ID) error

AddEdge adds an edge from -> to. If bidirectional is true, adds the reverse edge as well.

func (*Graph) AddNode

func (g *Graph) AddNode(id node.ID) error

AddNode adds a node to the graph.

func (*Graph) EdgeCount

func (g *Graph) EdgeCount() int

EdgeCount returns the number of edges in the graph.

func (*Graph) HasEdge

func (g *Graph) HasEdge(from, to node.ID) bool

HasEdge checks if an edge exists from -> to.

func (*Graph) HasNode

func (g *Graph) HasNode(id node.ID) bool

HasNode reports whether a node with the given id exists.

func (*Graph) Hash

func (g *Graph) Hash() string

Hash returns the SHA-256 hash of the graph.

func (*Graph) IsBidirectional

func (g *Graph) IsBidirectional() bool

IsBidirectional returns true if the graph is bidirectional.

func (*Graph) Neighbors

func (g *Graph) Neighbors(id node.ID) []node.ID

Neighbors returns the list of neighbors reachable from the given node id.

func (*Graph) Nodes

func (g *Graph) Nodes() []node.ID

Nodes returns a slice of all node IDs in the graph.

func (*Graph) RemoveEdge

func (g *Graph) RemoveEdge(from, to node.ID) error

RemoveEdge removes the edge from -> to. If bidirectional is true, removes the reverse edge as well.

func (*Graph) RemoveNode

func (g *Graph) RemoveNode(id node.ID) error

RemoveNode removes a node and its incident edges from the graph.

Jump to

Keyboard shortcuts

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