Upgrade dependent version: github.com/open-policy-agent/opa (#5315)
Upgrade dependent version: github.com/open-policy-agent/opa v0.18.0 -> v0.45.0 Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
75
vendor/github.com/agnivade/levenshtein/levenshtein.go
generated
vendored
Normal file
75
vendor/github.com/agnivade/levenshtein/levenshtein.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// Package levenshtein is a Go implementation to calculate Levenshtein Distance.
|
||||
//
|
||||
// Implementation taken from
|
||||
// https://gist.github.com/andrei-m/982927#gistcomment-1931258
|
||||
package levenshtein
|
||||
|
||||
import "unicode/utf8"
|
||||
|
||||
// ComputeDistance computes the levenshtein distance between the two
|
||||
// strings passed as an argument. The return value is the levenshtein distance
|
||||
//
|
||||
// Works on runes (Unicode code points) but does not normalize
|
||||
// the input strings. See https://blog.golang.org/normalization
|
||||
// and the golang.org/x/text/unicode/norm pacage.
|
||||
func ComputeDistance(a, b string) int {
|
||||
if len(a) == 0 {
|
||||
return utf8.RuneCountInString(b)
|
||||
}
|
||||
|
||||
if len(b) == 0 {
|
||||
return utf8.RuneCountInString(a)
|
||||
}
|
||||
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
|
||||
// We need to convert to []rune if the strings are non-ascii.
|
||||
// This could be avoided by using utf8.RuneCountInString
|
||||
// and then doing some juggling with rune indices.
|
||||
// The primary challenge is keeping track of the previous rune.
|
||||
// With a range loop, its not that easy. And with a for-loop
|
||||
// we need to keep track of the inter-rune width using utf8.DecodeRuneInString
|
||||
s1 := []rune(a)
|
||||
s2 := []rune(b)
|
||||
|
||||
// swap to save some memory O(min(a,b)) instead of O(a)
|
||||
if len(s1) > len(s2) {
|
||||
s1, s2 = s2, s1
|
||||
}
|
||||
lenS1 := len(s1)
|
||||
lenS2 := len(s2)
|
||||
|
||||
// init the row
|
||||
x := make([]int, lenS1+1)
|
||||
for i := 0; i <= lenS1; i++ {
|
||||
x[i] = i
|
||||
}
|
||||
|
||||
// fill in the rest
|
||||
for i := 1; i <= lenS2; i++ {
|
||||
prev := i
|
||||
var current int
|
||||
|
||||
for j := 1; j <= lenS1; j++ {
|
||||
|
||||
if s2[i-1] == s1[j-1] {
|
||||
current = x[j-1] // match
|
||||
} else {
|
||||
current = min(min(x[j-1]+1, prev+1), x[j]+1)
|
||||
}
|
||||
x[j-1] = prev
|
||||
prev = current
|
||||
}
|
||||
x[lenS1] = prev
|
||||
}
|
||||
return x[lenS1]
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user