Search in sources :

Example 1 with IntConsumer

use of org.roaringbitmap.IntConsumer in project RoaringBitmap by RoaringBitmap.

the class MapBenchmark method testMapViaBitset.

@BenchmarkMode(Mode.AverageTime)
@Benchmark
public RoaringBitmap testMapViaBitset(BenchmarkState benchmarkState) {
    final BitSet altRes = new java.util.BitSet();
    benchmarkState.bitmap.forEach(new IntConsumer() {

        @Override
        public void accept(int value) {
            altRes.set(inttointmap(value));
        }
    });
    return BitSetUtil.bitmapOf(altRes);
}
Also used : BitSet(java.util.BitSet) IntConsumer(org.roaringbitmap.IntConsumer) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with IntConsumer

use of org.roaringbitmap.IntConsumer in project RoaringBitmap by RoaringBitmap.

the class MutableInteger method testSparse.

@Test
public void testSparse() {
    MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
    for (int k = 0; k < 100000; k += 3000) bitmap.add(k);
    final MutableInteger cardinality = new MutableInteger();
    bitmap.forEach(new IntConsumer() {

        int expected = 0;

        @Override
        public void accept(int value) {
            cardinality.value++;
            Assert.assertEquals(value, expected);
            expected += 3000;
        }
    });
    Assert.assertEquals(cardinality.value, bitmap.getCardinality());
}
Also used : IntConsumer(org.roaringbitmap.IntConsumer) Test(org.junit.Test)

Example 3 with IntConsumer

use of org.roaringbitmap.IntConsumer in project RoaringBitmap by RoaringBitmap.

the class MutableInteger method testContinuous.

@Test
public void testContinuous() {
    MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
    bitmap.add(100L, 10000L);
    final MutableInteger cardinality = new MutableInteger();
    bitmap.forEach(new IntConsumer() {

        int expected = 100;

        @Override
        public void accept(int value) {
            cardinality.value++;
            Assert.assertEquals(value, expected++);
        }
    });
    Assert.assertEquals(cardinality.value, bitmap.getCardinality());
}
Also used : IntConsumer(org.roaringbitmap.IntConsumer) Test(org.junit.Test)

Example 4 with IntConsumer

use of org.roaringbitmap.IntConsumer in project RoaringBitmap by RoaringBitmap.

the class TestMappeableBitmapContainer method foreach.

@Test
public void foreach() {
    LongBuffer buffer = LongBuffer.allocate(MAX_CAPACITY / 64);
    buffer.put(~0L);
    MappeableContainer bc = new MappeableBitmapContainer(buffer.asReadOnlyBuffer(), 64);
    bc.forEach((short) 0, new IntConsumer() {

        int expected = 0;

        @Override
        public void accept(int value) {
            assertEquals(value, expected++);
        }
    });
}
Also used : LongBuffer(java.nio.LongBuffer) IntConsumer(org.roaringbitmap.IntConsumer) Test(org.junit.Test)

Example 5 with IntConsumer

use of org.roaringbitmap.IntConsumer in project RoaringBitmap by RoaringBitmap.

the class MutableInteger method testDense.

@Test
public void testDense() {
    MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
    for (int k = 0; k < 100000; k += 3) bitmap.add(k);
    final MutableInteger cardinality = new MutableInteger();
    bitmap.forEach(new IntConsumer() {

        int expected = 0;

        @Override
        public void accept(int value) {
            cardinality.value++;
            Assert.assertEquals(value, expected);
            expected += 3;
        }
    });
    Assert.assertEquals(cardinality.value, bitmap.getCardinality());
}
Also used : IntConsumer(org.roaringbitmap.IntConsumer) Test(org.junit.Test)

Aggregations

IntConsumer (org.roaringbitmap.IntConsumer)7 Test (org.junit.Test)5 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)2 LongBuffer (java.nio.LongBuffer)1 BitSet (java.util.BitSet)1 RoaringBitmap (org.roaringbitmap.RoaringBitmap)1