Example usage for java.lang Long bitCount

List of usage examples for java.lang Long bitCount

Introduction

In this page you can find the example usage for java.lang Long bitCount.

Prototype

@HotSpotIntrinsicCandidate
public static int bitCount(long i) 

Source Link

Document

Returns the number of one-bits in the two's complement binary representation of the specified long value.

Usage

From source file:org.apache.hadoop.hive.ql.io.orc.FileDump.java

private static String getBloomFilterStats(BloomFilterIO bf) {
    StringBuilder sb = new StringBuilder();
    int bitCount = bf.getBitSize();
    int popCount = 0;
    for (long l : bf.getBitSet()) {
        popCount += Long.bitCount(l);
    }/*from w  w w .  j  a  v a2 s.co  m*/
    int k = bf.getNumHashFunctions();
    float loadFactor = (float) popCount / (float) bitCount;
    float expectedFpp = (float) Math.pow(loadFactor, k);
    DecimalFormat df = new DecimalFormat("###.####");
    sb.append(" numHashFunctions: ").append(k);
    sb.append(" bitCount: ").append(bitCount);
    sb.append(" popCount: ").append(popCount);
    sb.append(" loadFactor: ").append(df.format(loadFactor));
    sb.append(" expectedFpp: ").append(expectedFpp);
    return sb.toString();
}

From source file:org.apache.kylin.engine.mr.common.CubeStatsReader.java

private void printCuboidInfoTreeEntry(Map<Long, Long> cuboidRows, Map<Long, Double> cuboidSizes,
        PrintWriter out) {/*from  w  ww .jav a  2  s  .  co m*/
    long baseCuboid = Cuboid.getBaseCuboidId(seg.getCubeDesc());
    int dimensionCount = Long.bitCount(baseCuboid);
    printCuboidInfoTree(-1L, baseCuboid, cuboidScheduler, cuboidRows, cuboidSizes, dimensionCount, 0, out);
}

From source file:org.apache.kylin.engine.mr.steps.CubeSamplingTest.java

private void addCuboidBitSet(long cuboidId, List<Integer[]> allCuboidsBitSet) {
    Integer[] indice = new Integer[Long.bitCount(cuboidId)];

    long mask = Long.highestOneBit(baseCuboidId);
    int position = 0;
    for (int i = 0; i < ROW_LENGTH; i++) {
        if ((mask & cuboidId) > 0) {
            indice[position] = i;//  w  ww  .  j a  va  2s .  co  m
            position++;
        }
        mask = mask >> 1;
    }

    allCuboidsBitSet.add(indice);

}

From source file:org.apache.kylin.engine.mr.steps.KVGTRecordWriter.java

private void initVariables(Long cuboidId) {
    rowKeyEncoder = AbstractRowKeyEncoder.createInstance(cubeSegment, Cuboid.findById(cubeDesc, cuboidId));
    keyBuf = rowKeyEncoder.createBuf();/*w  ww  .j a v  a2s .c  o  m*/

    dimensions = Long.bitCount(cuboidId);
    measureColumns = new ImmutableBitSet(dimensions, dimensions + measureCount);
}

From source file:org.apache.kylin.engine.spark.SparkCubing.java

