LANG-1234: getLevenshteinDistance with a threshold: optimize implementation if the strings lengths differ more than the threshold (closes #118)
If the string lengths differ more than the threshold, there's no need for the algorithm to begin allocating arrays etc.
This commit is contained in:
parent
031f6b082f
commit
04b41e2c97
|
@ -7585,6 +7585,10 @@ distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only
|
|||
} else if (m == 0) {
|
||||
return n <= threshold ? n : -1;
|
||||
}
|
||||
// no need to calculate the distance if the length difference is greater than the threshold
|
||||
else if (Math.abs(n - m) > threshold) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n > m) {
|
||||
// swap the two strings to consume less memory
|
||||
|
|
Loading…
Reference in New Issue