Search in sources :

Example 31 with RoaringBitmap

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

the class Conj method addIfValid.

protected boolean addIfValid(long at, int id) {
    Object what = event.getIfAbsentPut(at, () -> new byte[ROARING_UPGRADE_THRESH]);
    if (what instanceof RoaringBitmap) {
        RoaringBitmap r = (RoaringBitmap) what;
        if (!r.contains(-id)) {
            r.add(id);
            return true;
        }
    } else {
        byte[] ii = (byte[]) what;
        if (indexOfZeroTerminated(ii, ((byte) -id)) == -1) {
            int nextSlot = indexOfZeroTerminated(ii, (byte) 0);
            if (nextSlot != -1) {
                ii[nextSlot] = (byte) id;
            } else {
                // upgrade to roaring and add
                RoaringBitmap rb = new RoaringBitmap();
                for (byte b : ii) rb.add(b);
                rb.add(id);
                event.put(at, rb);
            }
            return true;
        }
    }
    return false;
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 32 with RoaringBitmap

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

the class SpaceKeys method accept.

@Override
public void accept(JoglWindow j) {
    RoaringBitmap queue = this.queue;
    if (!queue.isEmpty()) {
        float dt = j.dtMS() / 1000f;
        synchronized (on) {
            this.queue = new RoaringBitmap();
        }
        queue.forEach((int k) -> {
            // shouldnt ever be zero actually
            boolean s = k >= 0;
            FloatProcedure f = ((s) ? keyPressed : keyReleased).get(Math.abs(k));
            if (f != null)
                f.value(dt);
        });
    }
}
Also used : FloatProcedure(org.eclipse.collections.api.block.procedure.primitive.FloatProcedure) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 33 with RoaringBitmap

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

the class TestVertexImpl method getVertexManagerEvent.

private VertexManagerEvent getVertexManagerEvent(long[] sizes, long totalSize, Vertex vertex) throws IOException {
    ByteBuffer payload = null;
    if (sizes != null) {
        RoaringBitmap partitionStats = ShuffleUtils.getPartitionStatsForPhysicalOutput(sizes);
        DataOutputBuffer dout = new DataOutputBuffer();
        partitionStats.serialize(dout);
        ByteString partitionStatsBytes = TezCommonUtils.compressByteArrayToByteString(dout.getData());
        payload = ShuffleUserPayloads.VertexManagerEventPayloadProto.newBuilder().setOutputSize(totalSize).setPartitionStats(partitionStatsBytes).build().toByteString().asReadOnlyByteBuffer();
    } else {
        payload = ShuffleUserPayloads.VertexManagerEventPayloadProto.newBuilder().setOutputSize(totalSize).build().toByteString().asReadOnlyByteBuffer();
    }
    VertexManagerEvent vmEvent = VertexManagerEvent.create(vertex.getName(), payload);
    return vmEvent;
}
Also used : VertexManagerEvent(org.apache.tez.runtime.api.events.VertexManagerEvent) ByteString(com.google.protobuf.ByteString) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) ByteBuffer(java.nio.ByteBuffer) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 34 with RoaringBitmap

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

the class ShuffleUtils method getPartitionStatsForPhysicalOutput.

/**
 * Data size for the destinations
 *
 * @param sizes for physical outputs
 */
public static RoaringBitmap getPartitionStatsForPhysicalOutput(long[] sizes) {
    RoaringBitmap partitionStats = new RoaringBitmap();
    if (sizes == null || sizes.length == 0) {
        return partitionStats;
    }
    final int RANGE_LEN = DATA_RANGE_IN_MB.values().length;
    for (int i = 0; i < sizes.length; i++) {
        int bucket = DATA_RANGE_IN_MB.getRange(sizes[i]).ordinal();
        int index = i * (RANGE_LEN);
        partitionStats.add(index + bucket);
    }
    return partitionStats;
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 35 with RoaringBitmap

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

the class HiveManifestUtils method compressFileNamesUsingRoaringBitmap.

private static String compressFileNamesUsingRoaringBitmap(List<String> fileNames) {
    RoaringBitmap roaringBitmap = new RoaringBitmap();
    // Add file names to roaring bitmap
    fileNames.forEach(name -> roaringBitmap.add(Integer.parseInt(name)));
    // Serialize the compressed data into ByteBuffer
    ByteBuffer byteBuffer = ByteBuffer.allocate(roaringBitmap.serializedSizeInBytes());
    roaringBitmap.serialize(byteBuffer);
    byteBuffer.flip();
    return new String(byteBuffer.array(), ISO_8859_1);
}
Also used : ByteBuffer(java.nio.ByteBuffer) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Aggregations

RoaringBitmap (org.roaringbitmap.RoaringBitmap)85 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 ByteBuffer (java.nio.ByteBuffer)6 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)6 BitmapDataProvider (org.roaringbitmap.BitmapDataProvider)6 ByteString (com.google.protobuf.ByteString)5 Setup (org.openjdk.jmh.annotations.Setup)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 FasterList (jcog.list.FasterList)4 Term (nars.term.Term)4 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4