LUCENE-6114: remove bw compat cruft from packedints

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1646247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-12-17 14:02:10 +00:00
parent 5258d624c3
commit 4ad12e843a
10 changed files with 7 additions and 93 deletions

View File

@ -42,11 +42,6 @@ final class Direct16 extends PackedInts.MutableImpl {
for (int i = 0; i < valueCount; ++i) {
values[i] = in.readShort();
}
// because packed ints have not always been byte-aligned
final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, 16) - 2L * valueCount);
for (int i = 0; i < remaining; ++i) {
in.readByte();
}
}
@Override

View File

@ -42,11 +42,6 @@ final class Direct32 extends PackedInts.MutableImpl {
for (int i = 0; i < valueCount; ++i) {
values[i] = in.readInt();
}
// because packed ints have not always been byte-aligned
final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, 32) - 4L * valueCount);
for (int i = 0; i < remaining; ++i) {
in.readByte();
}
}
@Override

View File

@ -40,11 +40,6 @@ final class Direct8 extends PackedInts.MutableImpl {
Direct8(int packedIntsVersion, DataInput in, int valueCount) throws IOException {
this(valueCount);
in.readBytes(values, 0, valueCount);
// because packed ints have not always been byte-aligned
final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, 8) - 1L * valueCount);
for (int i = 0; i < remaining; ++i) {
in.readByte();
}
}
@Override

View File

@ -17,7 +17,6 @@ package org.apache.lucene.util.packed;
* limitations under the License.
*/
import static org.apache.lucene.util.BitUtil.zigZagDecode;
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.PackedInts.checkBlockSize;
@ -50,14 +49,6 @@ public class MonotonicBlockPackedReader extends LongValues implements Accountabl
/** Sole constructor. */
public static MonotonicBlockPackedReader of(IndexInput in, int packedIntsVersion, int blockSize, long valueCount, boolean direct) throws IOException {
if (packedIntsVersion < PackedInts.VERSION_MONOTONIC_WITHOUT_ZIGZAG) {
return new MonotonicBlockPackedReader(in, packedIntsVersion, blockSize, valueCount, direct) {
@Override
protected long decodeDelta(long delta) {
return zigZagDecode(delta);
}
};
}
return new MonotonicBlockPackedReader(in, packedIntsVersion, blockSize, valueCount, direct);
}
@ -71,11 +62,7 @@ public class MonotonicBlockPackedReader extends LongValues implements Accountabl
subReaders = new PackedInts.Reader[numBlocks];
long sumBPV = 0;
for (int i = 0; i < numBlocks; ++i) {
if (packedIntsVersion < PackedInts.VERSION_MONOTONIC_WITHOUT_ZIGZAG) {
minValues[i] = in.readVLong();
} else {
minValues[i] = in.readZLong();
}
minValues[i] = in.readZLong();
averages[i] = Float.intBitsToFloat(in.readInt());
final int bitsPerValue = in.readVInt();
sumBPV += bitsPerValue;
@ -103,11 +90,7 @@ public class MonotonicBlockPackedReader extends LongValues implements Accountabl
assert index >= 0 && index < valueCount;
final int block = (int) (index >>> blockShift);
final int idx = (int) (index & blockMask);
return expected(minValues[block], averages[block], idx) + decodeDelta(subReaders[block].get(idx));
}
protected long decodeDelta(long delta) {
return delta;
return expected(minValues[block], averages[block], idx) + subReaders[block].get(idx);
}
/** Returns the number of values */

View File

@ -47,11 +47,6 @@ final class Packed16ThreeBlocks extends PackedInts.MutableImpl {
for (int i = 0; i < 3 * valueCount; ++i) {
blocks[i] = in.readShort();
}
// because packed ints have not always been byte-aligned
final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, 48) - 3L * valueCount * 2);
for (int i = 0; i < remaining; ++i) {
in.readByte();
}
}
@Override

View File

@ -27,7 +27,7 @@ import org.apache.lucene.util.RamUsageEstimator;
* Space optimized random access capable array of values with a fixed number of
* bits/value. Values are packed contiguously.
* </p><p>
* The implementation strives to perform af fast as possible under the
* The implementation strives to perform as fast as possible under the
* constraint of contiguous bits, by avoiding expensive operations. This comes
* at the cost of code clarity.
* </p><p>

View File

