graph

package
v1.0.9 Latest Latest
Warning

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

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

Documentation

Overview

Example (Circular)
node1 := NewNode("node1", "node2")
node2 := NewNode("node2", "node3")
node3 := NewNode("node3", "node1")
var g Graph
g = append(g, node1, node2, node3)
g, err := Resolve(g)
if err != nil {
	fmt.Println(err)
	// g.Display()
	return
}
fmt.Println("OK")
Output:

Circular dependency found
Example (Ok)
node1 := NewNode("node1", "node2")
node2 := NewNode("node2", "node3")
node3 := NewNode("node3")
var g Graph
g = append(g, node1, node2, node3)
g, err := Resolve(g)
if err != nil {
	fmt.Println(err)
	g.Display()
	return
}
fmt.Println("OK")
g.Display()
Output:

OK
node3
node2 -> node3
node1 -> node2

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph []*Node

Graph dependency graph

func Resolve

func Resolve(graph Graph) (Graph, error)

Resolve the dependency graph

func (Graph) Display

func (g Graph) Display()

Display the dependency graph

type Node

type Node struct {
	// Name of the node
	Name string

	// Dependencies of the node
	Deps []string
}

Node represents a single node in the graph with it's dependencies

func NewNode

func NewNode(name string, deps ...string) *Node

NewNode creates a new node

func (*Node) String

func (n *Node) String() string

Jump to

Keyboard shortcuts

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