Documentation
¶
Overview ¶
Package detection provides multi-method code duplication detection.
This package coordinates multiple detection algorithms and combines their results to provide comprehensive duplicate reporting.
Detection Methods Supported: - DetectionMethodArtDupl: Suffix tree algorithm on AST tokens - DetectionMethodHash: Rolling hash on file content
Core Types: - MultiDetector: Coordinates multiple detection methods - MethodDetector: Interface for individual detection algorithms
Usage:
cfg := detection.Config{Methods: []string{detection.MethodArtDupl}, Verbose: verbose}
md := detection.NewMultiDetector(cfg, data, tree)
matches := md.FindDuplOver(ctx, threshold)
Index ¶
Constants ¶
const ( MethodArtDupl = domain.MethodArtDupl MethodHash = domain.MethodHash )
Detection method name constants — aliases for domain.DetectionMethod to prevent drift across packages.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.4.0
type Config struct {
// Methods specifies which detection algorithms to run.
// Accepted values: MethodArtDupl, MethodHash.
// Empty means use the default (art-dupl only).
Methods []domain.DetectionMethod
// Verbose enables detailed logging during detection.
Verbose bool
}
Config configures the MultiDetector's behavior.
type MethodDetector ¶
type MethodDetector interface {
// FindDuplOver runs detection with the given threshold and returns
// matches via a channel for streaming consumption.
// The context allows callers to cancel detection early.
FindDuplOver(ctx context.Context, threshold int) <-chan syntax.Match
// Name returns a human-readable name for the detection method.
Name() string
}
MethodDetector is the interface that all detection algorithms implement. Each detector produces a stream of syntax.Match results for duplicate code.
type MultiDetector ¶
type MultiDetector struct {
// contains filtered or unexported fields
}
MultiDetector runs multiple detection methods and combines results.
func NewMultiDetector ¶
func NewMultiDetector( cfg Config, data []*syntax.Node, tree *suffixtree.STree, ) *MultiDetector
NewMultiDetector creates a new multi-method detector.
func (*MultiDetector) FindDuplOver ¶
FindDuplOver runs all configured clone detection methods and streams matches. The ctx is checked on every channel send — if cancelled, the goroutine exits early to prevent goroutine leaks.