\
    Get the Levenshtein distance between two strings.

    :param first:     the first string
    :param second:    the second string
19260
def get_levenshtein(first, second):
    
    if not first:
        return len(second)

    if not second:
        return len(first)

    prev_distances = range(0, len(second) + 1)
    curr_distances = None

    # Find the minimum edit distance between each substring of 'first' and
    # the entirety of 'second'. The first column of each distance list is
    # the distance from the current string to the empty string.
    for first_idx, first_char in enumerate(first, start=1):
        # Keep only the previous and current rows of the
        # lookup table in memory
        curr_distances = [first_idx]

        for second_idx, second_char in enumerate(second, start=1):
            # Take the max of the neighbors
            compare = [
                prev_distances[second_idx - 1],
                prev_distances[second_idx],
                curr_distances[second_idx - 1],
            ]

            distance = min(*compare)

            if first_char != second_char:
                distance += 1

            curr_distances.append(distance)

        prev_distances = curr_distances

    return curr_distances[-1]
747035
public int compare(final T first, final T second) {
    if (first.equals(second)) return 0;
    else return first.size() - second.size();
  }
1338509
public String differenceBetweenIgnoreWhitespaceAnd(String first, String second) {
        String cleanFirst = allWhitespaceToSingleSpace(first);
        String cleanSecond = allWhitespaceToSingleSpace(second);
        String cleanDiff = differenceBetweenAnd(cleanFirst, cleanSecond);
        if (cleanDiff != null) {
            if (("<div>"+ cleanFirst + "</div>").equals(cleanDiff)) {
                cleanDiff = "<div>" + first + "</div>";
            } else if (cleanFirst != null && cleanFirst.equals(cleanDiff)) {
                cleanDiff = first;
            }
        }
        return cleanDiff;
    }
554230
def hamming_distance(s1, s2):
    
    if len(s1) != len(s2):
        raise ValueError("Undefined for sequences of unequal length")
    return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
939244
public int DamerauLevenshteinDistance(String string2, int maxDistance) {
        if (baseString == null) return string2 == null ? 0 : string2.length(); //string2 ?? "").Length;
        if (string2 == null || string2.isEmpty()) return baseString.length();
        if(maxDistance == 0) return baseString.equals(string2) ? 0 : -1;

        // if strings of different lengths, ensure shorter string is in string1. This can result in a little
        // faster speed by spending more time spinning just the inner loop during the main processing.
        String string1;
        if (baseString.length() > string2.length()) {
            string1 = string2;
            string2 = baseString;
        } else {
            string1 = baseString;
        }
        int sLen = string1.length(); // this is also the minimun length of the two strings
        int tLen = string2.length();

        // suffix common to both strings can be ignored
        while ((sLen > 0) && (string1.charAt(sLen - 1) == string2.charAt(tLen - 1))) { sLen--; tLen--; }

        int start = 0;
        if ((string1.charAt(0) == string2.charAt(0)) || (sLen == 0)) { // if there'string1 a shared prefix, or all string1 matches string2'string1 suffix
            // prefix common to both strings can be ignored
            while ((start < sLen) && (string1.charAt(start) == string2.charAt(start))) start++;
            sLen -= start; // length of the part excluding common prefix and suffix
            tLen -= start;

            // if all of shorter string matches prefix and/or suffix of longer string, then
            // edit distance is just the delete of additional characters present in longer string
            if (sLen == 0) return tLen;

            string2 = string2.substring(start, start + tLen); // faster than string2[start+j] in inner loop below
        }
        int lenDiff = tLen - sLen;
        if ((maxDistance < 0) || (maxDistance > tLen)) {
            maxDistance = tLen;
        } else if (lenDiff > maxDistance) return -1;

        if (tLen > v0.length)
        {
            v0 = new int[tLen];
            v2 = new int[tLen];
        } else {
            for(int i = 0; i < tLen; i++) v2[i] = 0;    // Substituting Array.clear(v2, 0, tLen)
        }
        int j;
        for (j = 0; j < maxDistance; j++) v0[j] = j + 1;
        for (; j < tLen; j++) v0[j] = maxDistance + 1;

        int jStartOffset = maxDistance - (tLen - sLen);
        boolean haveMax = maxDistance < tLen;
        int jStart = 0;
        int jEnd = maxDistance;
        char sChar = string1.charAt(0);
        int current = 0;
        for (int i = 0; i < sLen; i++) {
            char prevsChar = sChar;
            sChar = string1.charAt(start+i);
            char tChar = string2.charAt(0);
            int left = i;
            current = left + 1;
            int nextTransCost = 0;
            // no need to look beyond window of lower right diagonal - maxDistance cells (lower right diag is i - lenDiff)
            // and the upper left diagonal + maxDistance cells (upper left is i)
            jStart += (i > jStartOffset) ? 1 : 0;
            jEnd += (jEnd < tLen) ? 1 : 0;
            for (j = jStart; j < jEnd; j++) {
                int above = current;
                int thisTransCost = nextTransCost;
                nextTransCost = v2[j];
                v2[j] = current = left; // cost of diagonal (substitution)
                left = v0[j];    // left now equals current cost (which will be diagonal at next iteration)
                char prevtChar = tChar;
                tChar = string2.charAt(j);
                if (sChar != tChar) {
                    if (left < current) current = left;   // insertion
                    if (above < current) current = above; // deletion
                    current++;
                    if ((i != 0) && (j != 0)
                            && (sChar == prevtChar)
                            && (prevsChar == tChar)) {
                        thisTransCost++;
                        if (thisTransCost < current) current = thisTransCost; // transposition
                    }
                }
                v0[j] = current;
            }
            if (haveMax && (v0[i + lenDiff] > maxDistance)) return -1;
        }
        return (current <= maxDistance) ? current : -1;
    }
