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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations