Apache Lucene open-source search software
LUCENE-9907: Remove unused BlockPackedReader (#93)
Ignacio Vera936b3451af7b
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.javadeleted file mode 100644index 3da4cd2a5aa..00000000000--- 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.javaindex 03239f4ef5b..ebe60a46dff 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.javaindex fc5df8e6397..5e9131284fa 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.javaindex 32b5ef22cdf..baff6ae2ef1 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();}