LANG-1277: StringUtils#getLevenshteinDistance reduce memory consumption

minimal clean-up

add changes.xml entry
This commit is contained in:
pascalschumacher 2016-10-20 21:51:01 +02:00
parent 103b64a373
commit 6423a76655
2 changed files with 9 additions and 15 deletions

View File

@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body> <body>
<release version="3.6" date="tba" description="tba"> <release version="3.6" date="tba" description="tba">
<action issue="LANG-1277" type="update" dev="pschumacher" due-to="yufcuy">StringUtils#getLevenshteinDistance reduce memory consumption</action>
<action issue="LANG-1070" type="fix" dev="pschumacher" due-to="Paul Pogonyshev">ArrayUtils#add confusing example in javadoc</action> <action issue="LANG-1070" type="fix" dev="pschumacher" due-to="Paul Pogonyshev">ArrayUtils#add confusing example in javadoc</action>
<action issue="LANG-1271" type="fix" dev="pschumacher" due-to="Pierre Templier">StringUtils#isAnyEmpty and #isAnyBlank should return false for an empty array</action> <action issue="LANG-1271" type="fix" dev="pschumacher" due-to="Pierre Templier">StringUtils#isAnyEmpty and #isAnyBlank should return false for an empty array</action>
<action issue="LANG-1270" type="add" dev="pschumacher" due-to="Pierre Templier">Add StringUtils#isAnyNotEmpty and #isAnyNotBlank</action> <action issue="LANG-1270" type="add" dev="pschumacher" due-to="Pierre Templier">Add StringUtils#isAnyNotEmpty and #isAnyNotBlank</action>

View File

@ -7736,11 +7736,9 @@ public class StringUtils {
* another, where each change is a single character modification (deletion, * another, where each change is a single character modification (deletion,
* insertion or substitution).</p> * insertion or substitution).</p>
* *
* <p>The previous implementation of the Levenshtein distance algorithm * <p>The implementation uses a single-dimensional array of length s.length() + 1. See
* was from <a href="https://web.archive.org/web/20120526085419/http://www.merriampark.com/ldjava.htm"> * <a href="http://blog.softwx.net/2014/12/optimizing-levenshtein-algorithm-in-c.html">
* https://web.archive.org/web/20120526085419/http://www.merriampark.com/ldjava.htm</a></p> * http://blog.softwx.net/2014/12/optimizing-levenshtein-algorithm-in-c.html</a> for details.</p>
*
* <p>This implementation only need one single-dimensional arrays of length s.length() + 1</p>
* *
* <pre> * <pre>
* StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException * StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException
@ -7768,13 +7766,8 @@ public class StringUtils {
throw new IllegalArgumentException("Strings must not be null"); throw new IllegalArgumentException("Strings must not be null");
} }
/* int n = s.length();
This implementation use two variable to record the previous cost counts, int m = t.length();
So this implementation use less memory than previous impl.
*/
int n = s.length(); // length of s
int m = t.length(); // length of t
if (n == 0) { if (n == 0) {
return m; return m;
@ -7799,7 +7792,7 @@ public class StringUtils {
int upper; int upper;
char t_j; // jth character of t char t_j; // jth character of t
int cost; // cost int cost;
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
p[i] = i; p[i] = i;