Search in sources :

Example 36 with RoaringBitmap

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

the class RoaringBitmapSerialiser method deserialise.

@Override
public RoaringBitmap deserialise(final byte[] allBytes, final int offset, final int length) throws SerialisationException {
    final RoaringBitmap value = new RoaringBitmap();
    final byte[] convertedBytes = RoaringBitmapUtils.upConvertSerialisedForm(allBytes, offset, length);
    final ByteArrayInputStream byteIn = new ByteArrayInputStream(convertedBytes);
    final DataInputStream in = new DataInputStream(byteIn);
    try {
        value.deserialize(in);
    } catch (final IOException e) {
        throw new SerialisationException(e.getMessage(), e);
    }
    return value;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 37 with RoaringBitmap

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

the class RoaringBitmapSerialiserTest method shouldDeserialiseEmpty.

@Test
@Override
public void shouldDeserialiseEmpty() throws SerialisationException {
    // When
    final RoaringBitmap value = serialiser.deserialiseEmpty();
    // Then
    assertEquals(new RoaringBitmap(), value);
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Test(org.junit.jupiter.api.Test) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)

Example 38 with RoaringBitmap

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

the class RoaringBitmapJsonDeserialiser method deserialize.

@Override
public RoaringBitmap deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
    final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
    final TreeNode bitmapObject = treeNode.get(RoaringBitmapConstants.BITMAP_WRAPPER_OBJECT_NAME);
    if (null != bitmapObject) {
        final TextNode jsonNodes = (TextNode) bitmapObject.get(RoaringBitmapConstants.BITMAP_VALUE_FIELD_NAME);
        return (RoaringBitmap) bitmapSerialiser.deserialise(jsonNodes.binaryValue());
    } else {
        throw new IllegalArgumentException("Received null bitmap treenode");
    }
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 39 with RoaringBitmap

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

the class RoaringBitmapAggregatorTest method emptyInputBitmapGeneratesEmptyOutputBitmap.

@Test
public void emptyInputBitmapGeneratesEmptyOutputBitmap() {
    RoaringBitmap bitmap1 = new RoaringBitmap();
    RoaringBitmap bitmap2 = new RoaringBitmap();
    RoaringBitmapAggregator roaringBitmapAggregator = new RoaringBitmapAggregator();
    final RoaringBitmap result = roaringBitmapAggregator.apply(bitmap1, bitmap2);
    assertEquals(0, result.getCardinality());
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Test(org.junit.jupiter.api.Test) BinaryOperatorTest(uk.gov.gchq.koryphe.binaryoperator.BinaryOperatorTest)

Example 40 with RoaringBitmap

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

the class RoaringBitmapAggregatorTest method threeOverlappingInputBitmapsProducesSingleSortedBitmap.

@Test
public void threeOverlappingInputBitmapsProducesSingleSortedBitmap() {
    int[] inputs = new int[6];
    RoaringBitmap inputBitmap1 = new RoaringBitmap();
    int input1 = 23615000;
    int input2 = 23616440;
    inputBitmap1.add(input1);
    inputBitmap1.add(input2);
    inputs[0] = input1;
    inputs[1] = input2;
    RoaringBitmapAggregator roaringBitmapAggregator = new RoaringBitmapAggregator();
    RoaringBitmap state = roaringBitmapAggregator.apply(inputBitmap1, null);
    assertEquals(state, inputBitmap1);
    RoaringBitmap inputBitmap2 = new RoaringBitmap();
    int input3 = 23615003;
    int input4 = 23615018;
    inputBitmap2.add(input3);
    inputBitmap2.add(input4);
    inputs[2] = input3;
    inputs[3] = input4;
    state = roaringBitmapAggregator.apply(state, inputBitmap2);
    RoaringBitmap inputBitmap3 = new RoaringBitmap();
    int input5 = 23615002;
    int input6 = 23615036;
    inputBitmap3.add(input5);
    inputBitmap3.add(input6);
    inputs[4] = input5;
    inputs[5] = input6;
    state = roaringBitmapAggregator.apply(state, inputBitmap3);
    Arrays.sort(inputs);
    int outPutBitmapSize = state.getCardinality();
    assertEquals(6, outPutBitmapSize);
    int i = 0;
    for (final Integer value : state) {
        assertEquals((Integer) inputs[i], value);
        i++;
    }
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Test(org.junit.jupiter.api.Test) BinaryOperatorTest(uk.gov.gchq.koryphe.binaryoperator.BinaryOperatorTest)

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