You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2021/04/19 07:47:52 UTC

[lucene] branch main updated: LUCENE-9907: Remove unused BlockPackedReader (#93)

This is an automated email from the ASF dual-hosted git repository.

ivera pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 936b345  LUCENE-9907: Remove unused BlockPackedReader (#93)
936b345 is described below

commit 936b3451af7b1399cda467d6759e82d03a33bd2e
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Mon Apr 19 09:47:44 2021 +0200

    LUCENE-9907: Remove unused BlockPackedReader (#93)
---
 .../lucene/util/packed/BlockPackedReader.java      | 122 ---------------------
 .../lucene/util/packed/BlockPackedWriter.java      |   1 -
 .../apache/lucene/util/packed/package-info.java    |   1 -
 .../apache/lucene/util/packed/TestPackedInts.java  |  22 ----
 4 files changed, 146 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java b/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java
deleted file mode 100644
index 3da4cd2..0000000
--- a/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.util.packed;
-
-import static org.apache.lucene.util.BitUtil.zigZagDecode;
-import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.BPV_SHIFT;
-import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MAX_BLOCK_SIZE;
-import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MIN_BLOCK_SIZE;
-import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MIN_VALUE_EQUALS_0;
-import static org.apache.lucene.util.packed.BlockPackedReaderIterator.readVLong;
-import static org.apache.lucene.util.packed.PackedInts.checkBlockSize;
-import static org.apache.lucene.util.packed.PackedInts.numBlocks;
-
-import java.io.IOException;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.Accountable;
-import org.apache.lucene.util.LongValues;
-
-/**
- * Provides random access to a stream written with {@link BlockPackedWriter}.
- *
- * @lucene.internal
- */
-public final class BlockPackedReader extends LongValues implements Accountable {
-
-  private final int blockShift, blockMask;
-  private final long valueCount;
-  private final long[] minValues;
-  private final PackedInts.Reader[] subReaders;
-  private final long sumBPV;
-
-  /** Sole constructor. */
-  public BlockPackedReader(
-      IndexInput in, int packedIntsVersion, int blockSize, long valueCount, boolean direct)
-      throws IOException {
-    this.valueCount = valueCount;
-    blockShift = checkBlockSize(blockSize, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE);
-    blockMask = blockSize - 1;
-    final int numBlocks = numBlocks(valueCount, blockSize);
-    long[] minValues = null;
-    subReaders = new PackedInts.Reader[numBlocks];
-    long sumBPV = 0;
-    for (int i = 0; i < numBlocks; ++i) {
-      final int token = in.readByte() & 0xFF;
-      final int bitsPerValue = token >>> BPV_SHIFT;
-      sumBPV += bitsPerValue;
-      if (bitsPerValue > 64) {
-        throw new CorruptIndexException("Corrupted Block#" + i, in);
-      }
-      if ((token & MIN_VALUE_EQUALS_0) == 0) {
-        if (minValues == null) {
-          minValues = new long[numBlocks];
-        }
-        minValues[i] = zigZagDecode(1L + readVLong(in));
-      }
-      if (bitsPerValue == 0) {
-        subReaders[i] = new PackedInts.NullReader(blockSize);
-      } else {
-        final int size = (int) Math.min(blockSize, valueCount - (long) i * blockSize);
-        if (direct) {
-          final long pointer = in.getFilePointer();
-          subReaders[i] =
-              PackedInts.getDirectReaderNoHeader(
-                  in, PackedInts.Format.PACKED, packedIntsVersion, size, bitsPerValue);
-          in.seek(
-              pointer + PackedInts.Format.PACKED.byteCount(packedIntsVersion, size, bitsPerValue));
-        } else {
-          subReaders[i] =
-              PackedInts.getReaderNoHeader(
-                  in, PackedInts.Format.PACKED, packedIntsVersion, size, bitsPerValue);
-        }
-      }
-    }
-    this.minValues = minValues;
-    this.sumBPV = sumBPV;
-  }
-
-  @Override
-  public long get(long index) {
-    assert index >= 0 && index < valueCount;
-    final int block = (int) (index >>> blockShift);
-    final int idx = (int) (index & blockMask);
-    return (minValues == null ? 0 : minValues[block]) + subReaders[block].get(idx);
-  }
-
-  @Override
-  public long ramBytesUsed() {
-    long size = 0;
-    for (PackedInts.Reader reader : subReaders) {
-      size += reader.ramBytesUsed();
-    }
-    return size;
-  }
-
-  @Override
-  public String toString() {
-    long avgBPV = subReaders.length == 0 ? 0 : sumBPV / subReaders.length;
-    return getClass().getSimpleName()
-        + "(blocksize="
-        + (1 << blockShift)
-        + ",size="
-        + valueCount
-        + ",avgBPV="
-        + avgBPV
-        + ")";
-  }
-}
diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java b/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
index 03239f4..ebe60a4 100644
--- a/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
@@ -50,7 +50,6 @@ import org.apache.lucene.store.DataOutput;
  * </ul>
  *
  * @see BlockPackedReaderIterator
- * @see BlockPackedReader
  * @lucene.internal
  */
 public final class BlockPackedWriter extends AbstractBlockPackedWriter {
diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/package-info.java b/lucene/core/src/java/org/apache/lucene/util/packed/package-info.java
index fc5df8e..5e91312 100644
--- a/lucene/core/src/java/org/apache/lucene/util/packed/package-info.java
+++ b/lucene/core/src/java/org/apache/lucene/util/packed/package-info.java
@@ -83,7 +83,6 @@
  *             Reader.
  *       </ul>
  *   <li><b>{@link org.apache.lucene.util.packed.BlockPackedWriter}, {@link
- *       org.apache.lucene.util.packed.BlockPackedReader}, {@link
  *       org.apache.lucene.util.packed.BlockPackedReaderIterator}</b>
  *       <ul>
  *         <li>Splits the stream into fixed-size blocks.
diff --git a/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
index 32b5ef2..baff6ae 100644
--- a/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
+++ b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
@@ -1324,15 +1324,6 @@ public class TestPackedInts extends LuceneTestCase {
           () -> {
             it2.skip(1);
           });
-
-      in1.seek(0L);
-      final BlockPackedReader reader =
-          new BlockPackedReader(
-              in1, PackedInts.VERSION_CURRENT, blockSize, valueCount, random().nextBoolean());
-      assertEquals(in1.getFilePointer(), in1.length());
-      for (i = 0; i < valueCount; ++i) {
-        assertEquals("i=" + i, values[i], reader.get(i));
-      }
       in1.close();
       dir.close();
     }
@@ -1412,19 +1403,6 @@ public class TestPackedInts extends LuceneTestCase {
         new BlockPackedReaderIterator(in, PackedInts.VERSION_CURRENT, blockSize, valueCount);
     it.skip(valueOffset);
     assertEquals(value, it.next());
-    in.seek(0L);
-    final BlockPackedReader reader =
-        new BlockPackedReader(
-            in, PackedInts.VERSION_CURRENT, blockSize, valueCount, random().nextBoolean());
-    assertEquals(value, reader.get(valueOffset));
-    for (int i = 0; i < 5; ++i) {
-      final long offset = TestUtil.nextLong(random(), 0, valueCount - 1);
-      if (offset == valueOffset) {
-        assertEquals(value, reader.get(offset));
-      } else {
-        assertEquals(0, reader.get(offset));
-      }
-    }
     in.close();
     dir.close();
   }