You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/10/27 19:55:48 UTC
svn commit: r1189895 - in /lucene/dev/branches/branch_3x/lucene/src:
java/org/apache/lucene/util/packed/ test/org/apache/lucene/util/packed/
Author: mikemccand
Date: Thu Oct 27 17:55:48 2011
New Revision: 1189895
URL: http://svn.apache.org/viewvc?rev=1189895&view=rev
Log:
LUCENE-2205: first backport packed ints impl to 3.x
Added:
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/
- copied from r1188628, lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/packed/
- copied from r1188628, lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/packed/
Removed:
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/PackedReaderIterator.java
Modified:
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/GrowableWriter.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/GrowableWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/GrowableWriter.java?rev=1189895&r1=1188628&r2=1189895&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/GrowableWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/GrowableWriter.java Thu Oct 27 17:55:48 2011
@@ -60,12 +60,12 @@ public class GrowableWriter implements P
return current;
}
- @Override
+ // @Override
public Object getArray() {
return current.getArray();
}
- @Override
+ // @Override
public boolean hasArray() {
return current.hasArray();
}
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java?rev=1189895&r1=1188628&r2=1189895&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java Thu Oct 27 17:55:48 2011
@@ -17,11 +17,8 @@ package org.apache.lucene.util.packed;
* limitations under the License.
*/
-import java.io.Closeable;
-
import org.apache.lucene.store.DataInput;
import org.apache.lucene.store.DataOutput;
-import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.CodecUtil;
import org.apache.lucene.util.Constants;
@@ -85,32 +82,6 @@ public class PackedInts {
*/
boolean hasArray();
}
-
- /**
- * Run-once iterator interface, to decode previously saved PackedInts.
- */
- public static interface ReaderIterator extends Closeable {
- /** Returns next value */
- long next() throws IOException;
- /** Returns number of bits per value */
- int getBitsPerValue();
- /** Returns number of values */
- int size();
- /** Returns the current position */
- int ord();
- /** Skips to the given ordinal and returns its value.
- * @return the value at the given position
- * @throws IOException if reading the value throws an IOException*/
- long advance(int ord) throws IOException;
- }
-
- public static interface RandomAccessReaderIterator extends ReaderIterator {
- /**
- * @param index the position of the wanted value.
- * @return the value at the stated index.
- */
- long get(int index) throws IOException;
- }
/**
* A packed integer array that can be modified.
@@ -223,32 +194,6 @@ public class PackedInts {
}
/**
- * Retrieve PackedInts as a {@link ReaderIterator}
- * @param in positioned at the beginning of a stored packed int structure.
- * @return an iterator to access the values
- * @throws IOException if the structure could not be retrieved.
- * @lucene.internal
- */
- public static ReaderIterator getReaderIterator(IndexInput in) throws IOException {
- return getRandomAccessReaderIterator(in);
- }
-
- /**
- * Retrieve PackedInts as a {@link RandomAccessReaderIterator}
- * @param in positioned at the beginning of a stored packed int structure.
- * @return an iterator to access the values
- * @throws IOException if the structure could not be retrieved.
- * @lucene.internal
- */
- public static RandomAccessReaderIterator getRandomAccessReaderIterator(IndexInput in) throws IOException {
- CodecUtil.checkHeader(in, CODEC_NAME, VERSION_START, VERSION_START);
- final int bitsPerValue = in.readVInt();
- assert bitsPerValue > 0 && bitsPerValue <= 64: "bitsPerValue=" + bitsPerValue;
- final int valueCount = in.readVInt();
- return new PackedReaderIterator(bitsPerValue, valueCount, in);
- }
-
- /**
* Create a packed integer array with the given amount of values initialized
* to 0. the valueCount and the bitsPerValue cannot be changed after creation.
* All Mutables known by this factory are kept fully in RAM.
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java?rev=1189895&r1=1188628&r2=1189895&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java Thu Oct 27 17:55:48 2011
@@ -54,7 +54,7 @@ public class TestPackedInts extends Luce
final int valueCount = 100+random.nextInt(500);
final Directory d = newDirectory();
- IndexOutput out = d.createOutput("out.bin", newIOContext(random));
+ IndexOutput out = d.createOutput("out.bin");
PackedInts.Writer w = PackedInts.getWriter(
out, valueCount, nbits);
@@ -71,7 +71,7 @@ public class TestPackedInts extends Luce
final long fp = out.getFilePointer();
out.close();
{// test reader
- IndexInput in = d.openInput("out.bin", newIOContext(random));
+ IndexInput in = d.openInput("out.bin");
PackedInts.Reader r = PackedInts.getReader(in);
assertEquals(fp, in.getFilePointer());
for(int i=0;i<valueCount;i++) {
@@ -81,66 +81,6 @@ public class TestPackedInts extends Luce
}
in.close();
}
- { // test reader iterator next
- IndexInput in = d.openInput("out.bin", newIOContext(random));
- PackedInts.ReaderIterator r = PackedInts.getReaderIterator(in);
- for(int i=0;i<valueCount;i++) {
- assertEquals("index=" + i + " ceil=" + ceil + " valueCount="
- + valueCount + " nbits=" + nbits + " for "
- + r.getClass().getSimpleName(), values[i], r.next());
- }
- assertEquals(fp, in.getFilePointer());
- in.close();
- }
- { // test reader iterator next vs. advance
- IndexInput in = d.openInput("out.bin", newIOContext(random));
- PackedInts.ReaderIterator intsEnum = PackedInts.getReaderIterator(in);
- for (int i = 0; i < valueCount; i +=
- 1 + ((valueCount - i) <= 20 ? random.nextInt(valueCount - i)
- : random.nextInt(20))) {
- final String msg = "index=" + i + " ceil=" + ceil + " valueCount="
- + valueCount + " nbits=" + nbits + " for "
- + intsEnum.getClass().getSimpleName();
- if (i - intsEnum.ord() == 1 && random.nextBoolean()) {
- assertEquals(msg, values[i], intsEnum.next());
- } else {
- assertEquals(msg, values[i], intsEnum.advance(i));
- }
- assertEquals(msg, i, intsEnum.ord());
- }
- if (intsEnum.ord() < valueCount - 1)
- assertEquals(values[valueCount - 1], intsEnum
- .advance(valueCount - 1));
- assertEquals(valueCount - 1, intsEnum.ord());
- assertEquals(fp, in.getFilePointer());
- in.close();
- }
-
- { // test reader iterator get
- IndexInput in = d.openInput("out.bin", newIOContext(random));
- PackedInts.RandomAccessReaderIterator intsEnum = PackedInts.getRandomAccessReaderIterator(in);
- for (int i = 0; i < valueCount; i++) {
- final String msg = "index=" + i + " ceil=" + ceil + " valueCount="
- + valueCount + " nbits=" + nbits + " for "
- + intsEnum.getClass().getSimpleName();
- final int ord = random.nextInt(valueCount);
- long seek = intsEnum.get(ord);
- assertEquals(msg, seek, values[ord]);
- if (random.nextBoolean() && ord < valueCount-1) {
- if (random.nextBoolean()) {
- assertEquals(msg, values[ord+1], intsEnum.advance(ord+1));
- } else {
- assertEquals(msg, values[ord+1], intsEnum.next());
- }
- }
- }
- if (intsEnum.ord() < valueCount - 1)
- assertEquals(values[valueCount - 1], intsEnum
- .advance(valueCount - 1));
- assertEquals(valueCount - 1, intsEnum.ord());
- assertEquals(fp, in.getFilePointer());
- in.close();
- }
ceil *= 2;
d.close();
}
@@ -255,14 +195,14 @@ public class TestPackedInts extends Luce
public void testSingleValue() throws Exception {
Directory dir = newDirectory();
- IndexOutput out = dir.createOutput("out", newIOContext(random));
+ IndexOutput out = dir.createOutput("out");
PackedInts.Writer w = PackedInts.getWriter(out, 1, 8);
w.add(17);
w.finish();
final long end = out.getFilePointer();
out.close();
- IndexInput in = dir.openInput("out", newIOContext(random));
+ IndexInput in = dir.openInput("out");
PackedInts.getReader(in);
assertEquals(end, in.getFilePointer());
in.close();