Documentation
¶
Index ¶
- func ComputeCouplingMetrics(g DirectedGraph, config CouplingConfig) (map[string]*CouplingMetrics, error)
- type CouplingConfig
- type CouplingMetrics
- type CycleDetector
- type CycleResult
- type DirectedGraph
- type MapGraph
- func (g *MapGraph) AddEdge(from, to string)
- func (g *MapGraph) AddNode(id string)
- func (g *MapGraph) HasNode(nodeID string) bool
- func (g *MapGraph) NodeCount() int
- func (g *MapGraph) NodeIDs() []string
- func (g *MapGraph) Predecessors(nodeID string) []string
- func (g *MapGraph) Successors(nodeID string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeCouplingMetrics ¶
func ComputeCouplingMetrics(g DirectedGraph, config CouplingConfig) (map[string]*CouplingMetrics, error)
ComputeCouplingMetrics computes Robert Martin's coupling metrics for all nodes in the directed graph.
Types ¶
type CouplingConfig ¶
type CouplingConfig struct {
// AbstractnessFunc computes the abstractness (0.0–1.0) for a given node.
// pyscn: ratio of public names matching abstract patterns.
// jscan: export ratio.
// If nil, Abstractness defaults to 0.0 for all nodes.
AbstractnessFunc func(nodeID string) (float64, error)
}
CouplingConfig configures coupling metric computation.
type CouplingMetrics ¶
type CouplingMetrics struct {
NodeID string
Ca int // Afferent coupling (incoming edges)
Ce int // Efferent coupling (outgoing edges)
Instability float64 // Ce / (Ca + Ce), 0 = maximally stable
Abstractness float64 // Provided by language-specific callback
Distance float64 // |Abstractness + Instability - 1|
}
CouplingMetrics holds Robert Martin's package coupling metrics for a node.
type CycleDetector ¶
type CycleDetector struct {
// contains filtered or unexported fields
}
CycleDetector finds strongly connected components using Tarjan's algorithm.
func NewCycleDetector ¶
func NewCycleDetector() *CycleDetector
NewCycleDetector creates a new CycleDetector.
func (*CycleDetector) DetectCycles ¶
func (d *CycleDetector) DetectCycles(g DirectedGraph) *CycleResult
DetectCycles finds all cycles (SCCs with size > 1) in the directed graph.
type CycleResult ¶
type CycleResult struct {
// Cycles contains all strongly connected components with more than one node.
Cycles [][]string
// HasCycles is true if any cycle was found.
HasCycles bool
// AffectedNodes contains all nodes that participate in at least one cycle.
AffectedNodes map[string]bool
}
CycleResult holds the result of cycle detection via Tarjan's SCC algorithm.
type DirectedGraph ¶
type DirectedGraph interface {
// NodeIDs returns all node identifiers in the graph.
NodeIDs() []string
// Successors returns the IDs of nodes that this node has edges to.
Successors(nodeID string) []string
// Predecessors returns the IDs of nodes that have edges to this node.
Predecessors(nodeID string) []string
// NodeCount returns the number of nodes in the graph.
NodeCount() int
// HasNode returns true if the node exists in the graph.
HasNode(nodeID string) bool
}
DirectedGraph provides read-only access to a directed graph. pyscn's DependencyGraph (map[string]*ModuleNode) and jscan's domain.DependencyGraph (method-based) can both implement this.
type MapGraph ¶
type MapGraph struct {
// contains filtered or unexported fields
}
MapGraph is a simple directed graph implementation backed by maps. Useful for testing and as a default implementation.
func (*MapGraph) AddEdge ¶
AddEdge adds a directed edge from → to. Both nodes are created if absent.
func (*MapGraph) Predecessors ¶
Predecessors returns the IDs of nodes that have an edge to nodeID.
func (*MapGraph) Successors ¶
Successors returns the IDs of nodes reachable by one edge from nodeID.