graph

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DotEdgeSpec

type DotEdgeSpec struct {
	FromNodeName string
	ToNodeName   string
	Tooltip      string
	Style        string
	Color        string
}

DotEdgeSpec is the specification for an edge in DOT graph

type DotNodeSpec

type DotNodeSpec struct {
	// id of the node
	Name string
	// display text of the node
	DisplayName string
	Tooltip     string
	Shape       string
	Style       string
	FillColor   string
}

DotNodeSpec is the specification for a node in a DOT graph

type Edge

type Edge[NT NodeConstrain] struct {
	From NT
	To   NT
}

type EdgeSpecFunc

type EdgeSpecFunc[T NodeConstrain] func(from, to T) *DotEdgeSpec

EdgeSpecFunc is a function that returns the DOT specification for an edge.

type Graph

type Graph[NT NodeConstrain] struct {
	// contains filtered or unexported fields
}

Graph hold the nodes and edges of a graph

func NewGraph

func NewGraph[NT NodeConstrain](edgeSpecFunc EdgeSpecFunc[NT]) *Graph[NT]

NewGraph creates a new graph

func (*Graph[NT]) AddNode

func (g *Graph[NT]) AddNode(n NT) error

AddNode adds a node to the graph

func (*Graph[NT]) Connect

func (g *Graph[NT]) Connect(from, to NT) error

func (*Graph[NT]) TopologicalSort added in v0.2.0

func (g *Graph[NT]) TopologicalSort() []NT

type GraphCodeError

type GraphCodeError string
const (
	ErrDuplicateNode          GraphCodeError = "node with same key already exists in this graph"
	ErrConnectNotExistingNode GraphCodeError = "node to connect does not exist in this graph"
)

func (GraphCodeError) Error

func (ge GraphCodeError) Error() string

type GraphError

type GraphError struct {
	Code    GraphCodeError
	Message string
}

func NewGraphError

func NewGraphError(code GraphCodeError, message string) *GraphError

func (*GraphError) Error

func (ge *GraphError) Error() string

func (*GraphError) Unwrap

func (ge *GraphError) Unwrap() error

type NodeConstrain

type NodeConstrain interface {
	// Name of the node, should be unique in the graph
	GetName() string
	// DotSpec returns the dot spec for this node
	DotSpec() *DotNodeSpec
}

NodeConstrain is a constraint for a node in a graph

Jump to

Keyboard shortcuts

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