private static int limitedLevenshtein(final String str1,final String str2,int idx1,int idx2,final int limit){
  while (true) {
    if (idx1 == str1.length()) {
      return str2.length() - idx2;
    }
 else     if (idx2 == str2.length()) {
      return str1.length() - idx1;
    }
 else     if (str1.charAt(idx1) != str2.charAt(idx2)) {
      if (limit < 1) {
        return 1;
      }
 else {
        return 1 + bestLimLev(str1,str2,idx1,idx2,limit - 1);
      }
    }
    ++idx1;
    ++idx2;
  }
}

private static int limitedLevenshtein ( final String str1 , final String str2 , int idx1 , int idx2 , final int limit ) { while ( true ) { if ( idx1 == str1 . length ( ) ) { return str2 . length ( ) - idx2 ; } else if ( idx2 == str2 . length ( ) ) { return str1 . length ( ) - idx1 ; } else if ( str1 . charAt ( idx1 ) != str2 . charAt ( idx2 ) ) { if ( limit < 1 ) { return 1 ; } else { return 1 + bestLimLev ( str1 , str2 , idx1 , idx2 , limit - 1 ) ; } } ++ idx1 ; ++ idx2 ; } }
calculate the levenshtein distance of two strings using index arithmetic given a maximum distance value to terminate calculation . this is not exactly the levenshtein algorithm , but fits our need to quickly look for similar strings .
