You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2012/12/21 10:48:47 UTC
svn commit: r1424829 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/util/packed/
lucene/core/src/test/org/apache/lucene/util/packed/
Author: jpountz
Date: Fri Dec 21 09:48:46 2012
New Revision: 1424829
URL: http://svn.apache.org/viewvc?rev=1424829&view=rev
Log:
LUCENE-4634: New streaming API to read/write ints with arbitrary numbers of bits per value (merged from r1424827).
Added:
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/PackedDataInput.java
- copied unchanged from r1424827, lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/PackedDataInput.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/PackedDataOutput.java
- copied unchanged from r1424827, lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/PackedDataOutput.java
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java?rev=1424829&r1=1424828&r2=1424829&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java Fri Dec 21 09:48:46 2012
@@ -787,4 +787,47 @@ public class TestPackedInts extends Luce
return true;
}
+ public void testPackedInputOutput() throws IOException {
+ final long[] longs = new long[random().nextInt(8192)];
+ final int[] bitsPerValues = new int[longs.length];
+ final boolean[] skip = new boolean[longs.length];
+ for (int i = 0; i < longs.length; ++i) {
+ final int bpv = RandomInts.randomIntBetween(random(), 1, 64);
+ bitsPerValues[i] = random().nextBoolean() ? bpv : _TestUtil.nextInt(random(), bpv, 64);
+ if (bpv == 64) {
+ longs[i] = random().nextLong();
+ } else {
+ longs[i] = _TestUtil.nextLong(random(), 0, PackedInts.maxValue(bpv));
+ }
+ skip[i] = rarely();
+ }
+
+ final Directory dir = newDirectory();
+ final IndexOutput out = dir.createOutput("out.bin", IOContext.DEFAULT);
+ PackedDataOutput pout = new PackedDataOutput(out);
+ long totalBits = 0;
+ for (int i = 0; i < longs.length; ++i) {
+ pout.writeLong(longs[i], bitsPerValues[i]);
+ totalBits += bitsPerValues[i];
+ if (skip[i]) {
+ pout.flush();
+ totalBits = 8 * (long) Math.ceil((double) totalBits / 8);
+ }
+ }
+ pout.flush();
+ assertEquals((long) Math.ceil((double) totalBits / 8), out.getFilePointer());
+ out.close();
+ final IndexInput in = dir.openInput("out.bin", IOContext.READONCE);
+ final PackedDataInput pin = new PackedDataInput(in);
+ for (int i = 0; i < longs.length; ++i) {
+ assertEquals("" + i, longs[i], pin.readLong(bitsPerValues[i]));
+ if (skip[i]) {
+ pin.skipToNextByte();
+ }
+ }
+ assertEquals((long) Math.ceil((double) totalBits / 8), in.getFilePointer());
+ in.close();
+ dir.close();
+ }
+
}