jpountz commented on code in PR #12610:
URL: https://github.com/apache/lucene/pull/12610#discussion_r1342470366


##########
lucene/core/src/java/org/apache/lucene/util/bkd/MutablePointTreeReaderUtils.java:
##########
@@ -81,6 +86,40 @@ protected int byteAt(int i, int k) {
           return (reader.getDocID(i) >>> Math.max(0, shift)) & 0xff;
         }
       }
+
+      @Override
+      protected Sorter getFallbackSorter(int k) {
+        return new InPlaceMergeSorter() {
+          @Override
+          protected int compare(int i, int j) {
+            if (k < config.packedBytesLength) {
+              reader.getValue(i, scratch1);
+              reader.getValue(j, scratch2);
+              int v =
+                  Arrays.compareUnsigned(
+                      scratch1.bytes,
+                      scratch1.offset + k,
+                      scratch1.offset + scratch1.length,
+                      scratch2.bytes,
+                      scratch2.offset + k,
+                      scratch2.offset + scratch2.length);
+              if (v != 0) {
+                return v;
+              }
+            }
+            if (bitsPerDocId == 0) {

Review Comment:
   can this ever be 0?



##########
lucene/core/src/java/org/apache/lucene/util/bkd/MutablePointTreeReaderUtils.java:
##########
@@ -81,6 +86,40 @@ protected int byteAt(int i, int k) {
           return (reader.getDocID(i) >>> Math.max(0, shift)) & 0xff;
         }
       }
+
+      @Override
+      protected Sorter getFallbackSorter(int k) {

Review Comment:
   I wonder if it would help to take advantage of 
`ArrayUtil#getUnsignedComparator`, e.g. something like below:
   
   ```java
   int cmpStartOffset;
   ByteArrayComparator packedBytesComparator;
   if (k >= config.packedBytesLength) {
     cmpStartOffset = config.packedBytesLength;
     packedBytesComparator = (a, ai, b, bi) -> 0;
   } else if (config.packedBytesLength >= 4 && config.packedBytesLength - k <= 
4) {
     cmpStartOffset = config.packedBytesLength - 4;
     packedBytesComparator = ArrayUtil.getUnsignedComparator(4);
   } else if (config.packedBytesLength >= 8 && config.packedBytesLength - k <= 
8) {
     cmpStartOffset = config.packedBytesLength - 8;
     packedBytesComparator = ArrayUtil.getUnsignedComparator(8);
   } else {
     cmpStartOffset = k;
     packedBytesComparator = 
ArrayUtil.getUnsignedComparator(config.packedBytesLength - k);
   }
   ```



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