mikemccand commented on a change in pull request #1179: LUCENE-9147: Move the 
stored fields index off-heap.
URL: https://github.com/apache/lucene-solr/pull/1179#discussion_r367955319
 
 

 ##########
 File path: 
lucene/core/src/java/org/apache/lucene/util/packed/DirectMonotonicReader.java
 ##########
 @@ -101,20 +104,99 @@ public static LongValues getInstance(Meta meta, 
RandomAccessInput data) throws I
         readers[i] = DirectReader.getInstance(data, meta.bpvs[i], 
meta.offsets[i]);
       }
     }
-    final int blockShift = meta.blockShift;
-
-    final long[] mins = meta.mins;
-    final float[] avgs = meta.avgs;
-    return new LongValues() {
-
-      @Override
-      public long get(long index) {
-        final int block = (int) (index >>> blockShift);
-        final long blockIndex = index & ((1 << blockShift) - 1);
-        final long delta = readers[block].get(blockIndex);
-        return mins[block] + (long) (avgs[block] * blockIndex) + delta;
+
+    return new DirectMonotonicReader(meta.blockShift, readers, meta.mins, 
meta.avgs, meta.bpvs);
+  }
+
+  private final int blockShift;
+  private final LongValues[] readers;
+  private final long[] mins;
+  private final float[] avgs;
+  private final byte[] bpvs;
+  private final int nonZeroBpvs;
+
+  private DirectMonotonicReader(int blockShift, LongValues[] readers, long[] 
mins, float[] avgs, byte[] bpvs) {
+    this.blockShift = blockShift;
+    this.readers = readers;
+    this.mins = mins;
+    this.avgs = avgs;
+    this.bpvs = bpvs;
+    if (readers.length != mins.length || readers.length != avgs.length || 
readers.length != bpvs.length) {
+      throw new IllegalArgumentException();
+    }
+    int nonZeroBpvs = 0;
+    for (byte b : bpvs) {
+      if (b != 0) {
+        nonZeroBpvs++;
+      }
+    }
+    this.nonZeroBpvs = nonZeroBpvs;
+  }
+
+  @Override
+  public long get(long index) {
+    final int block = (int) (index >>> blockShift);
+    final long blockIndex = index & ((1 << blockShift) - 1);
+    final long delta = readers[block].get(blockIndex);
+    return mins[block] + (long) (avgs[block] * blockIndex) + delta;
+  }
+
+  /** Get lower/upper bounds for the value at a given index without hitting 
the direct reader. */
+  private long[] getBounds(long index) {
+    final int block = (int) (index >>> blockShift);
 
 Review comment:
   Do we know this incoming `long index` is small enough not to overflow `int` 
after right shift?  Should we use `Math.toIntExact` instead to confirm?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to