Search in sources :

Example 6 with DirectWriter

use of org.apache.lucene.util.packed.DirectWriter in project lucene-solr by apache.

the class TestDirectPacked method doTestBpv.

private void doTestBpv(Directory directory, int bpv, long offset) throws Exception {
    MyRandom random = new MyRandom(random().nextLong());
    int numIters = TEST_NIGHTLY ? 100 : 10;
    for (int i = 0; i < numIters; i++) {
        long[] original = randomLongs(random, bpv);
        int bitsRequired = bpv == 64 ? 64 : DirectWriter.bitsRequired(1L << (bpv - 1));
        String name = "bpv" + bpv + "_" + i;
        IndexOutput output = directory.createOutput(name, IOContext.DEFAULT);
        for (long j = 0; j < offset; ++j) {
            output.writeByte((byte) random().nextInt());
        }
        DirectWriter writer = DirectWriter.getInstance(output, original.length, bitsRequired);
        for (int j = 0; j < original.length; j++) {
            writer.add(original[j]);
        }
        writer.finish();
        output.close();
        IndexInput input = directory.openInput(name, IOContext.DEFAULT);
        LongValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsRequired, offset);
        for (int j = 0; j < original.length; j++) {
            assertEquals("bpv=" + bpv, original[j], reader.get(j));
        }
        input.close();
    }
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) LongValues(org.apache.lucene.util.LongValues) IndexOutput(org.apache.lucene.store.IndexOutput) DirectWriter(org.apache.lucene.util.packed.DirectWriter)

Example 7 with DirectWriter

use of org.apache.lucene.util.packed.DirectWriter in project lucene-solr by apache.

the class TestDirectPacked method testSimple.

/** simple encode/decode */
public void testSimple() throws Exception {
    Directory dir = newDirectory();
    int bitsPerValue = DirectWriter.bitsRequired(2);
    IndexOutput output = dir.createOutput("foo", IOContext.DEFAULT);
    DirectWriter writer = DirectWriter.getInstance(output, 5, bitsPerValue);
    writer.add(1);
    writer.add(0);
    writer.add(2);
    writer.add(1);
    writer.add(2);
    writer.finish();
    output.close();
    IndexInput input = dir.openInput("foo", IOContext.DEFAULT);
    LongValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsPerValue, 0);
    assertEquals(1, reader.get(0));
    assertEquals(0, reader.get(1));
    assertEquals(2, reader.get(2));
    assertEquals(1, reader.get(3));
    assertEquals(2, reader.get(4));
    input.close();
    dir.close();
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) LongValues(org.apache.lucene.util.LongValues) IndexOutput(org.apache.lucene.store.IndexOutput) DirectWriter(org.apache.lucene.util.packed.DirectWriter) Directory(org.apache.lucene.store.Directory)

Example 8 with DirectWriter

use of org.apache.lucene.util.packed.DirectWriter in project lucene-solr by apache.

the class TestDirectPacked method testNotEnoughValues.

/** test exception is delivered if you add the wrong number of values */
public void testNotEnoughValues() throws Exception {
    Directory dir = newDirectory();
    int bitsPerValue = DirectWriter.bitsRequired(2);
    IndexOutput output = dir.createOutput("foo", IOContext.DEFAULT);
    DirectWriter writer = DirectWriter.getInstance(output, 5, bitsPerValue);
    writer.add(1);
    writer.add(0);
    writer.add(2);
    writer.add(1);
    IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
        writer.finish();
    });
    assertTrue(expected.getMessage().startsWith("Wrong number of values added"));
    output.close();
    dir.close();
}
Also used : IndexOutput(org.apache.lucene.store.IndexOutput) DirectWriter(org.apache.lucene.util.packed.DirectWriter) Directory(org.apache.lucene.store.Directory)

Aggregations

DirectWriter (org.apache.lucene.util.packed.DirectWriter)8 IndexOutput (org.apache.lucene.store.IndexOutput)3 SortedDocValues (org.apache.lucene.index.SortedDocValues)2 Directory (org.apache.lucene.store.Directory)2 IndexInput (org.apache.lucene.store.IndexInput)2 LongValues (org.apache.lucene.util.LongValues)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 EmptyDocValuesProducer (org.apache.lucene.index.EmptyDocValuesProducer)1 FieldInfo (org.apache.lucene.index.FieldInfo)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1 DirectMonotonicWriter (org.apache.lucene.util.packed.DirectMonotonicWriter)1