Java Set Cardinality cardinalityInBitmapWordRange(long[] bitmap, int start, int end)

Here you can find the source of cardinalityInBitmapWordRange(long[] bitmap, int start, int end)

Description

Hamming weight of the 64-bit words involved in the range start, start+1,..., end-1

License

Apache License

Parameter

Parameter Description
bitmap array of words to be modified
start first index to be modified (inclusive)
end last index to be modified (exclusive)

Return

the hamming weight

Declaration

public static int cardinalityInBitmapWordRange(long[] bitmap, int start, int end) 

Method Source Code

//package com.java2s;
/*/*w  w w .  ja va  2s  . com*/
 * (c) the authors Licensed under the Apache License, Version 2.0.
 */

public class Main {
    /**
     * Hamming weight of the 64-bit words involved in the range
     *  start, start+1,..., end-1
     * 
     * @param bitmap array of words to be modified
     * @param start first index to be modified (inclusive)
     * @param end last index to be modified (exclusive)
     * @return the hamming weight
     */
    public static int cardinalityInBitmapWordRange(long[] bitmap, int start, int end) {
        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]);
        }
        return answer;
    }
}

Related

  1. cardinality(byte b)
  2. cardinality(final int from, final int to, final long[] words)
  3. cardinality(long v)
  4. cardinalityInBitmapRange(long[] bitmap, int start, int end)