Search in sources :

Example 56 with RoaringBitmap

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

the class Roaring64NavigableMap method or.

/**
 * In-place bitwise OR (union) operation. The current bitmap is modified.
 *
 * @param x2 other bitmap
 */
public void or(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).or((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).or((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)

Example 57 with RoaringBitmap

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

the class Roaring64NavigableMap method and.

/**
 * In-place bitwise AND (intersection) operation. The current bitmap is modified.
 *
 * @param x2 other bitmap
 */
public void and(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) {
            // None of given high values are present in x2
            thisIterator.remove();
        } else {
            BitmapDataProvider lowBitmap1 = e1.getValue();
            if (lowBitmap2 instanceof RoaringBitmap && lowBitmap1 instanceof RoaringBitmap) {
                ((RoaringBitmap) lowBitmap1).and((RoaringBitmap) lowBitmap2);
            } else if (lowBitmap2 instanceof MutableRoaringBitmap && lowBitmap1 instanceof MutableRoaringBitmap) {
                ((MutableRoaringBitmap) lowBitmap1).and((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 58 with RoaringBitmap

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

the class Roaring64NavigableMap method deserialize.

/**
 * Deserialize (retrieve) this bitmap.
 *
 * Unlike RoaringBitmap, there is no specification for now: it may change from one java version to
 * another, and from one RoaringBitmap version to another.
 *
 * The current bitmap is overwritten.
 *
 * @param in the DataInput stream
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void deserialize(DataInput in) throws IOException {
    this.clear();
    signedLongs = in.readBoolean();
    int nbHighs = in.readInt();
    // Other NavigableMap may accept a target capacity
    highToBitmap = new TreeMap<>();
    for (int i = 0; i < nbHighs; i++) {
        int high = in.readInt();
        RoaringBitmap provider = new RoaringBitmap();
        provider.deserialize(in);
        highToBitmap.put(high, provider);
    }
    resetPerfHelpers();
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap)

Example 59 with RoaringBitmap

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

the class MapBenchmark method testMap.

@BenchmarkMode(Mode.AverageTime)
@Benchmark
public RoaringBitmap testMap(BenchmarkState benchmarkState) {
    final RoaringBitmap answer = new RoaringBitmap();
    benchmarkState.bitmap.forEach(new IntConsumer() {

        @Override
        public void accept(int value) {
            answer.add(inttointmap(value));
        }
    });
    return answer;
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) IntConsumer(org.roaringbitmap.IntConsumer) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 60 with RoaringBitmap

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

the class RoaringBitmapBenchmark method inplace_and.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap inplace_and() {
    RoaringBitmap b1 = bitmap1.clone();
    b1.and(bitmap2);
    return b1;
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

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