lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [07/10] lucene-solr:jira/http2: LUCENE-8573: Use FutureArrays#mismatch in BKDWriter
Date Wed, 28 Nov 2018 18:48:42 GMT
LUCENE-8573: Use FutureArrays#mismatch in BKDWriter

Closes #510

Signed-off-by: Adrien Grand <jpountz@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ecce083c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ecce083c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ecce083c

Branch: refs/heads/jira/http2
Commit: ecce083c5017576f552a5fd8e347b8748dbc0db9
Parents: 2715beb
Author: Christoph Büscher <cbuescher@posteo.de>
Authored: Tue Nov 27 17:41:58 2018 +0100
Committer: Adrien Grand <jpountz@gmail.com>
Committed: Wed Nov 28 10:18:35 2018 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  5 ++
 .../org/apache/lucene/util/bkd/BKDWriter.java   | 60 +++++++++-----------
 2 files changed, 32 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ecce083c/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 86d06bc..a8e100a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -233,6 +233,11 @@ Optimizations
 * LUCENE-8552: FieldInfos.getMergedFieldInfos no longer does any merging if there is <=
1 segment.
   (Christophe Bismuth via David Smiley)
 
+Other
+
+* LUCENE-8573: BKDWriter now uses FutureArrays#mismatch to compute shared prefixes.
+  (Christoph Büscher via Adrien Grand)
+
 ======================= Lucene 7.6.0 =======================
 
 Build

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ecce083c/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
index 1ffa275..39d05b0 100644
--- a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java
@@ -678,13 +678,10 @@ public class BKDWriter implements Closeable {
       checkMaxLeafNodeCount(leafBlockFPs.size());
 
       // Find per-dim common prefix:
-      int prefix = bytesPerDim;
       int offset = (leafCount - 1) * packedBytesLength;
-      for(int j=0;j<bytesPerDim;j++) {
-        if (leafValues[j] != leafValues[offset+j]) {
-          prefix = j;
-          break;
-        }
+      int prefix = FutureArrays.mismatch(leafValues, 0, bytesPerDim, leafValues, offset,
offset + bytesPerDim);
+      if (prefix == -1) {
+          prefix = bytesPerDim;
       }
 
       commonPrefixLengths[0] = prefix;
@@ -1156,11 +1153,10 @@ public class BKDWriter implements Closeable {
       //System.out.println("recursePack inner nodeID=" + nodeID + " splitDim=" + splitDim
+ " splitValue=" + new BytesRef(splitPackedValues, address, bytesPerDim));
 
       // find common prefix with last split value in this dim:
-      int prefix = 0;
-      for(;prefix<bytesPerDim;prefix++) {
-        if (splitPackedValues[address+prefix] != lastSplitValues[splitDim * bytesPerDim +
prefix]) {
-          break;
-        }
+      int prefix = FutureArrays.mismatch(splitPackedValues, address, address + bytesPerDim,
lastSplitValues,
+          splitDim * bytesPerDim, splitDim * bytesPerDim + bytesPerDim);
+      if (prefix == -1) {
+        prefix = bytesPerDim;
       }
 
       //System.out.println("writeNodeData nodeID=" + nodeID + " splitDim=" + splitDim + "
numDims=" + numDims + " bytesPerDim=" + bytesPerDim + " prefix=" + prefix);
@@ -1552,11 +1548,13 @@ public class BKDWriter implements Closeable {
         reader.getValue(i, scratchBytesRef2);
         for (int dim=0;dim<numDataDims;dim++) {
           final int offset = dim * bytesPerDim;
-          for(int j=0;j<commonPrefixLengths[dim];j++) {
-            if (scratchBytesRef1.bytes[scratchBytesRef1.offset+offset+j] != scratchBytesRef2.bytes[scratchBytesRef2.offset+offset+j])
{
-              commonPrefixLengths[dim] = j;
-              break;
-            }
+          int dimensionPrefixLength = commonPrefixLengths[dim];
+          commonPrefixLengths[dim] = FutureArrays.mismatch(scratchBytesRef1.bytes, scratchBytesRef1.offset
+ offset,
+              scratchBytesRef1.offset + offset + dimensionPrefixLength,
+              scratchBytesRef2.bytes, scratchBytesRef2.offset + offset,
+              scratchBytesRef2.offset + offset + dimensionPrefixLength);
+          if (commonPrefixLengths[dim] == -1) {
+            commonPrefixLengths[dim] = dimensionPrefixLength;
           }
         }
       }
@@ -1632,12 +1630,11 @@ public class BKDWriter implements Closeable {
       final int splitDim = split(minPackedValue, maxPackedValue, parentSplits);
       final int mid = (from + to + 1) >>> 1;
 
-      int commonPrefixLen = bytesPerDim;
-      for (int i = 0; i < bytesPerDim; ++i) {
-        if (minPackedValue[splitDim * bytesPerDim + i] != maxPackedValue[splitDim * bytesPerDim
+ i]) {
-          commonPrefixLen = i;
-          break;
-        }
+      int commonPrefixLen = FutureArrays.mismatch(minPackedValue, splitDim * bytesPerDim,
+          splitDim * bytesPerDim + bytesPerDim, maxPackedValue, splitDim * bytesPerDim,
+          splitDim * bytesPerDim + bytesPerDim);
+      if (commonPrefixLen == -1) {
+        commonPrefixLen = bytesPerDim;
       }
 
       MutablePointsReaderUtils.partition(maxDoc, splitDim, bytesPerDim, commonPrefixLen,
@@ -1713,12 +1710,9 @@ public class BKDWriter implements Closeable {
         heapSource.readPackedValue(Math.toIntExact(source.start + source.count - 1), scratch2);
 
         int offset = dim * bytesPerDim;
-        commonPrefixLengths[dim] = bytesPerDim;
-        for(int j=0;j<bytesPerDim;j++) {
-          if (scratch1[offset+j] != scratch2[offset+j]) {
-            commonPrefixLengths[dim] = j;
-            break;
-          }
+        commonPrefixLengths[dim] = FutureArrays.mismatch(scratch1, offset, offset + bytesPerDim,
scratch2, offset, offset + bytesPerDim);
+        if (commonPrefixLengths[dim] == -1) {
+          commonPrefixLengths[dim] = bytesPerDim;
         }
 
         int prefix = commonPrefixLengths[dim];
@@ -1754,11 +1748,11 @@ public class BKDWriter implements Closeable {
           heapSource.readPackedValue(i, scratch2);
           for (int dim = numIndexDims; dim < numDataDims; dim++) {
             final int offset = dim * bytesPerDim;
-            for (int j = 0; j < commonPrefixLengths[dim]; j++) {
-              if (scratch1[offset + j] != scratch2[offset + j]) {
-                commonPrefixLengths[dim] = j;
-                break;
-              }
+            int dimensionPrefixLength = commonPrefixLengths[dim];
+            commonPrefixLengths[dim] = FutureArrays.mismatch(scratch1, offset, offset + dimensionPrefixLength,
+                scratch2, offset, offset + dimensionPrefixLength);
+            if (commonPrefixLengths[dim] == -1) {
+                commonPrefixLengths[dim] = dimensionPrefixLength;
             }
           }
         }


Mime
View raw message