List of utility methods to do Set Cardinality
int | cardinality(byte b) cardinality int count = 0; for (int i = 0; i < 8; ++i) { if (((b >>> i) & 1) == 1) { ++count; return count; |
int | cardinality(final int from, final int to, final long[] words) cardinality int sum = 0; for (int i = from; i < to; i++) { sum += Long.bitCount(words[i]); return sum; |
int | cardinality(long v) Compute the cardinality (number of set bits) return Long.bitCount(v);
|
int | cardinalityInBitmapRange(long[] bitmap, int start, int end) Hamming weight of the bitset in the range start, start+1,..., end-1 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; |
int | cardinalityInBitmapWordRange(long[] bitmap, int start, int end) Hamming weight of the 64-bit words involved in the range start, start+1,..., end-1 if (start == end) { return 0; int firstword = start / 64; int endword = (end - 1) / 64; int answer = 0; for (int i = firstword; i <= endword; i++) { answer += Long.bitCount(bitmap[i]); ... |