Compute overall OR between bitmaps two-by-two.

This function runs in linear time with respect to the number of bitmaps.

@param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap)
@return aggregated bitmap
321868
public static MutableRoaringBitmap naive_or(@SuppressWarnings("rawtypes") Iterator bitmaps) {
    MutableRoaringBitmap answer = new MutableRoaringBitmap();
    while (bitmaps.hasNext()) {
      answer.naivelazyor((ImmutableRoaringBitmap) bitmaps.next());
    }
    answer.repairAfterLazy();
    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;
  }
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;
  }
124088
public static void main(String[] args)
  {
    BitmapIterationBenchmark state = new BitmapIterationBenchmark();
    state.bitmapAlgo = "concise";
    state.prob = 0.001;
    state.size = 1000000;
    state.setup();

    BitmapsForIntersection state2 = new BitmapsForIntersection();
    state2.setup(state);
    state.intersectionAndIter(state2);
  }
497699
public Bitmap asBitmap(INDArray array, int dataType) {
        return converter2.convert(asFrame(array, dataType));
    }
1044794
public static RoaringBitmap bitmapOf(final int... dat) {
    final RoaringBitmap ans = new RoaringBitmap();
    ans.add(dat);
    return ans;
  }
21177
public static IntMultimap invertFrom(Multimap<? extends Integer, ? extends Integer> map) {
    if (map instanceof IntMultimap) {
      IntMultimap other = (IntMultimap) map;
      // This is unnecessary, but it makes this method easier to implement.
      other.reindexItems();

      int[] newSortedKeys = Arrays.copyOf(other.sortedValues, other.sortedValues.length);
      int[] newSortedValues = Arrays.copyOf(other.sortedKeys, other.sortedKeys.length);
     
      ArrayUtils.sortKeyValuePairs(newSortedKeys, newSortedValues, 0, newSortedKeys.length);

      return new IntMultimap(newSortedKeys, newSortedValues);
    } else {
      IntMultimap inverse = IntMultimap.create();
      Multimaps.invertFrom(map, inverse);
      return inverse;
    }
  }
1077788
public static RoaringBitmap naive_xor(Iterator<? extends RoaringBitmap> bitmaps) {
    RoaringBitmap answer = new RoaringBitmap();
    while (bitmaps.hasNext()) {
      answer.xor(bitmaps.next());
    }
    return answer;
  }
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);
  }
253431
public static RoaringBitmap xor(RoaringBitmap... bitmaps) {
    return groupByKey(bitmaps)
            .entrySet()
            .parallelStream()
            .collect(XOR);
  }
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;
  }
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;
  }
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;
			}
		}
	}
176711
function calc_null_bitmap(values) {
    var val = 0, len = 0, bitmap = [];
    values.map(function(v) {
        val += (v == null || v == undefined ? 1 << len : 0);
        len += 1;

        if(len == 8) {
          bitmap.push(val);
          len = val = 0;
        }
        return val;
    });

    if(len > 0) {
      bitmap.push(val);
    }

    var packed = []
    bitmap.forEach(function(entry, i, bitmap) {
      packed[i] = pack.pack("C*", entry)
    })

    return packed
}
993374
public static ByteArrayInputStream toPNGInputStream(Bitmap bitmap) {
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
		return new ByteArrayInputStream(bytes.toByteArray());
	}
658782
Bitmap getBitmap(int position) {
    return bitmaps[position] != null ? bitmaps[position].get() : null;
  }
1041733
public static MutableRoaringBitmap xor(ImmutableRoaringBitmap... bitmaps) {
    return groupByKey(bitmaps)
            .entrySet()
            .parallelStream()
            .collect(XOR);
  }