dweiss commented on a change in pull request #349:
URL: https://github.com/apache/lucene/pull/349#discussion_r721382416



##########
File path: lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java
##########
@@ -656,4 +657,40 @@ protected int comparePivot(int j) {
     System.arraycopy(array, from, copy, 0, subLength);
     return copy;
   }
+
+  /** Comparator for a fixed number of bytes. */
+  @FunctionalInterface
+  public static interface ByteArrayComparator {
+
+    /**
+     * Compare bytes starting from the given offsets. The return value has the 
same contract as
+     * {@link Comparator#compare(Object, Object)}.
+     */
+    int compare(byte[] a, int aI, byte[] b, int bI);
+  }
+
+  /** Return a comparator for exactly the specified number of bytes. */
+  public static ByteArrayComparator getUnsignedComparator(int numBytes) {
+    if (numBytes == Long.BYTES) {
+      // Used by LongPoint, DoublePoint
+      return ArrayUtil::compareUnsigned8;
+    } else if (numBytes == Integer.BYTES) {
+      // Used by IntPoint, FloatPoint, LatLonPoint, LatLonShape
+      return ArrayUtil::compareUnsigned4;
+    } else {
+      return (a, ai, b, bI) -> Arrays.compareUnsigned(a, ai, ai + numBytes, b, 
bI, bI + numBytes);

Review comment:
       ai should probably read aI. I would make it more verbose everywhere 
though (aIndex or even offsetA).




-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to