Uses a priority queue to compute the or aggregate.

This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps.

@param bitmaps input bitmaps
@return aggregated bitmap
@see #horizontal_or(ImmutableRoaringBitmap...)
324958
public static MutableRoaringBitmap priorityqueue_or(ImmutableRoaringBitmap... bitmaps) {
    if (bitmaps.length == 0) {
      return new MutableRoaringBitmap();
    } else if (bitmaps.length == 1) {
      return bitmaps[0].toMutableRoaringBitmap();
    }
    // we buffer the call to getLongSizeInBytes(), hence the code complexity
    final ImmutableRoaringBitmap[] buffer = Arrays.copyOf(bitmaps, bitmaps.length);
    final int[] sizes = new int[buffer.length];
    final boolean[] istmp = new boolean[buffer.length];
    for (int k = 0; k < sizes.length; ++k) {
      sizes[k] = buffer[k].serializedSizeInBytes();
    }
    PriorityQueue<Integer> pq = new PriorityQueue<>(128, new Comparator<Integer>() {
      @Override
      public int compare(Integer a, Integer b) {
        return sizes[a] - sizes[b];
      }
    });
    for (int k = 0; k < sizes.length; ++k) {
      pq.add(k);
    }
    while (pq.size() > 1) {
      Integer x1 = pq.poll();
      Integer x2 = pq.poll();
      if (istmp[x1] && istmp[x2]) {
        buffer[x1] = MutableRoaringBitmap.lazyorfromlazyinputs((MutableRoaringBitmap) buffer[x1],
            (MutableRoaringBitmap) buffer[x2]);
        sizes[x1] = buffer[x1].serializedSizeInBytes();
        pq.add(x1);
      } else if (istmp[x2]) {
        ((MutableRoaringBitmap) buffer[x2]).lazyor(buffer[x1]);
        sizes[x2] = buffer[x2].serializedSizeInBytes();
        pq.add(x2);
      } else if (istmp[x1]) {
        ((MutableRoaringBitmap) buffer[x1]).lazyor(buffer[x2]);
        sizes[x1] = buffer[x1].serializedSizeInBytes();
        pq.add(x1);
      } else {
        buffer[x1] = ImmutableRoaringBitmap.lazyor(buffer[x1], buffer[x2]);
        sizes[x1] = buffer[x1].serializedSizeInBytes();
        istmp[x1] = true;
        pq.add(x1);
      }
    }
    MutableRoaringBitmap answer = (MutableRoaringBitmap) buffer[pq.poll()];
    answer.repairAfterLazy();
    return answer;
  }
253431
public static RoaringBitmap xor(RoaringBitmap... bitmaps) {
    return groupByKey(bitmaps)
            .entrySet()
            .parallelStream()
            .collect(XOR);
  }
612367
func HeapOr(bitmaps ...*Bitmap) *Bitmap {
	if len(bitmaps) == 0 {
		return NewBitmap()
	}
	// TODO:  for better speed, we could do the operation lazily, see Java implementation
	pq := make(priorityQueue, len(bitmaps))
	for i, bm := range bitmaps {
		pq[i] = &item{bm, i}
	}
	heap.Init(&pq)

	for pq.Len() > 1 {
		x1 := heap.Pop(&pq).(*item)
		x2 := heap.Pop(&pq).(*item)
		heap.Push(&pq, &item{Or(x1.value, x2.value), 0})
	}
	return heap.Pop(&pq).(*item).value
}
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;
			}
		}
	}
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;
  }
1003879
public CallbackResult<V> processCallbacks(Object... params)
	{
		if (callbacks.size() == 0)
			return CallbackResult.noResult();

		CallbackResult<V> result = CallbackResult.noResult();
		Priority lastPriority = Priority.HIGHEST;
		for (Pair<C, CallbackOption<P>> pair : callbacks)
		{
			if (result.isCancelled() && pair.getRight().getPriority() != lastPriority)
				return result;

			if (pair.getRight().apply(params))
			{
				CallbackResult<V> tmp = pair.getLeft().call(params);
				result = reduce.apply(result, tmp);
				if (result.isForcedCancelled())
					return result;

				lastPriority = pair.getRight().getPriority();
			}
		}

		return result;
	}
625283
public static RoaringBitmap bitmapOfUnordered(final int... data) {
    RoaringBitmapWriter<RoaringBitmap> writer = writer().constantMemory()
            .doPartialRadixSort().get();
    writer.addMany(data);
    writer.flush();
    return writer.getUnderlying();
  }
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();
	}
