Applying Cedrik Lime's patch to LANG-413; improving the memory footprint of getLevenshteinDistance

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@630580 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2008-02-24 03:33:49 +00:00
parent 5cbca4d5f5
commit 68c6547d0c
1 changed files with 9 additions and 0 deletions

View File

@ -5737,6 +5737,15 @@ allows us to retain the previous cost counts as required by the algorithm (takin
return n; return n;
} }
if (n > m) {
// swap the input strings to consume less memory
String tmp = s;
s = t;
t = tmp;
n = m;
m = t.length();
}
int p[] = new int[n+1]; //'previous' cost array, horizontally int p[] = new int[n+1]; //'previous' cost array, horizontally
int d[] = new int[n+1]; // cost array, horizontally int d[] = new int[n+1]; // cost array, horizontally
int _d[]; //placeholder to assist in swapping p and d int _d[]; //placeholder to assist in swapping p and d