Compute the bitwise ANDNOT between two long arrays and write the set bits in the container.

@param container where we write
@param bitmap1 first bitmap
@param bitmap2 second bitmap
482981
public static void fillArrayANDNOT(final short[] container, final long[] bitmap1,
      final long[] bitmap2) {
    int pos = 0;
    if (bitmap1.length != bitmap2.length) {
      throw new IllegalArgumentException("not supported");
    }
    for (int k = 0; k < bitmap1.length; ++k) {
      long bitset = bitmap1[k] & (~bitmap2[k]);
      while (bitset != 0) {
        container[pos++] = (short) (k * 64 + numberOfTrailingZeros(bitset));
        bitset &= (bitset - 1);
      }
    }
  }
411709
static Iterable<ImmutableBitmap> bitmapsFromIndexes(final IntIterable indexes, final BitmapIndex bitmapIndex)
  {
    // Do not use Iterables.transform() to avoid boxing/unboxing integers.
    return new Iterable<ImmutableBitmap>()
    {
      @Override
      public Iterator<ImmutableBitmap> iterator()
      {
        final IntIterator iterator = indexes.iterator();

        return new Iterator<ImmutableBitmap>()
        {
          @Override
          public boolean hasNext()
          {
            return iterator.hasNext();
          }

          @Override
          public ImmutableBitmap next()
          {
            return bitmapIndex.getBitmap(iterator.nextInt());
          }

          @Override
          public void remove()
          {
            throw new UnsupportedOperationException();
          }
        };
      }
    };
  }
1086746
public void and(final ImmutableRoaringBitmap array) {
    int pos1 = 0, pos2 = 0, intersectionSize = 0;
    final int length1 = highLowContainer.size(), length2 = array.highLowContainer.size();

    while (pos1 < length1 && pos2 < length2) {
      final short s1 = highLowContainer.getKeyAtIndex(pos1);
      final short s2 = array.highLowContainer.getKeyAtIndex(pos2);
      if (s1 == s2) {
        final MappeableContainer c1 = highLowContainer.getContainerAtIndex(pos1);
        final MappeableContainer c2 = array.highLowContainer.getContainerAtIndex(pos2);
        final MappeableContainer c = c1.iand(c2);
        if (!c.isEmpty()) {
          getMappeableRoaringArray().replaceKeyAndContainerAtIndex(intersectionSize++, s1, c);
        }
        ++pos1;
        ++pos2;
      } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
        pos1 = highLowContainer.advanceUntil(s2, pos1);
      } else { // s1 > s2
        pos2 = array.highLowContainer.advanceUntil(s1, pos2);
      }
    }
    getMappeableRoaringArray().resize(intersectionSize);
  }
321355
public void or(final Roaring64NavigableMap x2) {
    boolean firstBucket = true;

    for (Entry<Integer, BitmapDataProvider> e2 : x2.highToBitmap.entrySet()) {
      // Keep object to prevent auto-boxing
      Integer high = e2.getKey();

      BitmapDataProvider lowBitmap1 = this.highToBitmap.get(high);

      BitmapDataProvider lowBitmap2 = e2.getValue();

      // TODO Reviewers: is it a good idea to rely on BitmapDataProvider except in methods
      // expecting an actual MutableRoaringBitmap?
      // TODO This code may lead to closing a buffer Bitmap in current Navigable even if current is
      // not on buffer
      if ((lowBitmap1 == null || lowBitmap1 instanceof RoaringBitmap)
          && lowBitmap2 instanceof RoaringBitmap) {
        if (lowBitmap1 == null) {
          // Clone to prevent future modification of this modifying the input Bitmap
          RoaringBitmap lowBitmap2Clone = ((RoaringBitmap) lowBitmap2).clone();

          pushBitmapForHigh(high, lowBitmap2Clone);
        } else {
          ((RoaringBitmap) lowBitmap1).or((RoaringBitmap) lowBitmap2);
        }
      } else if ((lowBitmap1 == null || lowBitmap1 instanceof MutableRoaringBitmap)
          && lowBitmap2 instanceof MutableRoaringBitmap) {
        if (lowBitmap1 == null) {
          // Clone to prevent future modification of this modifying the input Bitmap
          BitmapDataProvider lowBitmap2Clone = ((MutableRoaringBitmap) lowBitmap2).clone();


          pushBitmapForHigh(high, lowBitmap2Clone);
        } else {
          ((MutableRoaringBitmap) lowBitmap1).or((MutableRoaringBitmap) lowBitmap2);
        }
      } else {
        throw new UnsupportedOperationException(
            ".or is not between " + this.getClass() + " and " + lowBitmap2.getClass());
      }

      if (firstBucket) {
        firstBucket = false;

        // Invalidate the lowest high as lowest not valid
        firstHighNotValid = Math.min(firstHighNotValid, high);
        allValid = false;
      }
    }
  }
