graph

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderMermaid

func RenderMermaid[K comparable, T any](w io.Writer, g *Graph[K, T]) error

func RenderText

func RenderText[K comparable, T any](w io.Writer, g *Graph[K, T]) error

Types

type Graph

type Graph[K comparable, T any] struct {
	Nodes   []*Node[T]
	KeyFunc func(T) K
	// contains filtered or unexported fields
}

func Ints

func Ints(values ...int) *Graph[int, int]

func New

func New[K comparable, T any](keyFunc func(T) K, values ...T) *Graph[K, T]

func Strings

func Strings(values ...string) *Graph[string, string]

func (*Graph[K, T]) Add

func (g *Graph[K, T]) Add(v T) (node *Node[T], added bool)

func (*Graph[K, T]) LinkTo

func (g *Graph[K, T]) LinkTo(prev *Node[T], node *Node[T]) (added bool)

func (*Graph[K, T]) Madd

func (g *Graph[K, T]) Madd(v T) *Node[T]

func (*Graph[K, T]) SortedByFrom added in v0.2.0

func (g *Graph[K, T]) SortedByFrom(nodes []*Node[T]) []*Node[T]

topological sort

func (*Graph[K, T]) SortedByTo added in v0.2.0

func (g *Graph[K, T]) SortedByTo(nodes []*Node[T]) []*Node[T]

topological sort

func (*Graph[K, T]) Walk

func (g *Graph[K, T]) Walk(fn func(*Node[T]))

func (*Graph[K, T]) WalkPath

func (g *Graph[K, T]) WalkPath(fn func([]*Node[T]), nodes []*Node[T])

type Node

type Node[T any] struct {
	ID    int
	Name  string
	Value T

	From []*Node[T]
	To   []*Node[T]

	Metadata struct {
		Shape Shape
	}
}

func (*Node[T]) String

func (n *Node[T]) String() string

type RenderFunc

type RenderFunc[K comparable, T any] func(io.Writer, *Graph[K, T]) error

type Shape

type Shape string
const (
	ShapeText    Shape = ""
	ShapeRhombus Shape = "rhombus"
)

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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