summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/blevesearch/bleve/search/levenshtein.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/blevesearch/bleve/search/levenshtein.go')
-rw-r--r--vendor/github.com/blevesearch/bleve/search/levenshtein.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/vendor/github.com/blevesearch/bleve/search/levenshtein.go b/vendor/github.com/blevesearch/bleve/search/levenshtein.go
index ec033143af..687608d3ff 100644
--- a/vendor/github.com/blevesearch/bleve/search/levenshtein.go
+++ b/vendor/github.com/blevesearch/bleve/search/levenshtein.go
@@ -57,15 +57,24 @@ func LevenshteinDistance(a, b string) int {
// in which case the first return val will be the max
// and the second will be true, indicating max was exceeded
func LevenshteinDistanceMax(a, b string, max int) (int, bool) {
+ v, wasMax, _ := LevenshteinDistanceMaxReuseSlice(a, b, max, nil)
+ return v, wasMax
+}
+
+func LevenshteinDistanceMaxReuseSlice(a, b string, max int, d []int) (int, bool, []int) {
la := len(a)
lb := len(b)
ld := int(math.Abs(float64(la - lb)))
if ld > max {
- return max, true
+ return max, true, d
}
- d := make([]int, la+1)
+ if cap(d) < la+1 {
+ d = make([]int, la+1)
+ }
+ d = d[:la+1]
+
var lastdiag, olddiag, temp int
for i := 1; i <= la; i++ {
@@ -98,8 +107,8 @@ func LevenshteinDistanceMax(a, b string, max int) (int, bool) {
}
// after each row if rowmin isn't less than max stop
if rowmin > max {
- return max, true
+ return max, true, d
}
}
- return d[la], false
+ return d[la], false, d
}