Search in sources :

Example 51 with RoaringBitmap

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

the class RunContainerRealDataBenchmarkRunOptimize method clone.

@Benchmark
public int clone(BenchmarkState benchmarkState) {
    int total = 0;
    for (int i = 0; i < benchmarkState.ac.size(); i++) {
        RoaringBitmap bitmap = benchmarkState.ac.get(i).clone();
        total += bitmap.getCardinality();
    }
    return total;
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 52 with RoaringBitmap

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

the class RunContainerRealDataBenchmarkRunOptimize method serializeToBAOSNoClone.

@Benchmark
public int serializeToBAOSNoClone(BenchmarkState benchmarkState) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    for (int i = 0; i < benchmarkState.ac.size(); i++) {
        RoaringBitmap bitmap = benchmarkState.ac.get(i);
        bitmap.serialize(dos);
    }
    dos.flush();
    return bos.size();
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RoaringBitmap(org.roaringbitmap.RoaringBitmap) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 53 with RoaringBitmap

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

the class TestRoaringBitmap method conversionTest.

@Test
public void conversionTest() {
    RoaringBitmap rb = new RoaringBitmap();
    for (int i = 0; i < 100; i++) {
        rb.add(i);
    }
    for (int i = 0; i < 100; i++) {
        rb.add(i * 2 + (1 << 16));
    }
    for (int i = 0; i < (1 << 16); i++) {
        rb.add(i * 2 + 2 * (1 << 16));
    }
    rb.runOptimize();
    MutableRoaringBitmap mrb = rb.toMutableRoaringBitmap();
    RoaringBitmap rb2 = mrb.toRoaringBitmap();
    Assert.assertEquals(rb, rb2);
    ImmutableRoaringBitmap irb = toMapped(mrb);
    Assert.assertEquals(irb.toRoaringBitmap(), rb2);
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Test(org.junit.Test)

Example 54 with RoaringBitmap

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

the class Roaring64NavigableMap method andNot.

/**
 * In-place bitwise ANDNOT (difference) operation. The current bitmap is modified.
 *
 * @param x2 other bitmap
 */
public void andNot(final Roaring64NavigableMap x2) {
    boolean firstBucket = true;
    Iterator<Entry<Integer, BitmapDataProvider>> thisIterator = highToBitmap.entrySet().iterator();
    while (thisIterator.hasNext()) {
        Entry<Integer, BitmapDataProvider> e1 = thisIterator.next();
        // Keep object to prevent auto-boxing
        Integer high = e1.getKey();
        BitmapDataProvider lowBitmap2 = x2.highToBitmap.get(high);
        if (lowBitmap2 != null) {
            BitmapDataProvider lowBitmap1 = e1.getValue();
            if (lowBitmap2 instanceof RoaringBitmap && lowBitmap1 instanceof RoaringBitmap) {
                ((RoaringBitmap) lowBitmap1).andNot((RoaringBitmap) lowBitmap2);
            } else if (lowBitmap2 instanceof MutableRoaringBitmap && lowBitmap1 instanceof MutableRoaringBitmap) {
                ((MutableRoaringBitmap) lowBitmap1).andNot((MutableRoaringBitmap) lowBitmap2);
            } else {
                throw new UnsupportedOperationException(".and is not between " + this.getClass() + " and " + lowBitmap1.getClass());
            }
        }
        if (firstBucket) {
            firstBucket = false;
            // Invalidate the lowest high as lowest not valid
            firstHighNotValid = Math.min(firstHighNotValid, high);
            allValid = false;
        }
    }
}
Also used : Entry(java.util.Map.Entry) MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) BitmapDataProvider(org.roaringbitmap.BitmapDataProvider) RoaringBitmap(org.roaringbitmap.RoaringBitmap) MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap)

Example 55 with RoaringBitmap

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

the class Roaring64NavigableMap method xor.

/**
 * In-place bitwise XOR (symmetric difference) operation. The current bitmap is modified.
 *
 * @param x2 other bitmap
 */
public void xor(final Roaring64NavigableMap x2) {
    boolean firstBucket = true;
    for (Entry<Integer, BitmapDataProvider> e2 : x2.highToBitmap.entrySet()) {
        // Keep object to prevent auto-boxing
        Integer high = e2.getKey();
        BitmapDataProvider lowBitmap1 = this.highToBitmap.get(high);
        BitmapDataProvider lowBitmap2 = e2.getValue();
        // not on buffer
        if ((lowBitmap1 == null || lowBitmap1 instanceof RoaringBitmap) && lowBitmap2 instanceof RoaringBitmap) {
            if (lowBitmap1 == null) {
                // Clone to prevent future modification of this modifying the input Bitmap
                RoaringBitmap lowBitmap2Clone = ((RoaringBitmap) lowBitmap2).clone();
                pushBitmapForHigh(high, lowBitmap2Clone);
            } else {
                ((RoaringBitmap) lowBitmap1).xor((RoaringBitmap) lowBitmap2);
            }
        } else if ((lowBitmap1 == null || lowBitmap1 instanceof MutableRoaringBitmap) && lowBitmap2 instanceof MutableRoaringBitmap) {
            if (lowBitmap1 == null) {
                // Clone to prevent future modification of this modifying the input Bitmap
                BitmapDataProvider lowBitmap2Clone = ((MutableRoaringBitmap) lowBitmap2).clone();
                pushBitmapForHigh(high, lowBitmap2Clone);
            } else {
                ((MutableRoaringBitmap) lowBitmap1).xor((MutableRoaringBitmap) lowBitmap2);
            }
        } else {
            throw new UnsupportedOperationException(".or is not between " + this.getClass() + " and " + lowBitmap2.getClass());
        }
        if (firstBucket) {
            firstBucket = false;
            // Invalidate the lowest high as lowest not valid
            firstHighNotValid = Math.min(firstHighNotValid, high);
            allValid = false;
        }
    }
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) BitmapDataProvider(org.roaringbitmap.BitmapDataProvider) RoaringBitmap(org.roaringbitmap.RoaringBitmap) MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap)

Aggregations

RoaringBitmap (org.roaringbitmap.RoaringBitmap)81 Benchmark (org.openjdk.jmh.annotations.Benchmark)14 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)9 DataOutputStream (java.io.DataOutputStream)8 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 DataInputStream (java.io.DataInputStream)7 IOException (java.io.IOException)7 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)6 BitmapDataProvider (org.roaringbitmap.BitmapDataProvider)6 ByteString (com.google.protobuf.ByteString)5 ByteBuffer (java.nio.ByteBuffer)5 Setup (org.openjdk.jmh.annotations.Setup)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 FasterList (jcog.list.FasterList)4 Term (nars.term.Term)4