graph

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InfiniteDepth is used as a flag to instruct the walker to traverse infinite depth
	InfiniteDepth int = -1

	// TraverseChildren is a flag to denote the Relationship should walk children
	TraverseChildren WalkDirection = iota

	// TraverseParents is a flag to denote the Relationship should walk parents
	TraverseParents
)

Variables

View Source
var (
	// ErrTraversalPathEnded is thrown when the walker has hit the final element in the tree
	ErrTraversalPathEnded = errors.New("traversal path has hit the final element")

	// ErrRelationshipWalkHalted is thrown when a walk is intended to discontinue walking
	ErrRelationshipWalkHalted = errors.New("relationship walk has reached a termination point")

	// ErrWalkDirectionUndefined is thrown when a direction is neither TraverseChildren or TraverseParents
	ErrWalkDirectionUndefined = errors.New("a walk direction of an unknown type has been given")
)

Functions

func AssociateChildren

func AssociateChildren(subject Relationship, children ...Relationship)

AssociateChildren is a generic function to associate child dependencies with an object

func AssociateParents

func AssociateParents(subject Relationship, parents ...Relationship)

AssociateParents is a generic function to associate parent dependencies with an object

func HasChild

func HasChild(host Relationship, question Relationship) bool

HasChild determines if a direct child relationship exists between host (parent) and question (supposed child)

func HasIndirectChild

func HasIndirectChild(host Relationship, question Relationship) bool

HasIndirectChild determines if a transitive parent relationship exists between host (parent) and question (supposed child)

func HasIndirectParent

func HasIndirectParent(host Relationship, question Relationship) bool

HasIndirectParent determines if a transitive parent relationship exists between host (child) and question (supposed parent)

func HasParent

func HasParent(host Relationship, question Relationship) bool

HasParent determines if a direct parent relationship exists between host (child) and question (supposed parent)

func WalkRelationship

func WalkRelationship(base Relationship, maxdepth int, offset int, direction WalkDirection, walkFunc RelationshipWalkFunc) error

WalkRelationship is a recursive walk similar to filepath.Walk except it traverses relationships

Types

type DotNode

type DotNode interface {
	Label() string
	GetGID() int
	GetGCost() int64
}

DotNode is an interface to describe the DOT requirements for traversing graphs

type DotWriter

type DotWriter struct {
	MaxDepth int
	Reversed bool
	// contains filtered or unexported fields
}

DotWriter is a type that will build the DOT syntax of our Metadata

func NewDotWriter

func NewDotWriter(output io.Writer, maxdepth int, reversed bool) *DotWriter

NewDotWriter creates a new writer to generate DOT graphs

func (*DotWriter) PlotGraph

func (dw *DotWriter) PlotGraph(root Relationship)

PlotGraph traverses the root Relationship (root) while DotWriter.MaxDepth > 0, generating the graph.

type Hasher

type Hasher interface {
	Hash() uint64
}

Hasher is an interface to allow types to be checksumed for potentially build breaking changes

type ItemGraph

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

ItemGraph the Items graph

func (*ItemGraph) AddEdge

func (g *ItemGraph) AddEdge(n1, n2 *Node)

AddEdge adds an edge to the graph

func (*ItemGraph) AddNode

func (g *ItemGraph) AddNode(n *Node)

AddNode adds a node to the graph

func (*ItemGraph) String

func (g *ItemGraph) String()

AddEdge adds an edge to the graph

func (*ItemGraph) Traverse

func (g *ItemGraph) Traverse(f func(*Node))

Traverse implements the BFS traversing algorithm

type Node

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

Node a single node that composes the tree

func ToNode

func ToNode(rel Relationship) *Node

ToNode converts a relationship to a node

func (*Node) String

func (n *Node) String() string

type NodeQueue

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

NodeQueue the queue of Nodes

func (*NodeQueue) Dequeue

func (s *NodeQueue) Dequeue() *Node

Dequeue removes an Node from the start of the queue

func (*NodeQueue) Enqueue

func (s *NodeQueue) Enqueue(t Node)

Enqueue adds an Node to the end of the queue

func (*NodeQueue) Front

func (s *NodeQueue) Front() *Node

Front returns the item next in the queue, without removing it

func (*NodeQueue) IsEmpty

func (s *NodeQueue) IsEmpty() bool

IsEmpty returns true if the queue is empty

func (*NodeQueue) New

func (s *NodeQueue) New() *NodeQueue

New creates a new NodeQueue

func (*NodeQueue) Size

func (s *NodeQueue) Size() int

Size returns the number of Nodes in the queue

type Relationship

type Relationship interface {
	Hasher
	DotNode
	GetID() string
	Children() []Relationship
	Parents() []Relationship
	ParentIDs() []string
	ChildrenIDs() []string
	AddChild(r ...Relationship)
	AddParent(r ...Relationship)
}

Relationship is an interface to allow core objects to build relationships between them

type RelationshipWalkFunc

type RelationshipWalkFunc func(rel Relationship, distance int) error

RelationshipWalkFunc allows for recursive relation traversal

type WalkDirection

type WalkDirection int

WalkDirection allows the directon of the walk to be specified

Jump to

Keyboard shortcuts

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