graph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(g *Graph, report *ValidationReport) int

Sanitize drops every edge in g flagged as dangling by report. In-place mutation; returns the number of edges dropped. Pre-condition: report was produced from Inspect(g) on this same graph (the dangling edge identity matches by all four (Type,Src,Dst,Line) fields).

func Validate

func Validate(g *Graph) error

Validate enforces the CKG invariants strictly:

  • every edge.src and edge.dst references an existing node ID
  • every node and edge has a valid Confidence label
  • every node has a known NodeType
  • every edge has a known EdgeType

Returns the FIRST violation as an error; preserved for backward compatibility with tests and strict-mode builds. New callers should prefer Inspect (which collects everything) plus Sanitize (which drops dangling edges) to enable lenient dogfooding flows.

Types

type DanglingEdge

type DanglingEdge struct {
	Edge types.Edge
	Src  bool // true when edge.Src has no matching node
	Dst  bool // true when edge.Dst has no matching node
}

DanglingEdge captures an edge whose Src or Dst (or both) does not reference a node present in g.Nodes. Used by Inspect / Sanitize to report and drop orphaned references without aborting the whole build.

type Graph

type Graph struct {
	Nodes []types.Node
	Edges []types.Edge
}

Graph is the in-memory CKG graph after build.

func Build

func Build(parts []*parse.ResolvedGraph) (*Graph, error)

Build merges per-language ResolvedGraphs, deduplicating nodes by ID (last-writer wins for attributes — should be identical for true dups) and edges by (Type, Src, Dst, Line) keep-first.

Cold-path semantics: each ResolvedGraph comes from a different language, so edge keys cannot collide across parts. Dedup is a no-op and Build's output is identical to the pre-G6-v3 append-only behaviour.

Partial-cache semantics (G6 v3): the same logical edge can arrive from two sources — (a) reloaded from DB for cached files, (b) freshly emitted by Pass 2 Resolve over the merged dirty+cached input. Without dedup these would double-count in the in-memory Graph that cluster/score/temporal passes consume (PageRank seeing 2× weight on cached↔cached edges, etc.).

Tie-breaker is keep-first, NOT count summation, because cold builds produce Edge.Count=1 for every edge (verified empirically on go-stablenet: 317614 edges all have count=1) — summing would inflate counts under partial and break § 7.1 parity with cold.

type ValidationReport

type ValidationReport struct {
	SchemaErrors  []error
	DanglingEdges []DanglingEdge
}

ValidationReport summarizes the result of Inspect. Schema errors are fatal-worthy (unknown type / invalid confidence — these mean the emitter is broken). Dangling edges are recoverable: Sanitize drops them and the build proceeds with a warning. This separation lets dogfooding self-analysis proceed even when the parser emits an orphaned reference.

func Inspect

func Inspect(g *Graph) *ValidationReport

Inspect collects ALL validation issues in g without aborting on the first. Schema errors (unknown node/edge type, invalid confidence) and dangling references (edge.Src or edge.Dst not in g.Nodes) are reported separately.

Inspect itself never returns an error — callers decide policy via the returned report. Use Validate for the legacy fatal-on-first-violation API.

func (*ValidationReport) CountByEdgeType

func (r *ValidationReport) CountByEdgeType() map[types.EdgeType]int

CountByEdgeType groups the dangling edges by their EdgeType. Useful for surfacing in build logs ("listens_on: 3, calls: 1").

func (*ValidationReport) HasDangling

func (r *ValidationReport) HasDangling() bool

HasDangling reports whether at least one edge has a missing endpoint.

func (*ValidationReport) HasSchemaErrors

func (r *ValidationReport) HasSchemaErrors() bool

HasSchemaErrors reports whether any unknown-type / invalid-confidence violations were found. These should always fail a build.

Jump to

Keyboard shortcuts

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