1369516
def distance_between(self, place_1, place_2, unit='km'):
        
        pickled_place_1 = self._pickle(place_1)
        pickled_place_2 = self._pickle(place_2)
        try:
            return self.redis.geodist(
                self.key, pickled_place_1, pickled_place_2, unit=unit
            )
        except TypeError:
            return None
1130384
public static double distance(LatLong latLong1, LatLong latLong2) {
        return Math.hypot(latLong1.longitude - latLong2.longitude, latLong1.latitude - latLong2.latitude);
    }
476901
def levenshtein_distance(self, a, b):
        '''
        '''

        n, m = len(a), len(b)
        if n > m:
            a,b = b,a
            n,m = m,n
        current = range(n+1)
        for i in range(1,m+1):
            previous, current = current, [i]+[0]*n
            for j in range(1,n+1):
                add, delete = previous[j]+1, current[j-1]+1
                change = previous[j-1]
                if a[j-1] != b[i-1]:
                    change = change + 1
                current[j] = min(add, delete, change)
        return current[n]
94144
public static int levenshteinDistance(String o1, String o2) {
    // Let o1 be the shorter one:
    if(o1.length() > o2.length()) {
      return levenshteinDistance(o2, o1);
    }
    final int l1 = o1.length(), l2 = o2.length();
    // Exploit that Java caches the hash code of strings:
    if(l1 == l2 && o1.hashCode() == o2.hashCode() && o1.equals(o2)) {
      return 0;
    }
    // Determine prefix and postfix lengths:
    final int prefix = prefixLen(o1, o2);
    if(prefix == l1 || prefix == l2) {
      return Math.abs(l1 - l2);
    }
    final int postfix = postfixLen(o1, o2, prefix);
    return // Prefix and postfix are a complete object:
    (prefix + postfix == l1 || prefix + postfix == l2) ? Math.abs(l1 - l2) : //
    // Exactly one char difference optimization:
        (l1 == l2 && prefix + postfix + 1 == l1) ? 1 : //
        // Default case, compute
            levenshteinDistance(o1, o2, prefix, postfix);
  }
1292591
def levenshtein_distance_metric(a, b):
    
    return (levenshtein_distance(a, b) / (2.0 * max(len(a), len(b), 1)))
380256
def distance_to(self, other):
        
        if self.overlaps(other):
            return 0
        try:
            if self.begin < other.begin:
                return other.begin - self.end
            else:
                return self.begin - other.end
        except:
            if self.end <= other:
                return other - self.end
            else:
                return self.begin - other
1303497
public static String subtractSeq(final String first, final String second) {
    return subtractSeq(first, second, DELIMITER);
  }
627652
public static String intersectSeq(final String first, final String second, final String delimiter) {
    if (isEmpty(first) || isEmpty(second)) { return ""; }
    List<String> firstSeq = Arrays.asList(split(first, ','));
    List<String> secondSeq = Arrays.asList(split(second, ','));
    Collection<String> rs = CollectUtils.intersection(firstSeq, secondSeq);
    StringBuilder buf = new StringBuilder();
    for (final String ele : rs) {
      buf.append(delimiter).append(ele);
    }
    if (buf.length() > 0) {
      buf.append(delimiter);
    }
    return buf.toString();
  }
1169972
def levenshtein_norm(source, target):
    

    # Compute Levenshtein distance using helper function. The max is always
    # just the length of the longer string, so this is used to normalize result
    # before returning it
    distance = _levenshtein_compute(source, target, False)
    return float(distance) / max(len(source), len(target))
1216601
private static boolean compareDistance(final String title1, final String title2, int distance) {
        return StringUtils.getLevenshteinDistance(title1, title2) <= distance;
    }
724013
def distance(self, other):
        
        return distance((self.separation, self.pa), (other.separation, other.pa))
500501
public static boolean isEqualSeq(final String first, final String second, final String delimiter) {
    if (isNotEmpty(first) && isNotEmpty(second)) {
      String[] firstWords = split(first, delimiter);
      Set<String> firstSet = CollectUtils.newHashSet();
      for (int i = 0; i < firstWords.length; i++) {
        firstSet.add(firstWords[i]);
      }
      String[] secondWords = split(second, delimiter);
      Set<String> secondSet = CollectUtils.newHashSet();
      for (int i = 0; i < secondWords.length; i++) {
        secondSet.add(secondWords[i]);
      }
      return firstSet.equals(secondSet);
    } else {
      return isEmpty(first) & isEmpty(second);
    }
  }