graph

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Overview

Package graph provides a directed multi-graph with class nodes and rule edges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassFor

func ClassFor(n graph.Node) korrel8r.Class

func RuleFor

func RuleFor(l graph.Line) korrel8r.Rule

Types

type Attrs

type Attrs map[string]string

Attributes for nodes and lines rendered by Graphviz.

func (Attrs) Attributes

func (a Attrs) Attributes() (enc []encoding.Attribute)

type Data

type Data struct {
	Nodes []*Node // Nodes slice index == Node.ID()
	Lines []*Line // Lines slice index == Line.ID()
	// contains filtered or unexported fields
}

Data contains a set of class nodes and rule lines to be used in rule/class graphs. Graphs based on the same Data have consistent node and line IDs.

Concurrency: Data is immutable once created.

func NewData

func NewData(rules ...korrel8r.Rule) *Data

NewData creates a new data set from a list of rules.

Concurrency: Data is immutable once created.

func (*Data) Classes

func (d *Data) Classes() []korrel8r.Class

Classes returns a copy of the complete list of classes.

func (*Data) EmptyGraph

func (d *Data) EmptyGraph() *Graph

EmptyGraph returns a new emptpy graph.

func (*Data) FullGraph added in v0.6.1

func (d *Data) FullGraph() *Graph

FullGraph returns a new graph of all the Data.

func (*Data) NodeFor

func (d *Data) NodeFor(c korrel8r.Class) *Node

NodeFor returns the Node for class c, or nil if absent.

func (*Data) Rules

func (d *Data) Rules() []korrel8r.Rule

Rules returns a copy of the complete list of rules.

type Edge added in v0.1.1

type Edge multi.Edge

func (*Edge) EachLine added in v0.1.1

func (e *Edge) EachLine(visit func(*Line))

func (*Edge) Goal added in v0.1.1

func (e *Edge) Goal() *Node

func (*Edge) Start added in v0.1.1

func (e *Edge) Start() *Node

type Graph

type Graph struct {
	*multi.DirectedGraph
	GraphAttrs, NodeAttrs, EdgeAttrs Attrs
	Data                             *Data
	// contains filtered or unexported fields
}

Graph is a directed multigraph with korrel8r.Class noes and korrel8r.Rule lines. Nodes and lines carry attributes for rendering by GraphViz.

Concurrency: Graph is mutable, normal concurrency rules apply regarding read/write operations.

func New

func New(data *Data) *Graph

New empty graph based on Data

func (*Graph) AllLines

func (g *Graph) AllLines() (lines []*Line)

func (*Graph) AllNodes

func (g *Graph) AllNodes() (nodes []*Node)

func (*Graph) AllPaths

func (g *Graph) AllPaths(start korrel8r.Class, goals ...korrel8r.Class) *Graph

AllPaths returns a new sub-graph containing all paths between start and goal.

func (*Graph) DOTAttributers

func (g *Graph) DOTAttributers() (graph, node, edge encoding.Attributer)

func (*Graph) DOTID

func (g *Graph) DOTID() string

func (*Graph) EachEdge added in v0.1.1

func (g *Graph) EachEdge(visit func(*Edge))

func (*Graph) EachLine

func (g *Graph) EachLine(visit func(*Line))

func (*Graph) EachNode

func (g *Graph) EachNode(visit func(*Node))

func (*Graph) LinesBetween

func (g *Graph) LinesBetween(u, v *Node) (lines []*Line)

func (*Graph) LinesTo

func (g *Graph) LinesTo(v *Node) (lines []*Line)

func (*Graph) Neighbours

func (g *Graph) Neighbours(start korrel8r.Class, depth int, f func(*Line) bool) *Graph

Neighbours traverses a breadth-first neighbourhood of start. Returns the subset of the graph that was traversed.

func (*Graph) NodeFor

func (g *Graph) NodeFor(c korrel8r.Class) *Node

func (*Graph) NodesFor

func (g *Graph) NodesFor(classes ...korrel8r.Class) (nodes []*Node)

func (*Graph) NodesSubgraph

func (g *Graph) NodesSubgraph(nodes []graph.Node) *Graph

NodesSubgraph returns a new graph containing nodes and all lines between them.

func (*Graph) Select

func (g *Graph) Select(keep func(l *Line) bool) *Graph

Select creates a sub-graph of all lines where keep(line) is true.

func (*Graph) ShortestPaths

func (g *Graph) ShortestPaths(start korrel8r.Class, goals ...korrel8r.Class) *Graph

ShortestPaths returns a new sub-graph containing all shortest paths between start and goals.

func (*Graph) Traverse

func (g *Graph) Traverse(start korrel8r.Class, goals []korrel8r.Class, f func(*Line) bool) *Graph

Traverse rules on paths from start to goal. Returns the subset of the graph that was traversed.

type Line

type Line struct {
	multi.Line
	Attrs   // GraphViz Attributer
	Rule    korrel8r.Rule
	Queries Queries // Queries generated by Rule
}

Line is one line in a multi-graph edge, corresponds to a rule.

func LineFor added in v0.6.0

func LineFor(l graph.Line) *Line

func (*Line) DOTID

func (l *Line) DOTID() string

func (*Line) String

func (l *Line) String() string

type Node

type Node struct {
	multi.Node
	Attrs   // GraphViz Attributer
	Class   korrel8r.Class
	Result  korrel8r.Result // Accumulate incoming query results.
	Queries Queries         // All queries leading to this node.
}

Node is a graph Node, contains a Class.

func NodeFor added in v0.6.0

func NodeFor(n graph.Node) *Node

func (*Node) DOTID

func (n *Node) DOTID() string

func (*Node) Empty added in v0.1.1

func (n *Node) Empty() bool

func (*Node) String

func (n *Node) String() string

type Queries added in v0.1.2

type Queries map[string]QueryCount

Queries is a map of QueryCount by Query name.

func (Queries) Get added in v0.6.0

func (qs Queries) Get(q korrel8r.Query) int

func (Queries) Has added in v0.6.0

func (qs Queries) Has(q korrel8r.Query) bool

func (Queries) Set added in v0.6.0

func (qs Queries) Set(q korrel8r.Query, n int)

func (Queries) Total added in v0.1.2

func (qs Queries) Total() (total int)

Total of the counts

type QueryCount

type QueryCount struct {
	Query korrel8r.Query
	Count int
}

QueryCount records count of objects resulting from a query. Count == -1 means the query has not been evaluated.

Jump to

Keyboard shortcuts

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