Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7236#discussion_r33977873
--- Diff:
unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
@@ -207,6 +207,78 @@ public boolean equals(final Object other) {
}
}
+ private char charAt(int bytePos) {
+ int num = numBytes(bytes[bytePos]);
+ if (num == 1) return (char) bytes[bytePos];
+ int l = bytes[bytePos] & 0x000F;
+ l = l << 8 + num + 1 >> 8 + num + 1;
+ for (int i = 1; i < num; i++) {
+ l = l << 6;
+ l = l | (0x003F & bytes[bytePos + i]);
+ }
+ return (char) l;
+ }
+
+ public int levenshteinDistance(UTF8String other) {
+ // Implementation adopted from
org.apache.common.lang3.StringUtils.getLevenshteinDistance
+
+ int n = length();
+ int m = other.length();
+
+ if (n == 0) {
+ return m;
+ } else if (m == 0) {
+ return n;
+ }
+
+ UTF8String s;
+ UTF8String t;
+
+ if (n <= m) {
+ s = this;
+ t = other;
+ } else {
+ s = other;
+ t = this;
+ n = s.length();
+ m = t.length();
+ }
+
+ int p[] = new int[n + 1];
--- End diff --
actually this one is probably ok -- I think JIT with the proper escape
analysis can do on-stack allocation for this.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]