Search in sources :

Example 26 with LongValues

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

the class TestPackedInts method testPagedGrowableWriter.

public void testPagedGrowableWriter() {
    int pageSize = 1 << (TestUtil.nextInt(random(), 6, 30));
    // supports 0 values?
    PagedGrowableWriter writer = new PagedGrowableWriter(0, pageSize, TestUtil.nextInt(random(), 1, 64), random().nextFloat());
    assertEquals(0, writer.size());
    // compare against AppendingDeltaPackedLongBuffer
    PackedLongValues.Builder buf = PackedLongValues.deltaPackedBuilder(random().nextFloat());
    int size = random().nextInt(1000000);
    long max = 5;
    for (int i = 0; i < size; ++i) {
        buf.add(TestUtil.nextLong(random(), 0, max));
        if (rarely()) {
            max = PackedInts.maxValue(rarely() ? TestUtil.nextInt(random(), 0, 63) : TestUtil.nextInt(random(), 0, 31));
        }
    }
    writer = new PagedGrowableWriter(size, pageSize, TestUtil.nextInt(random(), 1, 64), random().nextFloat());
    assertEquals(size, writer.size());
    final LongValues values = buf.build();
    for (int i = size - 1; i >= 0; --i) {
        writer.set(i, values.get(i));
    }
    for (int i = 0; i < size; ++i) {
        assertEquals(values.get(i), writer.get(i));
    }
    // test ramBytesUsed
    assertEquals(RamUsageTester.sizeOf(writer), writer.ramBytesUsed(), 8);
    // test copy
    PagedGrowableWriter copy = writer.resize(TestUtil.nextLong(random(), writer.size() / 2, writer.size() * 3 / 2));
    for (long i = 0; i < copy.size(); ++i) {
        if (i < writer.size()) {
            assertEquals(writer.get(i), copy.get(i));
        } else {
            assertEquals(0, copy.get(i));
        }
    }
    // test grow
    PagedGrowableWriter grow = writer.grow(TestUtil.nextLong(random(), writer.size() / 2, writer.size() * 3 / 2));
    for (long i = 0; i < grow.size(); ++i) {
        if (i < writer.size()) {
            assertEquals(writer.get(i), grow.get(i));
        } else {
            assertEquals(0, grow.get(i));
        }
    }
}
Also used : LongValues(org.apache.lucene.util.LongValues)

Example 27 with LongValues

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

the class TestDirectMonotonic method testRandom.

public void testRandom() throws IOException {
    final int iters = atLeast(3);
    for (int iter = 0; iter < iters; ++iter) {
        Directory dir = newDirectory();
        final int blockShift = TestUtil.nextInt(random(), DirectMonotonicWriter.MIN_BLOCK_SHIFT, DirectMonotonicWriter.MAX_BLOCK_SHIFT);
        final int maxNumValues = 1 << 20;
        final int numValues;
        if (random().nextBoolean()) {
            // random number
            numValues = TestUtil.nextInt(random(), 1, maxNumValues);
        } else {
            // multiple of the block size
            final int numBlocks = TestUtil.nextInt(random(), 0, maxNumValues >>> blockShift);
            numValues = TestUtil.nextInt(random(), 0, numBlocks) << blockShift;
        }
        List<Long> actualValues = new ArrayList<>();
        long previous = random().nextLong();
        if (numValues > 0) {
            actualValues.add(previous);
        }
        for (int i = 1; i < numValues; ++i) {
            previous += random().nextInt(1 << random().nextInt(20));
            actualValues.add(previous);
        }
        final long dataLength;
        try (IndexOutput metaOut = dir.createOutput("meta", IOContext.DEFAULT);
            IndexOutput dataOut = dir.createOutput("data", IOContext.DEFAULT)) {
            DirectMonotonicWriter w = DirectMonotonicWriter.getInstance(metaOut, dataOut, numValues, blockShift);
            for (long v : actualValues) {
                w.add(v);
            }
            w.finish();
            dataLength = dataOut.getFilePointer();
        }
        try (IndexInput metaIn = dir.openInput("meta", IOContext.READONCE);
            IndexInput dataIn = dir.openInput("data", IOContext.DEFAULT)) {
            DirectMonotonicReader.Meta meta = DirectMonotonicReader.loadMeta(metaIn, numValues, blockShift);
            LongValues values = DirectMonotonicReader.getInstance(meta, dataIn.randomAccessSlice(0, dataLength));
            for (int i = 0; i < numValues; ++i) {
                assertEquals(actualValues.get(i).longValue(), values.get(i));
            }
        }
        dir.close();
    }
}
Also used : ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) LongValues(org.apache.lucene.util.LongValues) IndexOutput(org.apache.lucene.store.IndexOutput) Directory(org.apache.lucene.store.Directory)

