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