@ -45,11 +45,6 @@ final class Packed8ThreeBlocks extends PackedInts.MutableImpl {
Packed8ThreeBlocks(int packedIntsVersion, DataInput in, int valueCount) throws IOException {
this(valueCount);
in.readBytes(blocks, 0, 3 * valueCount);
// because packed ints have not always been byte-aligned
final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, 24) - 3L * valueCount * 1);
for (int i = 0; i < remaining; ++i) {
in.readByte();
}
}
@Override

View File

@ -65,9 +65,8 @@ public class PackedInts {
public static final int DEFAULT_BUFFER_SIZE = 1024; // 1K
public final static String CODEC_NAME = "PackedInts";
public final static int VERSION_START = 0; // PackedInts were long-aligned
public final static int VERSION_BYTE_ALIGNED = 1;
public static final int VERSION_MONOTONIC_WITHOUT_ZIGZAG = 2;
public final static int VERSION_START = VERSION_MONOTONIC_WITHOUT_ZIGZAG;
public final static int VERSION_CURRENT = VERSION_MONOTONIC_WITHOUT_ZIGZAG;
/**
@ -94,11 +93,7 @@ public class PackedInts {
@Override
public long byteCount(int packedIntsVersion, int valueCount, int bitsPerValue) {
if (packedIntsVersion < VERSION_BYTE_ALIGNED) {
return 8L * (long) Math.ceil((double) valueCount * bitsPerValue / 64);
} else {
return (long) Math.ceil((double) valueCount * bitsPerValue / 8);
}
return (long) Math.ceil((double) valueCount * bitsPerValue / 8);
}
},
@ -889,32 +884,7 @@ public class PackedInts {
checkVersion(version);
switch (format) {
case PACKED:
final long byteCount = format.byteCount(version, valueCount, bitsPerValue);
if (byteCount != format.byteCount(VERSION_CURRENT, valueCount, bitsPerValue)) {
assert version == VERSION_START;
final long endPointer = in.getFilePointer() + byteCount;
// Some consumers of direct readers assume that reading the last value
// will make the underlying IndexInput go to the end of the packed
// stream, but this is not true because packed ints storage used to be
// long-aligned and is now byte-aligned, hence this additional
// condition when reading the last value
return new DirectPackedReader(bitsPerValue, valueCount, in) {
@Override
public long get(int index) {
final long result = super.get(index);
if (index == valueCount - 1) {
try {
in.seek(endPointer);
} catch (IOException e) {
throw new IllegalStateException("failed", e);
}
}
return result;
}
};
} else {
return new DirectPackedReader(bitsPerValue, valueCount, in);
}
return new DirectPackedReader(bitsPerValue, valueCount, in);
case PACKED_SINGLE_BLOCK:
return new DirectPacked64SingleBlockReader(bitsPerValue, valueCount, in);
default:

View File

@ -39,7 +39,7 @@ final class PackedReaderIterator extends PackedInts.ReaderIteratorImpl {
this.format = format;
this.packedIntsVersion = packedIntsVersion;
bulkOperation = BulkOperation.of(format, bitsPerValue);
iterations = iterations(mem);
iterations = bulkOperation.computeIterations(valueCount, mem);
assert valueCount == 0 || iterations > 0;
nextBlocks = new byte[iterations * bulkOperation.byteBlockCount()];
nextValues = new LongsRef(new long[iterations * bulkOperation.byteValueCount()], 0, 0);
@ -47,15 +47,6 @@ final class PackedReaderIterator extends PackedInts.ReaderIteratorImpl {
position = -1;
}
private int iterations(int mem) {
int iterations = bulkOperation.computeIterations(valueCount, mem);
if (packedIntsVersion < PackedInts.VERSION_BYTE_ALIGNED) {
// make sure iterations is a multiple of 8
iterations = (iterations + 7) & 0xFFFFFFF8;
}
return iterations;
}
@Override
public LongsRef next(int count) throws IOException {
assert nextValues.length >= 0;

View File

@ -78,11 +78,6 @@ if __name__ == '__main__':
f.write(" for (int i = 0; i < 3 * valueCount; ++i) {\n")
f.write(" blocks[i] = in.read%s();\n" %TYPES[bpv].title())
f.write(" }\n")
f.write(" // because packed ints have not always been byte-aligned\n")
f.write(" final int remaining = (int) (PackedInts.Format.PACKED.byteCount(packedIntsVersion, valueCount, %d) - 3L * valueCount * %d);\n" %(3 * bpv, bpv / 8))
f.write(" for (int i = 0; i < remaining; ++i) {\n")
f.write(" in.readByte();\n")
f.write(" }\n")
f.write(" }\n")
f.write("""