List of usage examples for java.lang Long lowestOneBit
public static long lowestOneBit(long i)
From source file:Main.java
public static void main(String[] args) { long l = 100; System.out.println("Number = " + l); System.out.println("Binary = " + Long.toBinaryString(l)); System.out.println("Lowest one bit = " + Long.lowestOneBit(l)); }
From source file:Main.java
public static void main(String[] args) { long l = 100; System.out.println("Number = " + l); System.out.println("Binary = " + Long.toBinaryString(l)); System.out.println("Lowest one bit = " + Long.lowestOneBit(l)); System.out.print("Number of leading zeros = "); System.out.println(Long.numberOfLeadingZeros(l)); System.out.print("Number of trailing zeros = "); System.out.println(Long.numberOfTrailingZeros(l)); }
From source file:org.apache.kylin.cube.cuboid.Cuboid.java
private static Long translateToOnTreeCuboid(AggregationGroup agg, long cuboidID) { if ((cuboidID & ~agg.getPartialCubeFullMask()) > 0) { //the partial cube might not contain all required dims return null; }/* w w w. ja v a 2 s. c om*/ // add mandantory cuboidID = cuboidID | agg.getMandatoryColumnMask(); // add hierarchy for (HierarchyMask hierarchyMask : agg.getHierarchyMasks()) { long fullMask = hierarchyMask.fullMask; long intersect = cuboidID & fullMask; if (intersect != 0 && intersect != fullMask) { boolean startToFill = false; for (int i = hierarchyMask.dims.length - 1; i >= 0; i--) { if (startToFill) { cuboidID |= hierarchyMask.dims[i]; } else { if ((cuboidID & hierarchyMask.dims[i]) != 0) { startToFill = true; cuboidID |= hierarchyMask.dims[i]; } } } } } // add joint dims for (Long joint : agg.getJoints()) { if (((cuboidID | joint) != cuboidID) && ((cuboidID & ~joint) != cuboidID)) { cuboidID = cuboidID | joint; } } if (!agg.isOnTree(cuboidID)) { // no column, add one column long nonJointDims = removeBits((agg.getPartialCubeFullMask() ^ agg.getMandatoryColumnMask()), agg.getJoints()); if (nonJointDims != 0) { long nonJointNonHierarchy = removeBits(nonJointDims, Collections2.transform(agg.getHierarchyMasks(), new Function<HierarchyMask, Long>() { @Override public Long apply(HierarchyMask input) { return input.fullMask; } })); if (nonJointNonHierarchy != 0) { //there exists dim that does not belong to any joint or any hierarchy, that's perfect return cuboidID | Long.lowestOneBit(nonJointNonHierarchy); } else { //choose from a hierarchy that does not intersect with any joint dim, only check level 1 long allJointDims = agg.getJointDimsMask(); for (HierarchyMask hierarchyMask : agg.getHierarchyMasks()) { long dim = hierarchyMask.allMasks[0]; if ((dim & allJointDims) == 0) { return cuboidID | dim; } } } } cuboidID = cuboidID | Collections.min(agg.getJoints(), cuboidSelectComparator); Preconditions.checkState(agg.isOnTree(cuboidID)); } return cuboidID; }