@Test public void andNot() { final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb2 = new RoaringBitmap(); rb.add(1); rb.add(1 << 16); rb2.add(1 << 16); rb.add(2 << 16); rb.add(3 << 16); rb2.add(3 << 16); rb.andNot(rb2); final IntIterator i = rb.getIntIterator(); assertTrue(i.hasNext()); assertEquals(1, i.next()); assertTrue(i.hasNext()); assertEquals(2 << 16, i.next()); assertFalse(i.hasNext()); }
public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2) { final RoaringBitmap answer = new RoaringBitmap(); int pos1 = 0, pos2 = 0; final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); while (pos1 < length1 && pos2 < length2) { final char s1 = x1.highLowContainer.getKeyAtIndex(pos1); final char s2 = x2.highLowContainer.getKeyAtIndex(pos2); if (s1 == s2) { final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); final Container c = c1.andNot(c2); if (!c.isEmpty()) { answer.highLowContainer.append(s1, c); } ++pos1; ++pos2; } else if (s1 < s2) { final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, nextPos1); pos1 = nextPos1; } else { pos2 = x2.highLowContainer.advanceUntil(s1, pos2); } } if (pos2 == length2) { answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); } return answer; }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2) { final RoaringBitmap answer = new RoaringBitmap(); int pos1 = 0, pos2 = 0; final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); while (pos1 < length1 && pos2 < length2) { final char s1 = x1.highLowContainer.getKeyAtIndex(pos1); final char s2 = x2.highLowContainer.getKeyAtIndex(pos2); if (s1 == s2) { final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); final Container c = c1.andNot(c2); if (!c.isEmpty()) { answer.highLowContainer.append(s1, c); } ++pos1; ++pos2; } else if (s1 < s2) { final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, nextPos1); pos1 = nextPos1; } else { pos2 = x2.highLowContainer.advanceUntil(s1, pos2); } } if (pos2 == length2) { answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); } return answer; } }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2) { final RoaringBitmap answer = new RoaringBitmap(); int pos1 = 0, pos2 = 0; final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); while (pos1 < length1 && pos2 < length2) { final char s1 = x1.highLowContainer.getKeyAtIndex(pos1); final char s2 = x2.highLowContainer.getKeyAtIndex(pos2); if (s1 == s2) { final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); final Container c = c1.andNot(c2); if (!c.isEmpty()) { answer.highLowContainer.append(s1, c); } ++pos1; ++pos2; } else if (s1 < s2) { final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, nextPos1); pos1 = nextPos1; } else { pos2 = x2.highLowContainer.advanceUntil(s1, pos2); } } if (pos2 == length2) { answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); } return answer; } RoaringBitmap();   RoaringBitmap(RoaringArray highLowContainer);  RoaringBitmap(ImmutableRoaringBitmap rb); }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2) { final RoaringBitmap answer = new RoaringBitmap(); int pos1 = 0, pos2 = 0; final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); while (pos1 < length1 && pos2 < length2) { final char s1 = x1.highLowContainer.getKeyAtIndex(pos1); final char s2 = x2.highLowContainer.getKeyAtIndex(pos2); if (s1 == s2) { final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); final Container c = c1.andNot(c2); if (!c.isEmpty()) { answer.highLowContainer.append(s1, c); } ++pos1; ++pos2; } else if (s1 < s2) { final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, nextPos1); pos1 = nextPos1; } else { pos2 = x2.highLowContainer.advanceUntil(s1, pos2); } } if (pos2 == length2) { answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); } return answer; } RoaringBitmap();   RoaringBitmap(RoaringArray highLowContainer);  RoaringBitmap(ImmutableRoaringBitmap rb); static RoaringBitmap addOffset(final RoaringBitmap x, long offset); static RoaringBitmap add(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap add(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap and(final RoaringBitmap x1, final RoaringBitmap x2); static int andCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2); void add(final int... dat); void addN(final int[] dat, final int offset, final int n); static RoaringBitmap bitmapOf(final int... dat); static RoaringBitmap bitmapOfUnordered(final int... data); static RoaringBitmap flip(RoaringBitmap bm, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap flip(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap or(Iterator<? extends RoaringBitmap> bitmaps); static RoaringBitmap or(RoaringBitmap... bitmaps); static RoaringBitmap or(final RoaringBitmap x1, final RoaringBitmap x2); static int orCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int xorCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int andNotCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap remove(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap remove(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap xor(final RoaringBitmap x1, final RoaringBitmap x2); @Override void add(final int x); void add(final long rangeStart, final long rangeEnd); @Deprecated void add(final int rangeStart, final int rangeEnd); boolean intersects(long minimum, long supremum); void and(final RoaringBitmap x2); static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final int rangeStart, final int rangeEnd); void andNot(final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
      long rangeStart, long rangeEnd); @Deprecated static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
          final int rangeStart, final int rangeEnd); void orNot(final RoaringBitmap other, long rangeEnd); static RoaringBitmap orNot(
          final RoaringBitmap x1, final RoaringBitmap x2, long rangeEnd); boolean checkedAdd(final int x); boolean checkedRemove(final int x); void clear(); @Override RoaringBitmap clone(); @Override boolean contains(final int x); boolean contains(long minimum, long supremum); void deserialize(DataInput in, byte[] buffer); void deserialize(DataInput in); void deserialize(ByteBuffer bbf); @Override boolean equals(Object o); boolean isHammingSimilar(RoaringBitmap other, int tolerance); void flip(final int x); void flip(final long rangeStart, final long rangeEnd); @Deprecated void flip(final int rangeStart, final int rangeEnd); @Override long getLongCardinality(); @Override int getCardinality(); @Override void forEach(IntConsumer ic); ContainerPointer getContainerPointer(); @Override PeekableIntIterator getIntIterator(); @Override IntIterator getReverseIntIterator(); @Override RoaringBatchIterator getBatchIterator(); @Override long getLongSizeInBytes(); @Override int getSizeInBytes(); @Override int hashCode(); boolean hasRunCompression(); @Override boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override RoaringBitmap limit(int maxcardinality); void or(final RoaringBitmap x2); static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); @Override long rankLong(int x); @Override long rangeCardinality(long start, long end); @Override int rank(int x); @Override void readExternal(ObjectInput in); @Override void remove(final int x); void remove(final long rangeStart, final long rangeEnd); @Deprecated void remove(final int rangeStart, final int rangeEnd); boolean removeRunCompression(); boolean runOptimize(); boolean contains(RoaringBitmap subset); @Override int select(int j); @Override long nextValue(int fromValue); @Override long previousValue(int fromValue); @Override long nextAbsentValue(int fromValue); @Override long previousAbsentValue(int fromValue); @Override int first(); @Override int last(); @Override void serialize(DataOutput out); @Override void serialize(ByteBuffer buffer); static long maximumSerializedSize(long cardinality, long universe_size); @Override int serializedSizeInBytes(); @Override int[] toArray(); @Override void append(char key, Container container); MutableRoaringBitmap toMutableRoaringBitmap(); @Override String toString(); @Override void trim(); @Override void writeExternal(ObjectOutput out); void xor(final RoaringBitmap x2); static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2) { final RoaringBitmap answer = new RoaringBitmap(); int pos1 = 0, pos2 = 0; final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); while (pos1 < length1 && pos2 < length2) { final char s1 = x1.highLowContainer.getKeyAtIndex(pos1); final char s2 = x2.highLowContainer.getKeyAtIndex(pos2); if (s1 == s2) { final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); final Container c = c1.andNot(c2); if (!c.isEmpty()) { answer.highLowContainer.append(s1, c); } ++pos1; ++pos2; } else if (s1 < s2) { final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, nextPos1); pos1 = nextPos1; } else { pos2 = x2.highLowContainer.advanceUntil(s1, pos2); } } if (pos2 == length2) { answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); } return answer; } RoaringBitmap();   RoaringBitmap(RoaringArray highLowContainer);  RoaringBitmap(ImmutableRoaringBitmap rb); static RoaringBitmap addOffset(final RoaringBitmap x, long offset); static RoaringBitmap add(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap add(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap and(final RoaringBitmap x1, final RoaringBitmap x2); static int andCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2); void add(final int... dat); void addN(final int[] dat, final int offset, final int n); static RoaringBitmap bitmapOf(final int... dat); static RoaringBitmap bitmapOfUnordered(final int... data); static RoaringBitmap flip(RoaringBitmap bm, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap flip(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap or(Iterator<? extends RoaringBitmap> bitmaps); static RoaringBitmap or(RoaringBitmap... bitmaps); static RoaringBitmap or(final RoaringBitmap x1, final RoaringBitmap x2); static int orCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int xorCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int andNotCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap remove(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap remove(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap xor(final RoaringBitmap x1, final RoaringBitmap x2); @Override void add(final int x); void add(final long rangeStart, final long rangeEnd); @Deprecated void add(final int rangeStart, final int rangeEnd); boolean intersects(long minimum, long supremum); void and(final RoaringBitmap x2); static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final int rangeStart, final int rangeEnd); void andNot(final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
      long rangeStart, long rangeEnd); @Deprecated static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
          final int rangeStart, final int rangeEnd); void orNot(final RoaringBitmap other, long rangeEnd); static RoaringBitmap orNot(
          final RoaringBitmap x1, final RoaringBitmap x2, long rangeEnd); boolean checkedAdd(final int x); boolean checkedRemove(final int x); void clear(); @Override RoaringBitmap clone(); @Override boolean contains(final int x); boolean contains(long minimum, long supremum); void deserialize(DataInput in, byte[] buffer); void deserialize(DataInput in); void deserialize(ByteBuffer bbf); @Override boolean equals(Object o); boolean isHammingSimilar(RoaringBitmap other, int tolerance); void flip(final int x); void flip(final long rangeStart, final long rangeEnd); @Deprecated void flip(final int rangeStart, final int rangeEnd); @Override long getLongCardinality(); @Override int getCardinality(); @Override void forEach(IntConsumer ic); ContainerPointer getContainerPointer(); @Override PeekableIntIterator getIntIterator(); @Override IntIterator getReverseIntIterator(); @Override RoaringBatchIterator getBatchIterator(); @Override long getLongSizeInBytes(); @Override int getSizeInBytes(); @Override int hashCode(); boolean hasRunCompression(); @Override boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override RoaringBitmap limit(int maxcardinality); void or(final RoaringBitmap x2); static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); @Override long rankLong(int x); @Override long rangeCardinality(long start, long end); @Override int rank(int x); @Override void readExternal(ObjectInput in); @Override void remove(final int x); void remove(final long rangeStart, final long rangeEnd); @Deprecated void remove(final int rangeStart, final int rangeEnd); boolean removeRunCompression(); boolean runOptimize(); boolean contains(RoaringBitmap subset); @Override int select(int j); @Override long nextValue(int fromValue); @Override long previousValue(int fromValue); @Override long nextAbsentValue(int fromValue); @Override long previousAbsentValue(int fromValue); @Override int first(); @Override int last(); @Override void serialize(DataOutput out); @Override void serialize(ByteBuffer buffer); static long maximumSerializedSize(long cardinality, long universe_size); @Override int serializedSizeInBytes(); @Override int[] toArray(); @Override void append(char key, Container container); MutableRoaringBitmap toMutableRoaringBitmap(); @Override String toString(); @Override void trim(); @Override void writeExternal(ObjectOutput out); void xor(final RoaringBitmap x2); static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd);  }