private Map<Long, HLLCounter> sampling(final JavaRDD<List<String>> rowJavaRDD, final String cubeName,
        String segmentId) throws Exception {
    CubeInstance cubeInstance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv())
            .reloadCubeLocal(cubeName);//from   w w  w . jav  a  2  s .c o m
    CubeSegment cubeSegment = cubeInstance.getSegmentById(segmentId);
    CubeDesc cubeDesc = cubeInstance.getDescriptor();
    CuboidScheduler cuboidScheduler = new CuboidScheduler(cubeDesc);
    List<Long> allCuboidIds = cuboidScheduler.getAllCuboidIds();
    final HashMap<Long, HLLCounter> zeroValue = Maps.newHashMap();
    for (Long id : allCuboidIds) {
        zeroValue.put(id, new HLLCounter(cubeDesc.getConfig().getCubeStatsHLLPrecision()));
    }

    CubeJoinedFlatTableEnrich flatDesc = new CubeJoinedFlatTableEnrich(
            EngineFactory.getJoinedFlatTableDesc(cubeSegment), cubeDesc);

    final int[] rowKeyColumnIndexes = flatDesc.getRowKeyColumnIndexes();
    final int nRowKey = cubeDesc.getRowkey().getRowKeyColumns().length;
    final long baseCuboidId = Cuboid.getBaseCuboidId(cubeDesc);
    final Map<Long, Integer[]> allCuboidsBitSet = Maps.newHashMapWithExpectedSize(allCuboidIds.size());
    final ByteArray[] row_hashcodes = new ByteArray[nRowKey];

    for (Long cuboidId : allCuboidIds) {
        Integer[] cuboidBitSet = new Integer[Long.bitCount(cuboidId)];

        long mask = Long.highestOneBit(baseCuboidId);
        int position = 0;
        for (int i = 0; i < nRowKey; i++) {
            if ((mask & cuboidId) > 0) {
                cuboidBitSet[position] = i;
                position++;
            }
            mask = mask >> 1;
        }
        allCuboidsBitSet.put(cuboidId, cuboidBitSet);
    }
    for (int i = 0; i < nRowKey; ++i) {
        row_hashcodes[i] = new ByteArray();
    }

    final HashMap<Long, HLLCounter> samplingResult = rowJavaRDD.aggregate(zeroValue,
            new Function2<HashMap<Long, HLLCounter>, List<String>, HashMap<Long, HLLCounter>>() {

                final HashFunction hashFunction = Hashing.murmur3_128();

                @Override
                public HashMap<Long, HLLCounter> call(HashMap<Long, HLLCounter> v1, List<String> v2)
                        throws Exception {
                    for (int i = 0; i < nRowKey; i++) {
                        Hasher hc = hashFunction.newHasher();
                        String colValue = v2.get(rowKeyColumnIndexes[i]);
                        if (colValue != null) {
                            row_hashcodes[i].set(hc.putString(colValue).hash().asBytes());
                        } else {
                            row_hashcodes[i].set(hc.putInt(0).hash().asBytes());
                        }
                    }

                    for (Map.Entry<Long, Integer[]> entry : allCuboidsBitSet.entrySet()) {
                        Hasher hc = hashFunction.newHasher();
                        HLLCounter counter = v1.get(entry.getKey());
                        final Integer[] cuboidBitSet = entry.getValue();
                        for (int position = 0; position < cuboidBitSet.length; position++) {
                            hc.putBytes(row_hashcodes[cuboidBitSet[position]].array());
                        }
                        counter.add(hc.hash().asBytes());
                    }
                    return v1;
                }
            },
            new Function2<HashMap<Long, HLLCounter>, HashMap<Long, HLLCounter>, HashMap<Long, HLLCounter>>() {
                @Override
                public HashMap<Long, HLLCounter> call(HashMap<Long, HLLCounter> v1,
                        HashMap<Long, HLLCounter> v2) throws Exception {
                    Preconditions.checkArgument(v1.size() == v2.size());
                    Preconditions.checkArgument(v1.size() > 0);
                    for (Map.Entry<Long, HLLCounter> entry : v1.entrySet()) {
                        final HLLCounter counter1 = entry.getValue();
                        final HLLCounter counter2 = v2.get(entry.getKey());
                        counter1.merge(Preconditions.checkNotNull(counter2, "counter cannot be null"));
                    }
                    return v1;
                }

            });
    return samplingResult;
}

From source file:tufts.vue.LWComponent.java

public void copyStyle(LWComponent styleSource, long permittedPropertyBits) {
    if (DEBUG.STYLE || styleSource == null) {
        System.out.println("COPY STYLE of " + Util.tags(styleSource) + " ==>> " + Util.tags(this)
                + " permitBits=" + Long.bitCount(permittedPropertyBits));
    }//  w  ww .  j a  v a2 s .c o m
    if (styleSource == null)
        return;
    for (Key key : Key.AllKeys)
        //if (key.isStyleProperty && styleSource.supportsProperty(key) && (permittedPropertyBits & key.bit) != 0)
        if (styleSource.isStyling(key) && (permittedPropertyBits & key.bit) != 0)
            key.copyValue(styleSource, this);
}

From source file:tufts.vue.LWComponent.java

public void copyProperties(LWComponent source, long propertyBits) {
    if (DEBUG.STYLE)
        System.out//w  w  w  .ja va  2  s  .c  om
                .println("COPY PROPS of " + source + " ==>> " + this + " bits=" + Long.bitCount(propertyBits));
    for (Key key : Key.AllKeys)
        if ((propertyBits & key.bit) != 0 && source.supportsProperty(key))
            key.copyValue(source, this);
}