AngersZhuuuu commented on a change in pull request #34848:
URL: https://github.com/apache/spark/pull/34848#discussion_r782680699
##########
File path:
common/unsafe/src/main/java/org/apache/spark/unsafe/array/ByteArrayMethods.java
##########
@@ -91,4 +91,64 @@ public static boolean arrayEquals(
}
return true;
}
+
+ public static boolean contains(byte[] array, byte[] target) {
+ if (target.length == 0) {
+ return true;
+ } else if (array.length == 0) {
+ return false;
+ } else if (target.length > array.length) {
+ return false;
+ } else {
+ return indexOf(array, target) >= 0;
+ }
+ }
+
+ public static boolean startsWith(byte[] array, byte[] target) {
+ if (target.length == 0) {
+ return true;
+ } else if (array.length == 0) {
+ return false;
+ } else if (target.length > array.length) {
+ return false;
+ } else {
+ return indexOf(array, target) == 0;
+ }
+ }
+
+ public static boolean endsWith(byte[] array, byte[] target) {
+ if (target.length == 0) {
+ return true;
+ } else if (array.length == 0) {
+ return false;
+ } else if (target.length > array.length) {
+ return false;
+ } else {
+ int endPos = array.length - target.length;
+ for (int i = 0; i < target.length; ++i) {
+ if (array[endPos + i] != target[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
Review comment:
Updated with same method like `UTF8String`, so performance is not a
concern?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]