Search in sources :

Example 76 with RoaringBitmap

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

the class RoaringBitmapAggregatorTest method aggregatorDealsWithNullInput.

@Test
public void aggregatorDealsWithNullInput() {
    RoaringBitmapAggregator roaringBitmapAggregator = new RoaringBitmapAggregator();
    final RoaringBitmap state = roaringBitmapAggregator.apply(null, null);
    assertNull(state);
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Test(org.junit.jupiter.api.Test) BinaryOperatorTest(uk.gov.gchq.koryphe.binaryoperator.BinaryOperatorTest)

Example 77 with RoaringBitmap

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

the class RoaringBitmapAggregatorTest method singleInputBitmapGeneratesIdenticalOutputBitmap.

@Test
public void singleInputBitmapGeneratesIdenticalOutputBitmap() {
    RoaringBitmap inputBitmap = new RoaringBitmap();
    int input1 = 123298333;
    int input2 = 342903339;
    inputBitmap.add(input1);
    inputBitmap.add(input2);
    RoaringBitmapAggregator roaringBitmapAggregator = new RoaringBitmapAggregator();
    final RoaringBitmap result = roaringBitmapAggregator.apply(inputBitmap, null);
    assertEquals(2, result.getCardinality());
    assertEquals(inputBitmap, result);
}
Also used : RoaringBitmap(org.roaringbitmap.RoaringBitmap) Test(org.junit.jupiter.api.Test) BinaryOperatorTest(uk.gov.gchq.koryphe.binaryoperator.BinaryOperatorTest)

Example 78 with RoaringBitmap

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

the class RoaringBitmapJsonSerialisationTest method testCanDeserialiseVersionZeroPointThreePointFourBitmap.

@Test
public void testCanDeserialiseVersionZeroPointThreePointFourBitmap() throws IOException {
    // Bitmap of (2,3000,300000) serialised in 0.3.4 Roaring Bitmap base 64 encoded
    String serialisedBitmap = "{\"roaringBitmap\":{\"value\":\"OTAAAAIAAAAAAAEABAAAAAIAuAvgkw==\"}}";
    RoaringBitmap comparisonBitmap = new RoaringBitmap();
    comparisonBitmap.add(2);
    comparisonBitmap.add(3000);
    comparisonBitmap.add(300000);
    JsonParser parser = JSON_FACTORY.createParser(serialisedBitmap);
    parser.setCodec(new ObjectMapper());
    Object o = DESERIALISER.deserialize(parser, null);
    assertEquals(RoaringBitmap.class, o.getClass());
    assertEquals(comparisonBitmap, o);
    ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
    JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
    SERIALISER.serialize((RoaringBitmap) o, jsonGenerator, null);
    jsonGenerator.flush();
    byte[] bytes = byteArrayBuilder.toByteArray();
    String reSerialisedBitmap = new String(bytes);
    byteArrayBuilder = new ByteArrayBuilder();
    jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
    SERIALISER.serialize(comparisonBitmap, jsonGenerator, null);
    jsonGenerator.flush();
    String serialisedComparisonBitmap = new String(byteArrayBuilder.toByteArray());
    assertNotEquals(reSerialisedBitmap, serialisedBitmap);
    assertEquals(reSerialisedBitmap, serialisedComparisonBitmap);
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayBuilder(com.fasterxml.jackson.core.util.ByteArrayBuilder) RoaringBitmap(org.roaringbitmap.RoaringBitmap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.jupiter.api.Test)

Example 79 with RoaringBitmap

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

the class RoaringBitmapJsonSerialisationTest method testCanSerialiseAndDeserialise.

@Test
public void testCanSerialiseAndDeserialise() throws IOException {
    final ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
    JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
    RoaringBitmap testBitmap = new RoaringBitmap();
    testBitmap.add(2);
    testBitmap.add(3000);
    testBitmap.add(300000);
    for (int i = 400000; i < 500000; i += 2) {
        testBitmap.add(i);
    }
    SERIALISER.serialize(testBitmap, jsonGenerator, null);
    jsonGenerator.flush();
    byte[] serialisedBitmap = byteArrayBuilder.toByteArray();
    JsonParser parser = JSON_FACTORY.createParser(serialisedBitmap);
    parser.setCodec(new ObjectMapper());
    Object o = DESERIALISER.deserialize(parser, null);
    assertEquals(RoaringBitmap.class, o.getClass());
    assertEquals(testBitmap, o);
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayBuilder(com.fasterxml.jackson.core.util.ByteArrayBuilder) RoaringBitmap(org.roaringbitmap.RoaringBitmap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.jupiter.api.Test)

Example 80 with RoaringBitmap

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

the class RoaringBitmapJsonSerialisationTest method testCanSerialiseWithCustomObjectMapper.

@Test
public void testCanSerialiseWithCustomObjectMapper() throws IOException {
    // Bitmap of (2,3000,300000) serialised in 0.5.11 Roaring Bitmap base 64 encoded
    String serialisedComparisonBitmap = "{\"roaringBitmap\":{\"value\":\"OjAAAAIAAAAAAAEABAAAABgAAAAcAAAAAgC4C+CT\"}}";
    RoaringBitmap comparisonBitmap = new RoaringBitmap();
    comparisonBitmap.add(2);
    comparisonBitmap.add(3000);
    comparisonBitmap.add(300000);
    final ObjectMapper mapper = JSONSerialiser.createDefaultMapper();
    final SimpleModule bitmapModule = new SimpleModule(RoaringBitmapConstants.BITMAP_MODULE_NAME, new Version(1, 0, 9, null, null, null));
    bitmapModule.addSerializer(RoaringBitmap.class, new RoaringBitmapJsonSerialiser());
    bitmapModule.addDeserializer(RoaringBitmap.class, new RoaringBitmapJsonDeserialiser());
    mapper.registerModule(bitmapModule);
    RoaringBitmap testBitmap = mapper.readValue(serialisedComparisonBitmap, RoaringBitmap.class);
    assertEquals(comparisonBitmap, testBitmap);
    String serialisedBitmap = mapper.writeValueAsString(testBitmap);
    assertEquals(serialisedBitmap, serialisedComparisonBitmap);
}
Also used : Version(com.fasterxml.jackson.core.Version) RoaringBitmap(org.roaringbitmap.RoaringBitmap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.junit.jupiter.api.Test)

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