1081451
public static RoaringBitmap naive_and(RoaringBitmap... bitmaps) {
    if (bitmaps.length == 0) {
      return new RoaringBitmap();
    }
    RoaringBitmap answer = bitmaps[0].clone();
    for (int k = 1; k < bitmaps.length; ++k) {
      answer.and(bitmaps[k]);
    }
    return answer;
  }
802964
public static int cardinalityInBitmapRange(LongBuffer bitmap, int start, int end) {
    if (isBackedBySimpleArray(bitmap)) {
      return Util.cardinalityInBitmapRange(bitmap.array(), start, end);
    }
    if (start >= end) {
      return 0;
    }
    int firstword = start / 64;
    int endword = (end - 1) / 64;
    if (firstword == endword) {
      return Long.bitCount(bitmap.get(firstword) & ((~0L << start) & (~0L >>> -end)));
    }
    int answer = Long.bitCount(bitmap.get(firstword) & (~0L << start));
    for (int i = firstword + 1; i < endword; i++) {
      answer += Long.bitCount(bitmap.get(i));
    }
    answer += Long.bitCount(bitmap.get(endword) & (~0L >>> -end));
    return answer;
  }
683881
public static RoaringBitmap naive_xor(RoaringBitmap... bitmaps) {
    RoaringBitmap answer = new RoaringBitmap();
    for (int k = 0; k < bitmaps.length; ++k) {
      answer.xor(bitmaps[k]);
    }
    return answer;
  }
1212752
private boolean ensure2dLayout(IAtomContainer container) throws CDKException {
        if (!GeometryUtil.has2DCoordinates(container)) {
            StructureDiagramGenerator sdg = new StructureDiagramGenerator();
            sdg.generateCoordinates(container);
            return true;
        }
        return false;
    }
684535
public static MutableRoaringBitmap naive_or(MutableRoaringBitmap... bitmaps) {
    MutableRoaringBitmap answer = new MutableRoaringBitmap();
    for (int k = 0; k < bitmaps.length; ++k) {
      answer.lazyor(bitmaps[k]);
    }
    answer.repairAfterLazy();
    return answer;
  }
893308
public static SkippableIterator treeand(SkippableIterator... bitmap) {
		if (bitmap.length == 0)
			throw new RuntimeException("nothing to process");
		if (bitmap.length == 1)
			return bitmap[0];
		if (bitmap.length == 2)
			return and2by2(bitmap[0], bitmap[1]);
		if ((bitmap.length & 1) == 0) {// even
			SkippableIterator[] si = new SkippableIterator[bitmap.length / 2];
			for (int i = 0; i < si.length; ++i)
				si[i] = and2by2(bitmap[2 * i], bitmap[2 * i + 1]);
			return treeand(si);
		}
		// odd
		SkippableIterator[] si = new SkippableIterator[bitmap.length / 2 + 1];
		for (int i = 0; i < si.length - 1; ++i)
			si[i] = and2by2(bitmap[2 * i], bitmap[2 * i + 1]);
		si[si.length - 1] = bitmap[bitmap.length - 1];
		return treeand(si);
	}
1079229
public boolean contains(Container subset) {
    if(subset instanceof RunContainer) {
      return contains((RunContainer)subset);
    } else if(subset instanceof ArrayContainer) {
      return contains((ArrayContainer) subset);
    } else if(subset instanceof BitmapContainer){
      return contains((BitmapContainer)subset);
    }
    return false;
  }
