Documentation
¶
Overview ¶
Package graph separates shared rule definitions from mutable search results.
Data owns class/rule identity and compact integer topology. Node IDs identify classes; line IDs identify expanded (start class, goal class, rule) records. A Graph contains Node and Line objects for Gonum algorithms, rendering or results. It may contain only a subset of Data's topology. An Edge groups all parallel lines between two nodes; it has no separate identity in Data.
Searches can use Data's ID-based adjacency without constructing a Graph. Mutable Nodes, Lines and Queries belong to a search/result, not to Data. View adapts Data directly to Gonum algorithms without result-bearing objects. This package does not query stores; the engine does that.
Index ¶
- Variables
- type Attrs
- type Data
- func (d *Data) Class(id int64) korrel8r.Class
- func (d *Data) Classes() []korrel8r.Class
- func (d *Data) EachLineIDFrom(node int64, visit func(int))
- func (d *Data) EachLineIDTo(node int64, visit func(int))
- func (d *Data) EdgeWeight(from, to int64) (float64, bool)
- func (d *Data) Endpoints(id int) (int64, int64)
- func (d *Data) FullGraph() *Graph
- func (d *Data) Graph() View
- func (d *Data) LineCount() int
- func (d *Data) NewLine(id int, from, to *Node) *Line
- func (d *Data) NewNode(id int64) *Node
- func (d *Data) NodeCount() int
- func (d *Data) NodeID(c korrel8r.Class) (int64, bool)
- func (d *Data) RuleForLine(id int) korrel8r.Rule
- func (d *Data) Rules() []korrel8r.Rule
- type Edge
- type Graph
- func (g *Graph) AddLine(l *Line)
- func (g *Graph) DOTAttributers() (graph, node, edge encoding.Attributer)
- func (g *Graph) DOTID() string
- func (g *Graph) EachEdge(visit func(*Edge))
- func (g *Graph) EachLine(visit func(*Line))
- func (g *Graph) EachLineBetween(start, goal *Node, visit func(l *Line))
- func (g *Graph) EachLineFrom(start *Node, visit func(*Line))
- func (g *Graph) EachLineTo(goal *Node, visit func(*Line))
- func (g *Graph) EachNode(visit func(*Node))
- func (g *Graph) FindLine(start, goal korrel8r.Class, rule korrel8r.Rule) *Line
- func (g *Graph) LineStrings() (lines []string)
- func (g *Graph) NodeFor(c korrel8r.Class) *Node
- func (g *Graph) NodeForErr(c korrel8r.Class) (*Node, error)
- func (g *Graph) NodeStrings(sorted bool) (nodes []string)
- func (g *Graph) RemoveEmpty()
- func (g *Graph) RemoveEmptyGoalPaths(goals []korrel8r.Class)
- func (g *Graph) Select(keep func(*Line) bool) *Graph
- func (g *Graph) Weight(u, v int64) (w float64, ok bool)
- type Line
- type Node
- type Queries
- type QueryCount
- type Truncation
- type View
- func (g View) Edge(from, to int64) graph.Edge
- func (g View) From(id int64) graph.Nodes
- func (g View) HasEdgeBetween(x, y int64) bool
- func (g View) HasEdgeFromTo(from, to int64) bool
- func (g View) Node(id int64) graph.Node
- func (g View) Nodes() graph.Nodes
- func (g View) To(id int64) graph.Nodes
- func (g View) Weight(from, to int64) (float64, bool)
- func (g View) WeightedEdge(from, to int64) graph.WeightedEdge
Constants ¶
This section is empty.
Variables ¶
Pull useful functions into this package.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data is the shared, immutable graph of all rules. It assigns immutable integer IDs to nodes (classes), rules, and lines, and provides fast, allocation-free iteration via an adjacency list.
Mutable Node and Line values are created and managed separately to hold results and queries. A View provides a fast read-only Gonum graph of the Data.
func NewData ¶
NewData builds a rule graph definition. Input order determines node and line IDs; parallel lines, self-loops and repeated input rules are preserved.
func (*Data) Class ¶ added in v0.12.3
Class returns the class associated with a node ID. Invalid IDs panic.
func (*Data) EachLineIDFrom ¶ added in v0.12.3
EachLineIDFrom visits outgoing line IDs in creation order without allocating. Invalid node IDs are treated as empty adjacency lists.
func (*Data) EachLineIDTo ¶ added in v0.12.3
EachLineIDTo visits incoming line IDs in creation order without allocating. Invalid node IDs are treated as empty adjacency lists.
func (*Data) EdgeWeight ¶ added in v0.12.3
EdgeWeight returns the least weight of any line from->to, and whether the edge exists.
func (*Data) Endpoints ¶ added in v0.12.3
Endpoints returns the start and goal node IDs of a line. Invalid IDs panic.
func (*Data) FullGraph ¶ added in v0.6.1
FullGraph creates an independent mutable Graph containing all of Data. Nodes and lines have fresh, empty result/query/attribute state.
func (*Data) Graph ¶ added in v0.12.3
Graph returns a read-only Gonum view without building or caching another graph.
func (*Data) NewLine ¶ added in v0.12.3
NewLine creates independently owned mutable line state between explicit search/graph-owned nodes. Endpoint IDs must match the topology line or it panics. Retain the returned pointer to accumulate Queries; each call creates fresh state.
func (*Data) NewNode ¶ added in v0.12.3
NewNode creates a search-owned or graph-owned mutable node for a class identity. Each call creates independent state; Data retains no reference to the node.
func (*Data) NodeID ¶ added in v0.12.3
NodeID returns the class's node ID and whether it exists in the topology.
func (*Data) RuleForLine ¶ added in v0.12.3
RuleForLine returns the rule associated with a line. Invalid IDs panic.
type Edge ¶ added in v0.1.1
Edge groups all parallel Lines between a pair of nodes in a Gonum Graph. It is an algorithm/iteration view, not a separate topology record.
type Graph ¶
type Graph struct {
*multi.DirectedGraph
GraphAttrs, NodeAttrs, EdgeAttrs Attrs
Data *Data
// Truncation is set if the search returned a partial graph. It is a field
// rather than a GraphAttrs entry, which GraphViz would reject on render.
Truncation *Truncation
// contains filtered or unexported fields
}
Graph is a Gonum directed multigraph built from a Data definition. Nodes and Lines carry results, query accounting and GraphViz attributes. Graphs sharing Data use the same IDs, but normally own independent mutable objects.
Graph is not safe for concurrent mutation. For concurrent read-only topology access, use Data.Graph's View instead. Use AddLine (not the embedded SetLine) to maintain the ordered line index.
func New ¶
New creates an empty mutable Graph using data's identity space. It does not add any nodes or lines.
func (*Graph) AddLine ¶ added in v0.12.0
AddLine inserts a previously absent line into Gonum and the ordered line index. It retains l itself (including Queries), rather than copying it. Its endpoints must be the nodes owned by this Graph. Use copyLine for fresh mutable copies.
func (*Graph) DOTAttributers ¶
func (g *Graph) DOTAttributers() (graph, node, edge encoding.Attributer)
func (*Graph) EachLine ¶
EachLine visits the graph's line objects in insertion order without allocating.
func (*Graph) EachLineBetween ¶ added in v0.8.0
EachLineBetween calls visit(l) for each line between start and goal (if there are any).
func (*Graph) EachLineFrom ¶ added in v0.8.0
EachLineFrom calls visit(l) for each line from start.
func (*Graph) EachLineTo ¶ added in v0.8.0
EachLineTo calls visit(l) for each line to goal.
func (*Graph) FindLine ¶ added in v0.8.3
FindLine finds a line between start and goal with rule. Nil if not found.
func (*Graph) LineStrings ¶ added in v0.8.4
func (*Graph) NodeFor ¶
NodeFor returns this Graph's node for c, or nil if it is not in this Graph. Data.NodeID instead looks up topology membership without creating a Node.
func (*Graph) NodeForErr ¶ added in v0.8.1
func (*Graph) NodeStrings ¶ added in v0.8.4
func (*Graph) RemoveEmpty ¶ added in v0.8.4
func (g *Graph) RemoveEmpty()
Remove empty nodes and lines from the graph.
func (*Graph) RemoveEmptyGoalPaths ¶ added in v0.10.0
RemoveEmptyGoalPaths removes nodes not connected to a non-empty goal.
func (*Graph) Weight ¶ added in v0.8.4
Weight an edge by the "spread" of its rules.
Wildcard rules in domains with many classes (e.g. k8s, DependentToOwner) create many speculative graph lines, but following these lines often leads nowhere. The weight of an edge is the spread of its least expensive rule. In other words consider an edge expensive if it only has expensive rules.
type Line ¶
type Line struct {
multi.Line
Attrs
Rule korrel8r.Rule
Queries Queries // Queries generated by this rule for this pair of classes.
}
Line is a graph object for a topology line: one rule connecting a specific pair of class nodes. Its ID is assigned by Data, independent of its pointer identity. Searches and mutable Graphs own Lines and their Queries; View uses only IDs. Different rules (or repeated input rules) may connect the same pair of nodes.
type Node ¶
type Node struct {
multi.Node
Attrs
Class korrel8r.Class
Result result.Result
Queries Queries // Queries selecting objects in this class.
}
Node is a graph-owned object representing a class. A search-owned node holds mutable results, queries and display attributes. Read-only topology algorithms use View's lightweight node IDs instead of these mutable objects. Data stores class identity (node ID and class), not Node objects. Node IDs are meaningful within the Data that assigned them.
type Queries ¶ added in v0.1.2
type Queries map[korrel8r.Query]QueryCount
Queries holds mutable query accounting for a Node or Line, keyed by query identity. It belongs to a search or result Graph, never to immutable topology. Concurrent access requires synchronization by the owner.
func (Queries) AddStatuses ¶ added in v0.11.0
AddStatuses merges status counts into the QueryCount for q.
type QueryCount ¶
QueryCount records the number of objects resulting from a query. Count == -1 means the query has not been evaluated.
type Truncation ¶ added in v0.12.3
type Truncation struct {
Condition string // Name of the exceeded limit.
Limit int // Value of the exceeded limit.
}
Truncation records why a search stopped before exploring the whole graph.
type View ¶ added in v0.12.3
type View struct {
// contains filtered or unexported fields
}
View adapts Data's compact topology to Gonum's read-only weighted directed graph interface. It owns no Node/Line objects or cached graph representation. Nodes are lightweight IDs, not result-bearing *Node objects. Parallel lines form one edge whose weight is the least rule spread, as in Graph.Weight. Views and Data can be read concurrently; each iterator has independent state.
func (View) HasEdgeBetween ¶ added in v0.12.3
func (View) HasEdgeFromTo ¶ added in v0.12.3
Edge lookups use Data's pre-computed edge index, so they do not scan the source node's adjacency. Shortest-path searches relax every edge repeatedly, so a scan here would cost O(out-degree) per relaxation.
func (View) Weight ¶ added in v0.12.3
Weight preserves Graph.Weight's zero self-weight (even for an absent node). A self-weight does not imply that a self-loop edge exists.
func (View) WeightedEdge ¶ added in v0.12.3
func (g View) WeightedEdge(from, to int64) graph.WeightedEdge