@Test public void fliptest1() { final MutableRoaringBitmap rb = new MutableRoaringBitmap(); rb.add(0); rb.add(2); final MutableRoaringBitmap rb2 = MutableRoaringBitmap.flip(rb, 0L, 3); final MutableRoaringBitmap result = new MutableRoaringBitmap(); result.add(1); assertEquals(result, rb2); }
public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart, final long rangeEnd) { rangeSanityCheck(rangeStart, rangeEnd); if (rangeStart >= rangeEnd) { throw new RuntimeException("Invalid range " + rangeStart + " -- " + rangeEnd); } MutableRoaringBitmap answer = new MutableRoaringBitmap(); final char hbStart = highbits(rangeStart); final char lbStart = lowbits(rangeStart); final char hbLast = highbits(rangeEnd - 1); final char lbLast = lowbits(rangeEnd - 1); answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, hbStart); final int max = (BufferUtil.maxLowBit()); for (char hb = hbStart; hb <= hbLast; ++hb) { final int containerStart = (hb == hbStart) ? (lbStart) : 0; final int containerLast = (hb == hbLast) ? (lbLast) : max; final int i = bm.highLowContainer.getIndex(hb); final int j = answer.getMappeableRoaringArray().getIndex(hb); assert j < 0; if (i >= 0) { final MappeableContainer c = bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); if (!c.isEmpty()) { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, c); } } else { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); } } answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, hbLast); return answer; }
ImmutableRoaringBitmap implements Iterable<Integer>, Cloneable, ImmutableBitmapDataProvider { public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart, final long rangeEnd) { rangeSanityCheck(rangeStart, rangeEnd); if (rangeStart >= rangeEnd) { throw new RuntimeException("Invalid range " + rangeStart + " -- " + rangeEnd); } MutableRoaringBitmap answer = new MutableRoaringBitmap(); final char hbStart = highbits(rangeStart); final char lbStart = lowbits(rangeStart); final char hbLast = highbits(rangeEnd - 1); final char lbLast = lowbits(rangeEnd - 1); answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, hbStart); final int max = (BufferUtil.maxLowBit()); for (char hb = hbStart; hb <= hbLast; ++hb) { final int containerStart = (hb == hbStart) ? (lbStart) : 0; final int containerLast = (hb == hbLast) ? (lbLast) : max; final int i = bm.highLowContainer.getIndex(hb); final int j = answer.getMappeableRoaringArray().getIndex(hb); assert j < 0; if (i >= 0) { final MappeableContainer c = bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); if (!c.isEmpty()) { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, c); } } else { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); } } answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, hbLast); return answer; } }
ImmutableRoaringBitmap implements Iterable<Integer>, Cloneable, ImmutableBitmapDataProvider { public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart, final long rangeEnd) { rangeSanityCheck(rangeStart, rangeEnd); if (rangeStart >= rangeEnd) { throw new RuntimeException("Invalid range " + rangeStart + " -- " + rangeEnd); } MutableRoaringBitmap answer = new MutableRoaringBitmap(); final char hbStart = highbits(rangeStart); final char lbStart = lowbits(rangeStart); final char hbLast = highbits(rangeEnd - 1); final char lbLast = lowbits(rangeEnd - 1); answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, hbStart); final int max = (BufferUtil.maxLowBit()); for (char hb = hbStart; hb <= hbLast; ++hb) { final int containerStart = (hb == hbStart) ? (lbStart) : 0; final int containerLast = (hb == hbLast) ? (lbLast) : max; final int i = bm.highLowContainer.getIndex(hb); final int j = answer.getMappeableRoaringArray().getIndex(hb); assert j < 0; if (i >= 0) { final MappeableContainer c = bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); if (!c.isEmpty()) { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, c); } } else { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); } } answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, hbLast); return answer; } protected  ImmutableRoaringBitmap();  ImmutableRoaringBitmap(final ByteBuffer b); }
ImmutableRoaringBitmap implements Iterable<Integer>, Cloneable, ImmutableBitmapDataProvider { public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart, final long rangeEnd) { rangeSanityCheck(rangeStart, rangeEnd); if (rangeStart >= rangeEnd) { throw new RuntimeException("Invalid range " + rangeStart + " -- " + rangeEnd); } MutableRoaringBitmap answer = new MutableRoaringBitmap(); final char hbStart = highbits(rangeStart); final char lbStart = lowbits(rangeStart); final char hbLast = highbits(rangeEnd - 1); final char lbLast = lowbits(rangeEnd - 1); answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, hbStart); final int max = (BufferUtil.maxLowBit()); for (char hb = hbStart; hb <= hbLast; ++hb) { final int containerStart = (hb == hbStart) ? (lbStart) : 0; final int containerLast = (hb == hbLast) ? (lbLast) : max; final int i = bm.highLowContainer.getIndex(hb); final int j = answer.getMappeableRoaringArray().getIndex(hb); assert j < 0; if (i >= 0) { final MappeableContainer c = bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); if (!c.isEmpty()) { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, c); } } else { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); } } answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, hbLast); return answer; } protected  ImmutableRoaringBitmap();  ImmutableRoaringBitmap(final ByteBuffer b); static MutableRoaringBitmap and(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static MutableRoaringBitmap and(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final int rangeStart, final int rangeEnd); static MutableRoaringBitmap and(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static int andCardinality(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static int xorCardinality(final ImmutableRoaringBitmap x1,
                                   final ImmutableRoaringBitmap x2); static int andNotCardinality(final ImmutableRoaringBitmap x1,
                                      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2, long rangeStart, long rangeEnd); @Deprecated static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1,
                                              final ImmutableRoaringBitmap x2,
                                              final int rangeStart, final int rangeEnd); static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap orNot(
          final ImmutableRoaringBitmap x1, final ImmutableRoaringBitmap x2, long rangeEnd); static ImmutableRoaringBitmap bitmapOf(final int... data); static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart,
      final long rangeEnd); @Deprecated static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm,
                                            final int rangeStart, final int rangeEnd); static boolean intersects(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps); static MutableRoaringBitmap or(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap or(Iterator<? extends ImmutableRoaringBitmap> bitmaps); static MutableRoaringBitmap or(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static MutableRoaringBitmap or(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); static int orCardinality(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap xor(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static MutableRoaringBitmap xor(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); static MutableRoaringBitmap xor(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); @Override ImmutableRoaringBitmap clone(); @Override boolean contains(final int x); boolean contains(long minimum, long supremum); boolean contains(ImmutableRoaringBitmap subset); @Override boolean equals(Object o); boolean isHammingSimilar(ImmutableRoaringBitmap other, int tolerance); boolean intersects(long minimum, long supremum); @Override long getLongCardinality(); @Override int getCardinality(); @Override void forEach(IntConsumer ic); MappeableContainerPointer getContainerPointer(); @Override PeekableIntIterator getIntIterator(); @Override IntIterator getReverseIntIterator(); @Override BatchIterator getBatchIterator(); @Override long getLongSizeInBytes(); @Override int getSizeInBytes(); @Override int hashCode(); boolean hasRunCompression(); @Override boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override MutableRoaringBitmap limit(int maxcardinality); @Override long rankLong(int x); @Override long rangeCardinality(long start, long end); @Override int rank(int x); @Override int select(int j); @Override int first(); @Override int last(); @Override long nextValue(int fromValue); @Override long previousValue(int fromValue); @Override long nextAbsentValue(int fromValue); @Override long previousAbsentValue(int fromValue); @Override void serialize(DataOutput out); @Override void serialize(ByteBuffer buffer); @Override int serializedSizeInBytes(); @Override int[] toArray(); MutableRoaringBitmap toMutableRoaringBitmap(); RoaringBitmap toRoaringBitmap(); @Override String toString(); }
ImmutableRoaringBitmap implements Iterable<Integer>, Cloneable, ImmutableBitmapDataProvider { public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart, final long rangeEnd) { rangeSanityCheck(rangeStart, rangeEnd); if (rangeStart >= rangeEnd) { throw new RuntimeException("Invalid range " + rangeStart + " -- " + rangeEnd); } MutableRoaringBitmap answer = new MutableRoaringBitmap(); final char hbStart = highbits(rangeStart); final char lbStart = lowbits(rangeStart); final char hbLast = highbits(rangeEnd - 1); final char lbLast = lowbits(rangeEnd - 1); answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, hbStart); final int max = (BufferUtil.maxLowBit()); for (char hb = hbStart; hb <= hbLast; ++hb) { final int containerStart = (hb == hbStart) ? (lbStart) : 0; final int containerLast = (hb == hbLast) ? (lbLast) : max; final int i = bm.highLowContainer.getIndex(hb); final int j = answer.getMappeableRoaringArray().getIndex(hb); assert j < 0; if (i >= 0) { final MappeableContainer c = bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); if (!c.isEmpty()) { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, c); } } else { answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); } } answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, hbLast); return answer; } protected  ImmutableRoaringBitmap();  ImmutableRoaringBitmap(final ByteBuffer b); static MutableRoaringBitmap and(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static MutableRoaringBitmap and(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final int rangeStart, final int rangeEnd); static MutableRoaringBitmap and(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static int andCardinality(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static int xorCardinality(final ImmutableRoaringBitmap x1,
                                   final ImmutableRoaringBitmap x2); static int andNotCardinality(final ImmutableRoaringBitmap x1,
                                      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2, long rangeStart, long rangeEnd); @Deprecated static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1,
                                              final ImmutableRoaringBitmap x2,
                                              final int rangeStart, final int rangeEnd); static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap orNot(
          final ImmutableRoaringBitmap x1, final ImmutableRoaringBitmap x2, long rangeEnd); static ImmutableRoaringBitmap bitmapOf(final int... data); static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart,
      final long rangeEnd); @Deprecated static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm,
                                            final int rangeStart, final int rangeEnd); static boolean intersects(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps); static MutableRoaringBitmap or(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap or(Iterator<? extends ImmutableRoaringBitmap> bitmaps); static MutableRoaringBitmap or(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static MutableRoaringBitmap or(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); static int orCardinality(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); static MutableRoaringBitmap xor(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static MutableRoaringBitmap xor(final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); static MutableRoaringBitmap xor(final ImmutableRoaringBitmap x1,
      final ImmutableRoaringBitmap x2); @Override ImmutableRoaringBitmap clone(); @Override boolean contains(final int x); boolean contains(long minimum, long supremum); boolean contains(ImmutableRoaringBitmap subset); @Override boolean equals(Object o); boolean isHammingSimilar(ImmutableRoaringBitmap other, int tolerance); boolean intersects(long minimum, long supremum); @Override long getLongCardinality(); @Override int getCardinality(); @Override void forEach(IntConsumer ic); MappeableContainerPointer getContainerPointer(); @Override PeekableIntIterator getIntIterator(); @Override IntIterator getReverseIntIterator(); @Override BatchIterator getBatchIterator(); @Override long getLongSizeInBytes(); @Override int getSizeInBytes(); @Override int hashCode(); boolean hasRunCompression(); @Override boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override MutableRoaringBitmap limit(int maxcardinality); @Override long rankLong(int x); @Override long rangeCardinality(long start, long end); @Override int rank(int x); @Override int select(int j); @Override int first(); @Override int last(); @Override long nextValue(int fromValue); @Override long previousValue(int fromValue); @Override long nextAbsentValue(int fromValue); @Override long previousAbsentValue(int fromValue); @Override void serialize(DataOutput out); @Override void serialize(ByteBuffer buffer); @Override int serializedSizeInBytes(); @Override int[] toArray(); MutableRoaringBitmap toMutableRoaringBitmap(); RoaringBitmap toRoaringBitmap(); @Override String toString();  }