graph

package
v0.0.0-...-215933a Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreSiblingIDs

func AreSiblingIDs(a, b string) bool

AreSiblingIDs checks if two IDs are siblings

func BaseID

func BaseID(id string) string

BaseID is the end of the ID, so "just" the original part

func ID

func ID(parts ...string) string

ID for a node in the graph

func IsDescendentID

func IsDescendentID(parent, child string) bool

IsDescendentID checks if a child is the descendent of a given parent

func ParentID

func ParentID(id string) string

ParentID for a node in the graph

func SiblingID

func SiblingID(id, sibling string) string

SiblingID for a node in the graph

func SkipModuleAndParams

func SkipModuleAndParams(id string) bool

SkipModuleAndParams skips trimming modules and params

func Sources

func Sources(edges []dag.Edge) (sources []string)

Sources gets the sources from slice of edges

func Targets

func Targets(edges []dag.Edge) (targets []string)

Targets gets the targets from slice of edges

Types

type Edge

type Edge struct {
	Source     string   `json:"source"`
	Dest       string   `json:"dest"`
	Attributes []string `json:"attributes"`
}

An Edge is a generic pair of IDs indicating a directed edge in the graph

type Graph

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

Graph is a generic graph structure that uses IDs to connect the graph

func MergeDuplicates

func MergeDuplicates(ctx context.Context, g *Graph, skip SkipMergeFunc) (*Graph, error)

MergeDuplicates removes duplicates in the graph

func New

func New() *Graph

New constructs and returns a new Graph

func (*Graph) Add

func (g *Graph) Add(id string, value interface{})

Add a new value by ID

func (*Graph) Connect

func (g *Graph) Connect(from, to string)

Connect two vertices together by ID

func (*Graph) ConnectParent

func (g *Graph) ConnectParent(from, to string)

ConnectParent connects a parent node to a child node

func (*Graph) Contains

func (g *Graph) Contains(id string) bool

Contains returns true if the id exists in the map

func (*Graph) Copy

func (g *Graph) Copy() *Graph

Copy the graph for further modification

func (*Graph) Dependencies

func (g *Graph) Dependencies(id string) []string

Dependencies gets a list of all dependencies without relying on the ID functions and will work for dependencies that have been added during load.ResolveDependencies

func (*Graph) Descendents

func (g *Graph) Descendents(id string) (out []string)

Descendents gets a list of all descendents (not just children, everything) This only works if you're using the hierarchical ID functions from this module.

func (*Graph) Disconnect

func (g *Graph) Disconnect(from, to string)

Disconnect two vertices by IDs

func (*Graph) DownEdges

func (g *Graph) DownEdges(id string) (out []dag.Edge)

DownEdges returns outward-facing edges of the specified vertex

func (*Graph) Edges

func (g *Graph) Edges() []Edge

Edges will get a list of all of the edges in the graph.

func (*Graph) Get

func (g *Graph) Get(id string) interface{}

Get a value by ID

func (*Graph) GetParent

func (g *Graph) GetParent(id string) interface{}

GetParent returns the direct parent vertex of the current node.

func (*Graph) MaybeGet

func (g *Graph) MaybeGet(id string) (interface{}, bool)

MaybeGet returns the value of the element and a bool indicating if it was found, if it was not found the value of the returned element is nil.

func (*Graph) Remove

func (g *Graph) Remove(id string)

Remove an existing value by ID

func (*Graph) Root

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

Root will get the root element of the graph

func (*Graph) RootFirstTransform

func (g *Graph) RootFirstTransform(ctx context.Context, cb TransformFunc) (*Graph, error)

RootFirstTransform does Transform, but starting at the root

func (*Graph) RootFirstWalk

func (g *Graph) RootFirstWalk(ctx context.Context, cb WalkFunc) error

RootFirstWalk walks the graph root-to-leaf, checking sibling dependencies before descending.

func (*Graph) String

func (g *Graph) String() string

func (*Graph) Transform

func (g *Graph) Transform(ctx context.Context, cb TransformFunc) (*Graph, error)

Transform a graph of type A to a graph of type B. A and B can be the same.

func (*Graph) UpEdges

func (g *Graph) UpEdges(id string) (out []dag.Edge)

UpEdges returns inward-facing edges of the specified vertex

func (*Graph) Validate

func (g *Graph) Validate() error

Validate that the graph...

1. has a root 2. has no cycles 3. has no dangling edges

func (*Graph) Vertices

func (g *Graph) Vertices() []string

Vertices will det a list of the IDs for every vertex in the graph, cast to a string.

func (*Graph) Walk

func (g *Graph) Walk(ctx context.Context, cb WalkFunc) error

Walk the graph leaf-to-root

type Notifier

type Notifier struct {
	Pre  PreNotifyFunc
	Post PostNotifyFunc
}

Notifier can wrap a graph transform

func (*Notifier) Transform

func (n *Notifier) Transform(inner TransformFunc) TransformFunc

Transform wraps a TransformFunc with this notifier

type ParentEdge

type ParentEdge struct {
	dag.Edge
}

ParentEdge marks an edge as signifying a parent/child relationship

func NewParentEdge

func NewParentEdge(parent, child string) *ParentEdge

NewParentEdge constructs a new ParentEdge between the given vertices

type PostNotifyFunc

type PostNotifyFunc func(string, interface{}) error

PostNotifyFunc will be called after planning

type PreNotifyFunc

type PreNotifyFunc func(string) error

PreNotifyFunc will be called before execution

type SkipMergeFunc

type SkipMergeFunc func(string) bool

SkipMergeFunc will be used to determine whether or not to merge a node

type TransformFunc

type TransformFunc func(string, *Graph) error

TransformFunc is taken by the transformation functions

func NotifyPost

func NotifyPost(post PostNotifyFunc, inner TransformFunc) TransformFunc

NotifyPost will call a function after walking a node

func NotifyPre

func NotifyPre(pre PreNotifyFunc, inner TransformFunc) TransformFunc

NotifyPre will call a function before walking a node

type WalkFunc

type WalkFunc func(string, interface{}) error

WalkFunc is taken by the walking functions

Jump to

Keyboard shortcuts

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