similarity

package
v0.0.0-...-736eb86 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevenshteinDistance

func LevenshteinDistance(s1, s2 string) int

LevenshteinDistance calculates the Levenshtein distance between two strings.

func NormalizeTokenSequence

func NormalizeTokenSequence(function *ast.Function) []string

NormalizeTokenSequence extracts a normalized token sequence from a function.

func TokenSequenceSimilarity

func TokenSequenceSimilarity(func1, func2 *ast.Function) float64

TokenSequenceSimilarity calculates similarity between two functions based on token sequences.

func TreeEditDistance

func TreeEditDistance(node1, node2 goast.Node) int

TreeEditDistance calculates the edit distance between two AST nodes. This implements a simplified tree edit distance algorithm.

Types

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector handles similarity detection between functions.

func NewDetector

func NewDetector(threshold float64) *Detector

NewDetector creates a new similarity detector with the given threshold and configuration.

func NewDetectorWithConfig

func NewDetectorWithConfig(threshold float64, cfg *config.Config) *Detector

NewDetectorWithConfig creates a new similarity detector with explicit configuration.

func (*Detector) CalculateSimilarity

func (d *Detector) CalculateSimilarity(func1, func2 *ast.Function) float64

CalculateSimilarity calculates the similarity between two functions Returns a value between 0.0 (completely different) and 1.0 (identical).

func (*Detector) FindSimilarFunctions

func (d *Detector) FindSimilarFunctions(functions []*ast.Function) []Match

FindSimilarFunctions finds all similar function pairs above the threshold.

func (*Detector) FindSimilarFunctionsWithProcessor

func (d *Detector) FindSimilarFunctionsWithProcessor(
	processor ParallelProcessor,
	functions []*ast.Function,
	progressCallback func(completed, total int),
) ([]Match, error)

FindSimilarFunctionsWithProcessor finds similar functions using a provided parallel processor.

func (*Detector) IsAboveThreshold

func (d *Detector) IsAboveThreshold(similarity float64) bool

IsAboveThreshold checks if similarity is above the configured threshold.

type Match

type Match struct {
	Function1  *ast.Function
	Function2  *ast.Function
	Similarity float64
}

Match represents a match between two similar functions.

type ParallelProcessor

type ParallelProcessor interface {
	FindSimilarFunctions(functions []*ast.Function, progressCallback func(completed, total int)) ([]Match, error)
}

ParallelProcessor defines the interface for parallel similarity processing.

Jump to

Keyboard shortcuts

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