578734
public Bitmap getDrawingBitmap() {
        /*
         * Layer manager only starts drawing a new bitmap when the last one is swapped (taken to
         * the screen). This ensures that the layer manager draws not too many frames. (only as
         * much as can get displayed).
         */
        synchronized (this.allowSwap) {
            this.allowSwap.waitDisabled();
            Bitmap b = this.lmBitmap.lock();
            if (b != null) {
                b.setBackgroundColor(this.displayModel.getBackgroundColor());
            }
            return b;
        }
    }
880873
public static double estimateSelectivity(
      final Iterator<ImmutableBitmap> bitmaps,
      final long totalNumRows
  )
  {
    long numMatchedRows = 0;
    while (bitmaps.hasNext()) {
      final ImmutableBitmap bitmap = bitmaps.next();
      numMatchedRows += bitmap.size();
    }

    return Math.min(1., (double) numMatchedRows / totalNumRows);
  }
2797
public static SortedMap<Short, List<Container>> groupByKey(RoaringBitmap... bitmaps) {
    Map<Short, List<Container>> grouped = new HashMap<>();
    for (RoaringBitmap bitmap : bitmaps) {
      RoaringArray ra = bitmap.highLowContainer;
      for (int i = 0; i < ra.size; ++i) {
        Container container = ra.values[i];
        Short key = ra.keys[i];
        List<Container> slice = grouped.get(key);
        if (null == slice) {
          slice = new ArrayList<>();
          grouped.put(key, slice);
        }
        slice.add(container);
      }
    }
    SortedMap<Short, List<Container>> sorted = new TreeMap<>(Util::compareUnsigned);
    sorted.putAll(grouped);
    return sorted;
  }
1226171
public static RoaringBitmap priorityqueue_xor(RoaringBitmap... bitmaps) {
    // TODO: This code could be faster, see priorityqueue_or
    if (bitmaps.length == 0) {
      return new RoaringBitmap();
    }

    PriorityQueue<RoaringBitmap> pq =
        new PriorityQueue<>(bitmaps.length, new Comparator<RoaringBitmap>() {
          @Override
          public int compare(RoaringBitmap a, RoaringBitmap b) {
            return (int)(a.getLongSizeInBytes() - b.getLongSizeInBytes());
          }
        });
    Collections.addAll(pq, bitmaps);
    while (pq.size() > 1) {
      RoaringBitmap x1 = pq.poll();
      RoaringBitmap x2 = pq.poll();
      pq.add(RoaringBitmap.xor(x1, x2));
    }
    return pq.poll();
  }
1179381
public static SparseBitmap bitmapOf(int... k) {
		SparseBitmap s = new SparseBitmap();
		for (int i : k) {
			s.set(i);
		}
		return s;
	}
330564
public static int cardinalityInBitmapRange(long[] bitmap, int start, int end) {
    if (start >= end) {
      return 0;
    }
    int firstword = start / 64;
    int endword = (end - 1) / 64;
    if (firstword == endword) {
      return Long.bitCount(bitmap[firstword] & ( (~0L << start) & (~0L >>> -end) ));
    }
    int answer = Long.bitCount(bitmap[firstword] & (~0L << start));
    for (int i = firstword + 1; i < endword; i++) {
      answer += Long.bitCount(bitmap[i]);
    }
    answer += Long.bitCount(bitmap[endword] & (~0L >>> -end));
    return answer;
  }
909433
@Deprecated
  public static int setBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end) {
    if (BufferUtil.isBackedBySimpleArray(bitmap)) {
      return Util.setBitmapRangeAndCardinalityChange(bitmap.array(), start, end);
    }
    int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end);
    setBitmapRange(bitmap, start, end);
    int cardafter = cardinalityInBitmapWordRange(bitmap, start, end);
    return cardafter - cardbefore;
  }
512869
public static int[] mapToList(int[] bitMap) {
        int[] list = new int[(int)(bitMap.length * WORD_LENGTH)];
        Arrays.fill(list, 0);
        int j = -1;
        for (int i = 0; i < list.length; i++) {
            if (i % WORD_LENGTH == 0) {
                j++;
            }
            list[i] = (bitMap[j] & (1 << ((WORD_LENGTH - 1) - (i % WORD_LENGTH)))) == 0 ? 0 : 1;
        }
        return list;
    }
477263
@Deprecated
  public static int setBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end) {
    int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end);
    setBitmapRange(bitmap, start,end);
    int cardafter = cardinalityInBitmapWordRange(bitmap, start, end);
    return cardafter - cardbefore;
  }