In-place bitwise OR (union) operation. The current bitmap is modified.

@param x2 other bitmap
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;
      }
    }
  }
370194
public void flip(int x, int y) {
    int offset = y * rowSize + (x / 32);
    bits[offset] ^= 1 << (x & 0x1f);
  }
922321
@Override
    public boolean union(int x, int y) {
        int rx = x;
        int ry = y;
        int px = p[rx];
        int py = p[ry];
        while (px != py) {
            if (px < py) {
                if (rx == px) {
                    p[rx] = py;
                    return true;
                }
                p[rx] = py;
                rx = px;
                px = p[rx];
            } else {
                if (ry == py) {
                    p[ry] = px;
                    return true;
                }
                p[ry] = px;
                ry = py;
                py = p[ry];
            }
        }
        return false;
    }
1284485
static void int2bin(
	 int value,             /* input : decimal value */
	 int no_of_bits,        /* input : number of bits to use */
	 short[] bitstream, int bitstreams       /* output: bitstream  */
	)
	{
	   int pt_bitstream;
	   short   i, bit;

	   pt_bitstream = bitstreams + no_of_bits;

	   for (i = 0; i < no_of_bits; i++)
	   {
	     bit = (short)(value & 0x0001);      /* get lsb */
	     if (bit == 0)
	         bitstream[--pt_bitstream] = LD8KConstants.BIT_0;
	     else
	         bitstream[--pt_bitstream] = LD8KConstants.BIT_1;
	     value >>= 1;
	   }
	}
1077786
public SparseBitmap and(SparseBitmap o) {
		SparseBitmap a = new SparseBitmap();
		and2by2(a, this, o);
		return a;
	}
1187607
public static void setBitmapRange(long[] bitmap, int start, int end) {
    if (start == end) {
      return;
    }
    int firstword = start / 64;
    int endword = (end - 1) / 64;
    if (firstword == endword) {
      bitmap[firstword] |= (~0L << start) & (~0L >>> -end);
      return;
    }
    bitmap[firstword] |= ~0L << start;
    for (int i = firstword + 1; i < endword; i++) {
      bitmap[i] = ~0L;
    }
    bitmap[endword] |= ~0L >>> -end;
  }
959147
public static void or2by2(BitmapContainer container, SparseBitmap bitmap1,
			SparseBitmap bitmap2) {
		int it1 = 0;
		int it2 = 0;
		int p1 = bitmap1.buffer.get(it1);
		int p2 = bitmap2.buffer.get(it2);
		if ((it1 < bitmap1.buffer.size()) && (it2 < bitmap2.buffer.size()))
			while (true) {
				if (p1 < p2) {
					container.add(bitmap1.buffer.get(it1 + 1), p1);
					it1 += 2;
					if (it1 >= bitmap1.buffer.size())
						break;
					p1 += bitmap1.buffer.get(it1) + 1;
				} else if (p1 > p2) {
					container.add(bitmap2.buffer.get(it2 + 1), p2);
					it2 += 2;
					if (it2 >= bitmap2.buffer.size())
						break;
					p2 += bitmap2.buffer.get(it2) + 1;
				} else {
					container.add(
							bitmap1.buffer.get(it1 + 1)
									| bitmap2.buffer.get(it2 + 1), p1);
					it1 += 2;
					it2 += 2;
					if (it1 < bitmap1.buffer.size())
						p1 += bitmap1.buffer.get(it1) + 1;
					if (it2 < bitmap2.buffer.size())
						p2 += bitmap2.buffer.get(it2) + 1;
					if ((it1 >= bitmap1.buffer.size())
							|| (it2 >= bitmap2.buffer.size()))
						break;
				}
			}

		if (it1 < bitmap1.buffer.size()) {
			while (true) {
				container.add(bitmap1.buffer.get(it1 + 1), p1);
				it1 += 2;
				if (it1 == bitmap1.buffer.size())
					break;
				p1 += bitmap1.buffer.get(it1) + 1;
			}
		}
		if (it2 < bitmap2.buffer.size()) {
			while (true) {
				container.add(bitmap2.buffer.get(it2 + 1), p2);
				it2 += 2;
				if (it2 == bitmap2.buffer.size())
					break;
				p2 += bitmap2.buffer.get(it2) + 1;
			}
		}
	}
