Complement of roaring bit map returns incorrect result.
It seems that complement does not work on the last bit of the roaring bitmap.
I used following test code and all tests passed with concise bitmap but failed with roaring bitmap.
Result shows the last bit of roaring bitmap is unchanged even after complement operation.
public class RoaringBitmapTest
{
@Parameterized.Parameters
public static Iterable<Object[]> constructorFeeder()
{
return ImmutableList.of(
new Object[]{new ConciseBitmapFactory()},
new Object[]{new RoaringBitmapFactory()}
);
}
private final BitmapFactory testBitmapFactory;
public RoaringBitmapTest(BitmapFactory bitmapFactory)
{
this.testBitmapFactory = bitmapFactory;
}
@Test
public void testComplement1()
{
final MutableBitmap mutableBitmap = testBitmapFactory.makeEmptyMutableBitmap();
mutableBitmap.add(0);
mutableBitmap.add(2);
mutableBitmap.add(7);
ImmutableBitmap testBitmap = testBitmapFactory.makeImmutableBitmap(mutableBitmap);
ImmutableBitmap immutableBitmap = testBitmapFactory.complement(testBitmap, 8);
String result = immutableBitmap.toString().replaceAll("\\s","").split("\\[|\\]|\\{|\\}")[1];
Assert.assertEquals("1,3,4,5,6", result);
}
@Test
public void testComplement2()
{
final MutableBitmap mutableBitmap = testBitmapFactory.makeEmptyMutableBitmap();
mutableBitmap.add(0);
mutableBitmap.add(2);
ImmutableBitmap testBitmap = testBitmapFactory.makeImmutableBitmap(mutableBitmap);
ImmutableBitmap immutableBitmap = testBitmapFactory.complement(testBitmap, 4);
String result = immutableBitmap.toString().replaceAll("\\s","").split("\\[|\\]|\\{|\\}")[1];
Assert.assertEquals("1,3", result);
}
@Test
public void testComplement3()
{
final MutableBitmap mutableBitmap = testBitmapFactory.makeEmptyMutableBitmap();
mutableBitmap.add(4);
mutableBitmap.add(5);
ImmutableBitmap testBitmap = testBitmapFactory.makeImmutableBitmap(mutableBitmap);
ImmutableBitmap immutableBitmap = testBitmapFactory.complement(testBitmap, 10);
String result = immutableBitmap.toString().replaceAll("\\s","").split("\\[|\\]|\\{|\\}")[1];
Assert.assertEquals("0,1,2,3,6,7,8,9", result);
}
}
Complement of roaring bit map returns incorrect result.
It seems that complement does not work on the last bit of the roaring bitmap.
I used following test code and all tests passed with concise bitmap but failed with roaring bitmap.
Result shows the last bit of roaring bitmap is unchanged even after complement operation.