graph

package
v0.0.0-...-02c76fb Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 48

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 IsRoot

func IsRoot(id string) bool

IsRoot checks if the ID identifies the root

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(meta *node.Node) 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(node *node.Node)

Add a new value by ID

func (*Graph) AreSiblings

func (g *Graph) AreSiblings(fst, snd string) bool

AreSiblings returns true if both nodes share a parent edge, or both nodes are at the root of the graph (and have no parent edge). It returns false if both IDs are the same.

func (*Graph) Children

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

Children returns a list of ids whose parent id is set to the specified node

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) DownEdgesInGroup

func (g *Graph) DownEdgesInGroup(id, group string) (out []string)

DownEdgesInGroup returns the outward-facing edges of the specified vertex in the specified group

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) (*node.Node, bool)

Get 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, but a valid node will be constructed.

func (*Graph) GetParent

func (g *Graph) GetParent(id string) (*node.Node, bool)

GetParent returns the direct parent vertex of the current node.

func (*Graph) GetParentID

func (g *Graph) GetParentID(id string) (string, bool)

GetParentID is a combination of getting the parent the getting the ID.

func (*Graph) GroupNodes

func (g *Graph) GroupNodes(group string) []*node.Node

GroupNodes will return all nodes in the graph in the specified group

func (*Graph) IsNibling

func (g *Graph) IsNibling(fst, snd string) bool

IsNibling checks to see if second is the child of a sibling of the first.

func (*Graph) Nodes

func (g *Graph) Nodes() []*node.Node

Nodes will return all nodes in the graph

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) SafeConnect

func (g *Graph) SafeConnect(from, to string) error

SafeConnect connects two vertices together by ID but only if valid

func (*Graph) SafeDisconnect

func (g *Graph) SafeDisconnect(from, to string) error

SafeDisconnect disconnects two vertices by IDs but only if valid

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) UpEdgesInGroup

func (g *Graph) UpEdgesInGroup(id, group string) (out []string)

UpEdgesInGroup returns the outward-facing edges of the specified vertex in the specified group

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 get 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  NotifyFunc
	Post NotifyFunc
}

Notifier can wrap a graph transform

func (*Notifier) Transform

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

Transform wraps a TransformFunc with this notifier

type NotifyFunc

type NotifyFunc func(*node.Node) error

NotifyFunc will be called before execution

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 SkipMergeFunc

type SkipMergeFunc func(*node.Node) bool

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

type TransformFunc

type TransformFunc func(*node.Node, *Graph) error

TransformFunc is taken by the transformation functions

func NotifyPost

func NotifyPost(post NotifyFunc, inner TransformFunc) TransformFunc

NotifyPost will call a function after walking a node

func NotifyPre

func NotifyPre(pre NotifyFunc, inner TransformFunc) TransformFunc

NotifyPre will call a function before walking a node

type WalkFunc

type WalkFunc func(*node.Node) error

WalkFunc is taken by the walking functions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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