// Calculates the fuzzy match of needle in haystack, // using a modified version of the Levenshtein distance algorithm. // ported from: http://ginstrom.com/scribbles/2007/12/01/fuzzy-substring-matching-with-levenshtein-distance-in-python/ static int levenSubstringIC(S haystack, S needle) { int m = strL(needle), n = strL(haystack); // base cases if (containsIgnoreCase(haystack, needle)) ret 0; int[] v0 = new int[n+1], v1 = new int[n+1]; for i to m: { // iterate over needle v1[0] = i+1; for j to n: { // iterate over haystack int cost = neqic(needle.charAt(i), haystack.charAt(j)) ? 1 : 0; v1[j+1] = min3(v1[j]+1, // insertion v0[j+1]+1, // deletion v0[j]+cost); // substitution } int[] temp = v0; v0 = v1; v1 = temp; } ret minOfIntArray(v0); }