@Test @SuppressWarnings("deprecation") public void testDeprecatedIteratorXor() { MutableRoaringBitmap rb1 = new MutableRoaringBitmap(); MutableRoaringBitmap rb2 = new MutableRoaringBitmap(); List<MutableRoaringBitmap> list = new ArrayList<>(); list.add(rb1); list.add(rb2); rb1.add(200000L, 400000L); // two normal positive ranges rb2.add(300000L, 500000L); // full XOR is 200000 to 299999, 400000-4999999 MutableRoaringBitmap result = ImmutableRoaringBitmap.xor(list.iterator(), 250000L, 450000L); MutableRoaringBitmap resultInt = ImmutableRoaringBitmap.xor(list.iterator(), 250000, 450000); Assert.assertTrue(result.equals(resultInt)); Assert.assertEquals(100000, result.getCardinality()); // empty ranges get empty result resultInt = ImmutableRoaringBitmap.xor(list.iterator(), 300000, 200000); result = ImmutableRoaringBitmap.xor(list.iterator(), 300000L, 200000L); Assert.assertTrue(result.equals(resultInt)); Assert.assertEquals(0, resultInt.getCardinality()); }
@Test public void simpleTest() throws IOException { final org.roaringbitmap.buffer.MutableRoaringBitmap rr = MutableRoaringBitmap.bitmapOf(1, 2, 3, 1000); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(bos); rr.serialize(dos); dos.close(); final ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray()); final ImmutableRoaringBitmap rrback = new ImmutableRoaringBitmap(bb); Assert.assertTrue(rr.equals(rrback)); }
@Test public void ANDNOTtestA() { // both have run containers final MutableRoaringBitmap rr = new MutableRoaringBitmap(); for (int k = 4000; k < 4256; ++k) { rr.add(k); } for (int k = 65536; k < 65536 + 4000; ++k) { rr.add(k); } for (int k = 3 * 65536; k < 3 * 65536 + 9000; ++k) { rr.add(k); } for (int k = 4 * 65535; k < 4 * 65535 + 7000; ++k) { rr.add(k); } for (int k = 6 * 65535; k < 6 * 65535 + 10000; ++k) { rr.add(k); } for (int k = 8 * 65535; k < 8 * 65535 + 1000; ++k) { rr.add(k); } for (int k = 9 * 65535; k < 9 * 65535 + 30000; ++k) { rr.add(k); } rr.runOptimize(); final MutableRoaringBitmap rr2 = new MutableRoaringBitmap(); for (int k = 4000; k < 4256; ++k) { rr2.add(k); } for (int k = 65536; k < 65536 + 4000; ++k) { rr2.add(k); } for (int k = 3 * 65536 + 2000; k < 3 * 65536 + 6000; ++k) { rr2.add(k); } for (int k = 6 * 65535; k < 6 * 65535 + 1000; ++k) { rr2.add(k); } for (int k = 7 * 65535; k < 7 * 65535 + 1000; ++k) { rr2.add(k); } for (int k = 10 * 65535; k < 10 * 65535 + 5000; ++k) { rr2.add(k); } rr2.runOptimize(); final MutableRoaringBitmap correct = MutableRoaringBitmap.andNot(rr, rr2); rr.andNot(rr2); Assert.assertTrue(correct.equals(rr)); Assert.assertTrue(correct.hashCode() == rr.hashCode()); }