jackye1995 commented on a change in pull request #1946:
URL: https://github.com/apache/iceberg/pull/1946#discussion_r555395631



##########
File path: api/src/main/java/org/apache/iceberg/types/Comparators.java
##########
@@ -272,6 +276,30 @@ public int compare(ByteBuffer buf1, ByteBuffer buf2) {
     }
   }
 
+  private static class UnsignedByteArrayComparator implements 
Comparator<byte[]> {
+    private static final UnsignedByteArrayComparator INSTANCE = new 
UnsignedByteArrayComparator();
+
+    private UnsignedByteArrayComparator() {
+    }
+
+    @Override
+    public int compare(byte[] array1, byte[] array2) {
+      int len = Math.min(array1.length, array2.length);
+
+      // find the first difference and return
+      for (int i = 0; i < len; i += 1) {
+        // Conversion to int is what Byte.toUnsignedInt would do
+        int cmp = Integer.compare(((int) array1[i]) & 0xff, ((int) array2[i]) 
& 0xff);
+        if (cmp != 0) {
+          return cmp;
+        }
+      }
+
+      // if there are no differences, then the shorter seq is first

Review comment:
       nit: "the shorter seq is first" is a bit confusing to me, maybe "is 
smaller" is a better word.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to