Example 28 with LongValues

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

the class TestDirectMonotonic method testConstantSlope.

public void testConstantSlope() throws IOException {
    Directory dir = newDirectory();
    final int blockShift = TestUtil.nextInt(random(), DirectMonotonicWriter.MIN_BLOCK_SHIFT, DirectMonotonicWriter.MAX_BLOCK_SHIFT);
    final int numValues = TestUtil.nextInt(random(), 1, 1 << 20);
    final long min = random().nextLong();
    final long inc = random().nextInt(1 << random().nextInt(20));
    List<Long> actualValues = new ArrayList<>();
    for (int i = 0; i < numValues; ++i) {
        actualValues.add(min + inc * i);
    }
    final long dataLength;
    try (IndexOutput metaOut = dir.createOutput("meta", IOContext.DEFAULT);
        IndexOutput dataOut = dir.createOutput("data", IOContext.DEFAULT)) {
        DirectMonotonicWriter w = DirectMonotonicWriter.getInstance(metaOut, dataOut, numValues, blockShift);
        for (long v : actualValues) {
            w.add(v);
        }
        w.finish();
        dataLength = dataOut.getFilePointer();
    }
    try (IndexInput metaIn = dir.openInput("meta", IOContext.READONCE);
        IndexInput dataIn = dir.openInput("data", IOContext.DEFAULT)) {
        DirectMonotonicReader.Meta meta = DirectMonotonicReader.loadMeta(metaIn, numValues, blockShift);
        LongValues values = DirectMonotonicReader.getInstance(meta, dataIn.randomAccessSlice(0, dataLength));
        for (int i = 0; i < numValues; ++i) {
            assertEquals(actualValues.get(i).longValue(), values.get(i));
        }
        assertEquals(0, dataIn.getFilePointer());
    }
    dir.close();
}
Also used : ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) LongValues(org.apache.lucene.util.LongValues) IndexOutput(org.apache.lucene.store.IndexOutput) Directory(org.apache.lucene.store.Directory)

Example 29 with LongValues

use of org.apache.lucene.util.LongValues 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 30 with LongValues

use of org.apache.lucene.util.LongValues 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)

Aggregations

LongValues (org.apache.lucene.util.LongValues)31 IOException (java.io.IOException)8 RandomAccessInput (org.apache.lucene.store.RandomAccessInput)8 IndexInput (org.apache.lucene.store.IndexInput)7 BytesRef (org.apache.lucene.util.BytesRef)6 IndexOutput (org.apache.lucene.store.IndexOutput)5 Directory (org.apache.lucene.store.Directory)4 ArrayList (java.util.ArrayList)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 NumericDocValues (org.apache.lucene.index.NumericDocValues)3 SortedDocValues (org.apache.lucene.index.SortedDocValues)3 Bits (org.apache.lucene.util.Bits)3 MultiDocValues (org.apache.lucene.index.MultiDocValues)2 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)2 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 DirectWriter (org.apache.lucene.util.packed.DirectWriter)2 FieldFacetStats (org.apache.solr.handler.component.FieldFacetStats)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1