504968
protected static RoaringBitmap lazyorfromlazyinputs(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();
    main: if (pos1 < length1 && pos2 < length2) {
      short s1 = x1.highLowContainer.getKeyAtIndex(pos1);
      short s2 = x2.highLowContainer.getKeyAtIndex(pos2);

      while (true) {
        if (s1 == s2) {
          Container c1 = x1.highLowContainer.getContainerAtIndex(pos1);
          Container c2 = x2.highLowContainer.getContainerAtIndex(pos2);
          if ((c2 instanceof BitmapContainer) && (!(c1 instanceof BitmapContainer))) {
            Container tmp = c1;
            c1 = c2;
            c2 = tmp;
          }
          answer.highLowContainer.append(s1, c1.lazyIOR(c2));
          pos1++;
          pos2++;
          if ((pos1 == length1) || (pos2 == length2)) {
            break main;
          }
          s1 = x1.highLowContainer.getKeyAtIndex(pos1);
          s2 = x2.highLowContainer.getKeyAtIndex(pos2);
        } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
          Container c1 = x1.highLowContainer.getContainerAtIndex(pos1);
          answer.highLowContainer.append(s1, c1);
          pos1++;
          if (pos1 == length1) {
            break main;
          }
          s1 = x1.highLowContainer.getKeyAtIndex(pos1);
        } else { // s1 > s2
          Container c2 = x2.highLowContainer.getContainerAtIndex(pos2);
          answer.highLowContainer.append(s2,c2);
          pos2++;
          if (pos2 == length2) {
            break main;
          }
          s2 = x2.highLowContainer.getKeyAtIndex(pos2);
        }
      }
    }
    if (pos1 == length1) {
      answer.highLowContainer.append(x2.highLowContainer, pos2, length2);
    } else if (pos2 == length2) {
      answer.highLowContainer.append(x1.highLowContainer, pos1, length1);
    }
    return answer;
  }
1282430
public static SkippableIterator flatand(SkippableIterator... bitmap) {
		if (bitmap.length == 0)
			throw new RuntimeException("nothing to process");
		SkippableIterator answer = bitmap[0];
		for (int k = 1; k < bitmap.length; ++k) {
			answer = and2by2(answer, bitmap[k]);
		}
		return answer;
	}
1041733
public static MutableRoaringBitmap xor(ImmutableRoaringBitmap... bitmaps) {
    return groupByKey(bitmaps)
            .entrySet()
            .parallelStream()
            .collect(XOR);
  }
182174
private static int merging2_2(int[] buffer, int x) {
		int cnt1 = buffer[x + 1];
		int cnt2 = buffer[x + 3];
		final int w = buffer[x + 5];
		cnt1 = cnt1 - ((cnt1 >>> 1) & 0x55555555) + (w & 0x55555555);
		cnt2 = cnt2 - ((cnt2 >>> 1) & 0x55555555) + ((w >>> 1) & 0x55555555);
		cnt1 = (cnt1 & 0x33333333) + ((cnt1 >>> 2) & 0x33333333);
		cnt2 = (cnt2 & 0x33333333) + ((cnt2 >>> 2) & 0x33333333);
		cnt1 += cnt2;
		cnt1 = (cnt1 & 0x0F0F0F0F) + ((cnt1 >>> 4) & 0x0F0F0F0F);
		cnt1 += cnt1 >>> 8;
		cnt1 += cnt1 >>> 16;
		return cnt1 & 0x000000FF;
	}
774865
@Pure
	@Inline(value="($1 & $2)", constantExpression=true)
	public static int bitwiseAnd(int a, int b) {
		return a & b;
	}
1170773
public static <X extends Comparable<? super X>> int compare(X x1, X x2) {
		if (x1 == null) return x2 == null ? 0 : -1;
		return x2 == null ? 1 : x1.compareTo(x2);
	}
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;
  }
1275657
public void and(final RoaringBitmap x2) {
    int pos1 = 0, pos2 = 0, intersectionSize = 0;
    final int length1 = highLowContainer.size(), length2 = x2.highLowContainer.size();

    while (pos1 < length1 && pos2 < length2) {
      final short s1 = highLowContainer.getKeyAtIndex(pos1);
      final short s2 = x2.highLowContainer.getKeyAtIndex(pos2);
      if (s1 == s2) {
        final Container c1 = highLowContainer.getContainerAtIndex(pos1);
        final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2);
        final Container c = c1.iand(c2);
        if (!c.isEmpty()) {
          highLowContainer.replaceKeyAndContainerAtIndex(intersectionSize++, s1, c);
        }
        ++pos1;
        ++pos2;
      } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
        pos1 = highLowContainer.advanceUntil(s2, pos1);
      } else { // s1 > s2
        pos2 = x2.highLowContainer.advanceUntil(s1, pos2);
      }
    }
    highLowContainer.resize(intersectionSize);
  }
635955
public static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2) {
    final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size();
    int pos1 = 0, pos2 = 0;

    while (pos1 < length1 && pos2 < length2) {
      final short s1 = x1.highLowContainer.getKeyAtIndex(pos1);
      final short s2 = x2.highLowContainer.getKeyAtIndex(pos2);
      if (s1 == s2) {
        final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1);
        final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2);
        if (c1.intersects(c2)) {
          return true;
        }
        ++pos1;
        ++pos2;
      } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
        pos1 = x1.highLowContainer.advanceUntil(s2, pos1);
      } else { // s1 > s2
        pos2 = x2.highLowContainer.advanceUntil(s1, pos2);
      }
    }
    return false;
  }
741949
def bitsetxor(b1, b2):
	
	res = []
	for bit1, bit2 in zip(b1, b2):
		res.append( bit1 ^ bit2)
	return res