Apache Lucene open-source search software
LUCENE-3892: use PackedInt's VERSION constants
Michael McCandless32126e22d8a2
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java b/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.javaindex 1cae3d40cc2..30e9faecd86 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java@@ -40,8 +40,6 @@ final class ForUtil {* Special number of bits per value used whenever all values to encode are equal.*/private static final int ALL_VALUES_EQUAL = 0;- private static final int PACKED_INTS_VERSION_START = 0;- private static final int PACKED_INTS_VERSION_CURRENT = PACKED_INTS_VERSION_START;/*** Upper limit of the number of bytes that might be required to stored@@ -58,14 +56,16 @@ final class ForUtil {static final int MAX_DATA_SIZE;static {int maxDataSize = 0;- for (PackedInts.Format format : PackedInts.Format.values()) {- for (int bpv = 1; bpv <= 32; ++bpv) {- if (!format.isSupported(bpv)) {- continue;+ for(int version=PackedInts.VERSION_START;version<=PackedInts.VERSION_CURRENT;version++) {+ for (PackedInts.Format format : PackedInts.Format.values()) {+ for (int bpv = 1; bpv <= 32; ++bpv) {+ if (!format.isSupported(bpv)) {+ continue;+ }+ final PackedInts.Decoder decoder = PackedInts.getDecoder(format, version, bpv);+ final int iterations = (int) Math.ceil((float) BLOCK_SIZE / decoder.valueCount());+ maxDataSize = Math.max(maxDataSize, iterations * decoder.valueCount());}- final PackedInts.Decoder decoder = PackedInts.getDecoder(format, PACKED_INTS_VERSION_START, bpv);- final int iterations = (int) Math.ceil((float) BLOCK_SIZE / decoder.valueCount());- maxDataSize = Math.max(maxDataSize, iterations * decoder.valueCount());}}MAX_DATA_SIZE = maxDataSize;@@ -96,7 +96,7 @@ final class ForUtil {* Create a new {@link ForUtil} instance and save state into <code>out</code>.*/ForUtil(float acceptableOverheadRatio, DataOutput out) throws IOException {- out.writeVInt(PACKED_INTS_VERSION_CURRENT);+ out.writeVInt(PackedInts.VERSION_CURRENT);encodedSizes = new int[33];encoders = new PackedInts.Encoder[33];decoders = new PackedInts.Decoder[33];@@ -109,9 +109,9 @@ final class ForUtil {assert formatAndBits.bitsPerValue <= 32;encodedSizes[bpv] = encodedSize(formatAndBits.format, formatAndBits.bitsPerValue);encoders[bpv] = PackedInts.getEncoder(- formatAndBits.format, PACKED_INTS_VERSION_CURRENT, formatAndBits.bitsPerValue);+ formatAndBits.format, PackedInts.VERSION_CURRENT, formatAndBits.bitsPerValue);decoders[bpv] = PackedInts.getDecoder(- formatAndBits.format, PACKED_INTS_VERSION_CURRENT, formatAndBits.bitsPerValue);+ formatAndBits.format, PackedInts.VERSION_CURRENT, formatAndBits.bitsPerValue);iterations[bpv] = computeIterations(decoders[bpv]);out.writeVInt(formatAndBits.format.getId() << 5 | (formatAndBits.bitsPerValue - 1));@@ -123,8 +123,8 @@ final class ForUtil {*/ForUtil(DataInput in) throws IOException {int packedIntsVersion = in.readVInt();- if (packedIntsVersion != PACKED_INTS_VERSION_START) {- throw new CorruptIndexException("expected version=" + PACKED_INTS_VERSION_START + " but got version=" + packedIntsVersion);+ if (packedIntsVersion != PackedInts.VERSION_START) {+ throw new CorruptIndexException("expected version=" + PackedInts.VERSION_START + " but got version=" + packedIntsVersion);}encodedSizes = new int[33];encoders = new PackedInts.Encoder[33];diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java b/lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.javaindex 6d92351c8c0..c11135ed314 100644--- a/lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java+++ b/lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java@@ -675,6 +675,9 @@ public class PackedInts {* @return a decoder*/public static Decoder getDecoder(Format format, int version, int bitsPerValue) {+ if (version != VERSION_START) {+ throw new IllegalArgumentException("only VERSION_START is valid (got " + version + ")");+ }return BulkOperation.of(format, bitsPerValue);}@@ -687,6 +690,9 @@ public class PackedInts {* @return an encoder*/public static Encoder getEncoder(Format format, int version, int bitsPerValue) {+ if (version != VERSION_START) {+ throw new IllegalArgumentException("only VERSION_START is valid (got " + version + ")");+ }return BulkOperation.of(format, bitsPerValue);}