Optimize Jaccard function for set comparisons

This commit is contained in:
CodeMarker
2026-02-05 15:21:22 +08:00
committed by lyingbug
parent 53669876d2
commit 5fda6bc266
+5
View File
@@ -41,6 +41,11 @@ func Jaccard(a, b map[string]struct{}) float64 {
return 0
}
// small set drives large set
if len(a) > len(b) {
return Jaccard(b, a)
}
// Calculate intersection
inter := 0
for k := range a {