spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8830][SQL] native levenshtein distance
Date Thu, 09 Jul 2015 04:40:07 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7236#discussion_r34223127
  
    --- Diff: unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
    @@ -254,6 +254,67 @@ public boolean equals(final Object other) {
         }
       }
     
    +  /**
    +   * Levenshtein distance is a metric for measuring the distance of two strings. The
distance is
    +   * defined by the minimum number of single-character edits (i.e. insertions, deletions
or
    +   * substitutions) that are required to change one of the strings into the other.
    +   */
    +  public int levenshteinDistance(UTF8String other) {
    +    // Implementation adopted from org.apache.common.lang3.StringUtils.getLevenshteinDistance
    +
    +    int n = numChars();
    +    int m = other.numChars();
    +
    +    if (n == 0) {
    +      return m;
    +    } else if (m == 0) {
    +      return n;
    +    }
    +
    +    UTF8String s, t;
    +
    +    if (n <= m) {
    +      s = this;
    +      t = other;
    +    } else {
    +      s = other;
    +      t = this;
    +      n = s.numChars();
    --- End diff --
    
    It's better to swap n and m, because `numChar()` is not cheap.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message