Documentation
¶
Index ¶
- Variables
- type AlgorithmError
- type Dominators
- func (d *Dominators) HealthCheck(ctx context.Context) error
- func (d *Dominators) InputType() reflect.Type
- func (d *Dominators) Metrics() []eval.MetricDefinition
- func (d *Dominators) Name() string
- func (d *Dominators) OutputType() reflect.Type
- func (d *Dominators) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (d *Dominators) ProgressInterval() time.Duration
- func (d *Dominators) Properties() []eval.Property
- func (d *Dominators) SupportsPartialResults() bool
- func (d *Dominators) Timeout() time.Duration
- type DominatorsConfig
- type DominatorsInput
- type DominatorsOutput
- type TarjanConfig
- type TarjanInput
- type TarjanOutput
- type TarjanSCC
- func (t *TarjanSCC) HealthCheck(ctx context.Context) error
- func (t *TarjanSCC) InputType() reflect.Type
- func (t *TarjanSCC) Metrics() []eval.MetricDefinition
- func (t *TarjanSCC) Name() string
- func (t *TarjanSCC) OutputType() reflect.Type
- func (t *TarjanSCC) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (t *TarjanSCC) ProgressInterval() time.Duration
- func (t *TarjanSCC) Properties() []eval.Property
- func (t *TarjanSCC) SupportsPartialResults() bool
- func (t *TarjanSCC) Timeout() time.Duration
- type VF2
- func (v *VF2) HealthCheck(ctx context.Context) error
- func (v *VF2) InputType() reflect.Type
- func (v *VF2) Metrics() []eval.MetricDefinition
- func (v *VF2) Name() string
- func (v *VF2) OutputType() reflect.Type
- func (v *VF2) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
- func (v *VF2) ProgressInterval() time.Duration
- func (v *VF2) Properties() []eval.Property
- func (v *VF2) SupportsPartialResults() bool
- func (v *VF2) Timeout() time.Duration
- type VF2Config
- type VF2Graph
- type VF2Input
- type VF2Output
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidInput = errors.New("invalid input") ErrInvalidConfig = errors.New("invalid config") )
Package-level error definitions.
Functions ¶
This section is empty.
Types ¶
type AlgorithmError ¶
AlgorithmError wraps algorithm-specific errors.
func (*AlgorithmError) Error ¶
func (e *AlgorithmError) Error() string
type Dominators ¶
type Dominators struct {
// contains filtered or unexported fields
}
Dominators implements the Lengauer-Tarjan algorithm for computing dominators.
Description:
Computes the dominator tree of a control flow graph. Node A dominates node B if every path from the entry to B must go through A. Key Concepts: - Immediate dominator (idom): Closest dominator to a node - Dominator tree: Tree where parent is immediate dominator - Semi-dominator: Used in the algorithm to compute idom Use Cases: - Control flow analysis - Identifying critical code paths - Compiler optimizations (SSA form) - Dead code detection
Thread Safety: Safe for concurrent use.
func NewDominators ¶
func NewDominators(config *DominatorsConfig) *Dominators
NewDominators creates a new Dominators algorithm.
func (*Dominators) HealthCheck ¶
func (d *Dominators) HealthCheck(ctx context.Context) error
HealthCheck verifies the algorithm is functioning.
func (*Dominators) InputType ¶
func (d *Dominators) InputType() reflect.Type
InputType returns the expected input type.
func (*Dominators) Metrics ¶
func (d *Dominators) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*Dominators) OutputType ¶
func (d *Dominators) OutputType() reflect.Type
OutputType returns the output type.
func (*Dominators) Process ¶
func (d *Dominators) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process computes the dominator tree.
Description:
Implements a simplified version of the Lengauer-Tarjan algorithm to compute immediate dominators for all nodes reachable from entry.
Thread Safety: Safe for concurrent use.
func (*Dominators) ProgressInterval ¶
func (d *Dominators) ProgressInterval() time.Duration
ProgressInterval returns how often to report progress.
func (*Dominators) Properties ¶
func (d *Dominators) Properties() []eval.Property
Properties returns the correctness properties.
func (*Dominators) SupportsPartialResults ¶
func (d *Dominators) SupportsPartialResults() bool
SupportsPartialResults returns true.
func (*Dominators) Timeout ¶
func (d *Dominators) Timeout() time.Duration
Timeout returns the maximum execution time.
type DominatorsConfig ¶
type DominatorsConfig struct {
// MaxNodes limits the number of nodes to process.
MaxNodes int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
DominatorsConfig configures the dominators algorithm.
func DefaultDominatorsConfig ¶
func DefaultDominatorsConfig() *DominatorsConfig
DefaultDominatorsConfig returns the default configuration.
type DominatorsInput ¶
type DominatorsInput struct {
// Entry is the entry node of the graph.
Entry string
// Nodes is the list of all node IDs.
Nodes []string
// Successors maps each node to its successors.
Successors map[string][]string
// Source indicates where the request originated.
Source crs.SignalSource
}
DominatorsInput is the input for dominator computation.
type DominatorsOutput ¶
type DominatorsOutput struct {
// IDom maps each node to its immediate dominator.
// The entry node has no immediate dominator.
IDom map[string]string
// DominatorTree maps each node to its children in the dominator tree.
DominatorTree map[string][]string
// DominanceFrontier maps each node to its dominance frontier.
DominanceFrontier map[string][]string
// DFSOrder is the nodes in DFS pre-order.
DFSOrder []string
// NodesReachable is the number of nodes reachable from entry.
NodesReachable int
// TreeDepth is the maximum depth of the dominator tree.
TreeDepth int
}
DominatorsOutput is the output from dominator computation.
type TarjanConfig ¶
type TarjanConfig struct {
// MaxNodes limits the number of nodes to process.
MaxNodes int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
TarjanConfig configures the Tarjan algorithm.
func DefaultTarjanConfig ¶
func DefaultTarjanConfig() *TarjanConfig
DefaultTarjanConfig returns the default configuration.
type TarjanInput ¶
type TarjanInput struct {
// Nodes is the list of node IDs in the graph.
Nodes []string
// Edges maps each node to its outgoing edges (adjacency list).
Edges map[string][]string
// Source indicates where the request originated.
Source crs.SignalSource
}
TarjanInput is the input for Tarjan SCC detection.
type TarjanOutput ¶
type TarjanOutput struct {
// SCCs is the list of strongly connected components.
// Each SCC is a list of node IDs.
SCCs [][]string
// NodeToSCC maps each node to its SCC index.
NodeToSCC map[string]int
// Cyclic is true if any SCC has more than one node.
Cyclic bool
// LargestSCCSize is the size of the largest SCC.
LargestSCCSize int
// NodesProcessed is the number of nodes visited.
NodesProcessed int
// TopologicalOrder is the SCCs in reverse topological order.
// (each SCC can be treated as a single node in the DAG)
TopologicalOrder []int
}
TarjanOutput is the output from Tarjan SCC detection.
type TarjanSCC ¶
type TarjanSCC struct {
// contains filtered or unexported fields
}
TarjanSCC implements Tarjan's algorithm for finding strongly connected components.
Description:
Tarjan's algorithm finds all strongly connected components (SCCs) in a directed graph. An SCC is a maximal set of vertices such that there is a path from each vertex to every other vertex. Key Concepts: - DFS-based single pass algorithm - Uses lowlink values to identify component roots - Linear time complexity O(V + E) Use Cases: - Detect cycles in code dependencies - Identify mutually recursive functions - Analyze call graph structure - Find circular imports
Thread Safety: Safe for concurrent use.
func NewTarjanSCC ¶
func NewTarjanSCC(config *TarjanConfig) *TarjanSCC
NewTarjanSCC creates a new Tarjan SCC algorithm.
func (*TarjanSCC) HealthCheck ¶
HealthCheck verifies the algorithm is functioning.
func (*TarjanSCC) Metrics ¶
func (t *TarjanSCC) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*TarjanSCC) OutputType ¶
OutputType returns the output type.
func (*TarjanSCC) Process ¶
func (t *TarjanSCC) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process finds all strongly connected components.
Description:
Executes Tarjan's algorithm to find all SCCs in the input graph. Returns SCCs in reverse topological order.
Thread Safety: Safe for concurrent use.
func (*TarjanSCC) ProgressInterval ¶
ProgressInterval returns how often to report progress.
func (*TarjanSCC) Properties ¶
Properties returns the correctness properties.
func (*TarjanSCC) SupportsPartialResults ¶
SupportsPartialResults returns true.
type VF2 ¶
type VF2 struct {
// contains filtered or unexported fields
}
VF2 implements the VF2 algorithm for subgraph isomorphism.
Description:
VF2 determines if a pattern graph is isomorphic to a subgraph of a target graph. It uses a state-space representation with feasibility rules to prune the search space. Key Concepts: - State: Partial mapping from pattern nodes to target nodes - Candidate pairs: Nodes that can extend the current mapping - Feasibility: Rules to check if a pair can be added - Backtracking: Systematic search with pruning Use Cases: - Finding code patterns in AST - Detecting design patterns - Clone detection - API usage pattern matching
Thread Safety: Safe for concurrent use.
func (*VF2) HealthCheck ¶
HealthCheck verifies the algorithm is functioning.
func (*VF2) Metrics ¶
func (v *VF2) Metrics() []eval.MetricDefinition
Metrics returns the metrics this algorithm exposes.
func (*VF2) OutputType ¶
OutputType returns the output type.
func (*VF2) Process ¶
func (v *VF2) Process(ctx context.Context, snapshot crs.Snapshot, input any) (any, crs.Delta, error)
Process performs subgraph isomorphism search.
Description:
Uses the VF2 algorithm to find all subgraphs in target that are isomorphic to the pattern graph.
Thread Safety: Safe for concurrent use.
func (*VF2) ProgressInterval ¶
ProgressInterval returns how often to report progress.
func (*VF2) Properties ¶
Properties returns the correctness properties.
func (*VF2) SupportsPartialResults ¶
SupportsPartialResults returns true.
type VF2Config ¶
type VF2Config struct {
// MaxMatches limits the number of matches to find.
// Set to 0 for unlimited (find all matches).
MaxMatches int
// MaxIterations limits the search iterations.
MaxIterations int
// Timeout is the maximum execution time.
Timeout time.Duration
// ProgressInterval is how often to report progress.
ProgressInterval time.Duration
}
VF2Config configures the VF2 algorithm.
func DefaultVF2Config ¶
func DefaultVF2Config() *VF2Config
DefaultVF2Config returns the default configuration.
type VF2Graph ¶
type VF2Graph struct {
// Nodes is the list of node IDs.
Nodes []string
// Edges maps each node to its outgoing edges.
Edges map[string][]string
// NodeLabels maps node IDs to their labels (for semantic matching).
NodeLabels map[string]string
}
VF2Graph represents a labeled directed graph.
type VF2Input ¶
type VF2Input struct {
// Pattern is the smaller graph to find.
Pattern VF2Graph
// Target is the larger graph to search in.
Target VF2Graph
// NodeMatcher is an optional function to check node compatibility.
// If nil, all nodes are considered compatible.
NodeMatcher func(patternNode, targetNode string, patternLabels, targetLabels map[string]string) bool
// Source indicates where the request originated.
Source crs.SignalSource
}
VF2Input is the input for VF2 subgraph isomorphism.
type VF2Output ¶
type VF2Output struct {
// IsIsomorphic is true if at least one match was found.
IsIsomorphic bool
// Matches is the list of found isomorphisms.
// Each match maps pattern node IDs to target node IDs.
Matches []map[string]string
// MatchCount is the total number of matches found.
MatchCount int
// IterationsUsed is the number of search iterations.
IterationsUsed int
// PrunedStates is the number of states pruned by feasibility rules.
PrunedStates int
// SearchComplete is true if the entire search space was explored.
SearchComplete bool
}
VF2Output is the output from VF2.