graph

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package graph provides an implement of cfn.Graph and can be used to graph dependencies between elements of a CloudFormation template

Example (Get)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cfn/graph"
)

func main() {
	g := graph.New()
	g.Add("foo", "bar", "baz")
	g.Add("bar", "quux")
	g.Add("baz", "foo") // Circular dependencies are fine

	fmt.Println(g.Get("foo"))
	fmt.Println(g.Get("bar"))
	fmt.Println(g.Get("baz"))
}
Output:

[bar baz]
[quux]
[foo]
Example (GetReverse)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cfn/graph"
)

func main() {
	g := graph.New()
	g.Add("foo", "bar", "baz")
	g.Add("bar", "quux", "baz")
	g.Add("baz", "foo") // Circular dependencies are fine

	fmt.Println(g.GetReverse("foo"))
	fmt.Println(g.GetReverse("bar"))
	fmt.Println(g.GetReverse("baz"))
}
Output:

[baz]
[foo]
[bar foo]
Example (Nodes)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cfn/graph"
)

func main() {
	g := graph.New()
	g.Add("Cake", "Eggs", "Butter")
	g.Add("Eggs", "Chicken")
	g.Add("Dinner", "Chicken", "Cake")

	fmt.Println(g.Nodes())
}
Output:

[Butter Chicken Eggs Cake Dinner]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

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

Graph represents a directed, acyclic graph with ordered nodes

func New

func New() Graph

New returns a new Graph

func (*Graph) Add

func (g *Graph) Add(item interface{}, links ...interface{})

Add creates a link between two nodes in the graph

func (Graph) Get

func (g Graph) Get(item interface{}) []interface{}

Get returns all nodes that are connected to the item that you pass in.

func (Graph) GetReverse

func (g Graph) GetReverse(item interface{}) []interface{}

GetReverse returns all nodes that connect to the item that you pass in.

func (Graph) Nodes

func (g Graph) Nodes() []interface{}

Nodes returns all nodes of the graph, in order of their dependencies. Nodes with the fewest dependencies are at the beginning of the slice.

func (*Graph) String

func (g *Graph) String() string

Jump to

Keyboard shortcuts

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