790940
public boolean intersects(Container x) {
    if (x instanceof ArrayContainer) {
      return intersects((ArrayContainer) x);
    } else if (x instanceof BitmapContainer) {
      return intersects((BitmapContainer) x);
    }
    return intersects((RunContainer) x);
  }
364395
public static SkippableIterator and2by2(final SkippableIterator bitmap1,
			final SkippableIterator bitmap2) {
		return new SkippableIterator() {

			boolean hasvalue = false;
			int currentword = 0;

			@Override
			public boolean hasValue() {
				return this.hasvalue;
			}

			public SkippableIterator init() {
				movetonext();
				return this;
			}

			public void movetonext() {
				this.hasvalue = false;
				if (bitmap1.hasValue() && bitmap2.hasValue()) {
					while (true) {
						if (bitmap1.getCurrentWordOffset() < bitmap2
								.getCurrentWordOffset()) {
							bitmap1.advanceUntil(bitmap2.getCurrentWordOffset());
							if (!bitmap1.hasValue()) {
								return;
							}
						} else if (bitmap1.getCurrentWordOffset() > bitmap2
								.getCurrentWordOffset()) {
							bitmap2.advanceUntil(bitmap1.getCurrentWordOffset());
							if (!bitmap2.hasValue()) {
								return;
							}
						} else {
							this.currentword = bitmap1.getCurrentWord()
									& bitmap2.getCurrentWord();
							if (this.currentword != 0) {
								this.hasvalue = true;
								return;
							}
							bitmap1.advance();
							if (bitmap1.hasValue()) {
								bitmap2.advanceUntil(bitmap1
										.getCurrentWordOffset());
								if (bitmap2.hasValue()) {
									continue;
								}
							}
							return;
						}
					}
				}
			}

			@Override
			public void advance() {
				bitmap1.advance();
				if (bitmap1.hasValue()) {
					bitmap2.advanceUntil(bitmap1.getCurrentWordOffset());
					movetonext();
				} else
					this.hasvalue = false;
			}

			@Override
			public void advanceUntil(int min) {
				bitmap1.advanceUntil(min);
				if (bitmap1.hasValue()) {
					bitmap2.advanceUntil(bitmap1.getCurrentWordOffset());
					movetonext();
				} else
					this.hasvalue = false;
			}

			@Override
			public int getCurrentWord() {
				return this.currentword;
			}

			@Override
			public int getCurrentWordOffset() {
				return bitmap1.getCurrentWordOffset();// could be bitmap2, they
														// must be equal
			}

		}.init();
	}
349963
public int andCardinality(Container x) {
    if (this.isEmpty()) {
      return 0;
    } else if (x.isEmpty()) {
      return 0;
    } else {
      if (x instanceof ArrayContainer) {
        return andCardinality((ArrayContainer) x);
      } else if (x instanceof BitmapContainer) {
        return andCardinality((BitmapContainer) x);
      }
      return andCardinality((RunContainer) x);
    }
  }
424318
void andNot(LongBitSet other) {
		int pos = Math.min(numWords, other.numWords);
		while (--pos >= 0) {
			bits[pos] &= ~other.bits[pos];
		}
	}
774865
@Pure
	@Inline(value="($1 & $2)", constantExpression=true)
	public static int bitwiseAnd(int a, int b) {
		return a & b;
	}
994632
public static RoaringBitmap bitmapOf(final long[] words) {
    // split long[] into blocks.
    // each block becomes a single container, if any bit is set
    final RoaringBitmap ans = new RoaringBitmap();
    int containerIndex = 0;
    for (int from = 0; from < words.length; from += BLOCK_LENGTH) {
      final int to = Math.min(from + BLOCK_LENGTH, words.length);
      final int blockCardinality = cardinality(from, to, words);
      if (blockCardinality > 0) {
        ans.highLowContainer.insertNewKeyValueAt(containerIndex++, Util.highbits(from * Long.SIZE),
            BitSetUtil.containerOf(from, to, blockCardinality, words));
      }
    }
    return ans;
  }