Debian Codegraph @

fuzzy/levenshtein.go

raw symbols SCIP
1 package fuzzyscip-go gomod github.com/lithammer/fuzzysearch . `github.com/lithammer/fuzzysearch/fuzzy`/
2
3 // LevenshteinDistance measures the difference between two strings.
4 // The Levenshtein distance between two words is the minimum number of
5 // single-character edits (i.e. insertions, deletions or substitutions)
6 // required to change one word into the other.
7 //
8 // This implemention is optimized to use O(min(m,n)) space and is based on the
9 // optimized C version found here:
10 // http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Levenshtein_distance#C
11 func LevenshteinDistancescip-go gomod github.com/lithammer/fuzzysearch . `github.com/lithammer/fuzzysearch/fuzzy`/LevenshteinDistance().(s, t string) int {
12 r1, r2 := []rune(s), []rune(t)
13 column := make([]int, len(r1)+1)
14
15 for y := 1; y <= len(r1); y++ {
16 column[y] = y
17 }
18
19 for x := 1; x <= len(r2); x++ {
20 column[0] = x
21
22 for y, lastDiag := 1, x-1; y <= len(r1); y++ {
23 oldDiag := column[y]
24 cost := 0
25 if r1[y-1] != r2[x-1] {
26 cost = 1
27 }
28 column[y] = minscip-go gomod github.com/lithammer/fuzzysearch . `github.com/lithammer/fuzzysearch/fuzzy`/min().(column[y]+1, column[y-1]+1, lastDiag+cost)
29 lastDiag = oldDiag
30 }
31 }
32
33 return column[len(r1)]
34 }
35
36 func minscip-go gomod github.com/lithammer/fuzzysearch . `github.com/lithammer/fuzzysearch/fuzzy`/min().(a, b, c int) int {
37 if a < b && a < c {
38 return a
39 } else if b < c {
40 return b
41 }
42 return c
43 }