Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Jan 31, 2024
1 parent 5f4f6fa commit 929f8b4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,17 +600,22 @@ func likelyDuplicate(ctx context.Context, val []byte, dupes map[string]struct{})
// []byte -> string conversion within a map lookup does not allocate. (due to compiler optimizations)
valStr := string(val)
const similarityThreshold = 0.9
for k := range dupes {
for dupe := range dupes {
// Avoid comparing strings of vastly different lengths.
if len(k)*10 < len(valStr)*9 || len(k)*10 > len(valStr)*11 {
if len(dupe)*10 < len(valStr)*9 || len(dupe)*10 > len(valStr)*11 {
continue
}

similarity := strutil.Similarity(valStr, k, metrics.NewLevenshtein())
similarity := strutil.Similarity(valStr, dupe, metrics.NewLevenshtein())

// close enough
if similarity > similarityThreshold {
ctx.Logger().V(2).Info("found similar duplicate", "val", val, "k", k, "similarity", similarity)
ctx.Logger().V(2).Info(
"found similar duplicate",
"val", val,
"dupe", dupe,
"similarity", similarity,
)
return true
}
}
Expand Down

0 comments on commit 929f8b4

Please sign in to comment.