protected Attribute (final long type) { this.type = type; this.typeBit = Long.numberOfTrailingZeros(type); }
protected Attribute (final long type) { this.type = type; this.typeBit = Long.numberOfTrailingZeros(type); }
public static int lengthOfDouble(double value) { int requiredBits = 64 - Long.numberOfTrailingZeros(Double.doubleToRawLongBits(value)); if (requiredBits == 0) { requiredBits = 1; } return (requiredBits + 0x07) >> 3; }
public static int lengthOfFloat(float value) { int requiredBits = 64 - Long.numberOfTrailingZeros(((long) (Float.floatToRawIntBits(value))) << 32); if (requiredBits == 0) { requiredBits = 1; } return (requiredBits + 0x07) >> 3; }
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before * growing the backing table. * @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */ public LongMap (int initialCapacity, float loadFactor) { if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity); initialCapacity = MathUtils.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor)); if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity); capacity = initialCapacity; if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor); this.loadFactor = loadFactor; threshold = (int)(capacity * loadFactor); mask = capacity - 1; hashShift = 63 - Long.numberOfTrailingZeros(capacity); stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2); pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8); keyTable = new long[capacity + stashCapacity]; valueTable = (V[])new Object[keyTable.length]; }
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before * growing the backing table. * @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */ public LongMap (int initialCapacity, float loadFactor) { if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity); initialCapacity = MathUtils.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor)); if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity); capacity = initialCapacity; if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor); this.loadFactor = loadFactor; threshold = (int)(capacity * loadFactor); mask = capacity - 1; hashShift = 63 - Long.numberOfTrailingZeros(capacity); stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2); pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8); keyTable = new long[capacity + stashCapacity]; valueTable = (V[])new Object[keyTable.length]; }
private void resize (int newSize) { int oldEndIndex = capacity + stashSize; capacity = newSize; threshold = (int)(newSize * loadFactor); mask = newSize - 1; hashShift = 63 - Long.numberOfTrailingZeros(newSize); stashCapacity = Math.max(3, (int)Math.ceil(Math.log(newSize)) * 2); pushIterations = Math.max(Math.min(newSize, 8), (int)Math.sqrt(newSize) / 8); long[] oldKeyTable = keyTable; V[] oldValueTable = valueTable; keyTable = new long[newSize + stashCapacity]; valueTable = (V[])new Object[newSize + stashCapacity]; int oldSize = size; size = hasZeroValue ? 1 : 0; stashSize = 0; if (oldSize > 0) { for (int i = 0; i < oldEndIndex; i++) { long key = oldKeyTable[i]; if (key != EMPTY) putResize(key, oldValueTable[i]); } } }
private void resize (int newSize) { int oldEndIndex = capacity + stashSize; capacity = newSize; threshold = (int)(newSize * loadFactor); mask = newSize - 1; hashShift = 63 - Long.numberOfTrailingZeros(newSize); stashCapacity = Math.max(3, (int)Math.ceil(Math.log(newSize)) * 2); pushIterations = Math.max(Math.min(newSize, 8), (int)Math.sqrt(newSize) / 8); long[] oldKeyTable = keyTable; V[] oldValueTable = valueTable; keyTable = new long[newSize + stashCapacity]; valueTable = (V[])new Object[newSize + stashCapacity]; int oldSize = size; size = hasZeroValue ? 1 : 0; stashSize = 0; if (oldSize > 0) { for (int i = 0; i < oldEndIndex; i++) { long key = oldKeyTable[i]; if (key != EMPTY) putResize(key, oldValueTable[i]); } } }
@Override public T head() { if (elements == 0) { throw new NoSuchElementException("head of empty BitSet"); } else { return fromInt.apply(Long.numberOfTrailingZeros(elements)); } }
@Override public T head() { if (elements1 == 0) { return fromInt.apply(BITS_PER_WORD + Long.numberOfTrailingZeros(elements2)); } else { return fromInt.apply(Long.numberOfTrailingZeros(elements1)); } }
@Override protected T getNext() { final int pos = Long.numberOfTrailingZeros(element); element &= ~(1L << pos); return bitSet.fromInt.apply(pos + (index << ADDRESS_BITS_PER_WORD)); }
int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7; return ((int) ((lw >>> n) & UNSIGNED_MASK)) - ((int) ((rw >>> n) & UNSIGNED_MASK));
/** Returns true if n is a strong probable prime relative to the specified base. */ private boolean testWitness(long base, long n) { int r = Long.numberOfTrailingZeros(n - 1); long d = (n - 1) >> r; base %= n; if (base == 0) { return true; } // Calculate a := base^d mod n. long a = powMod(base, d, n); // n passes this test if // base^d = 1 (mod n) // or base^(2^j * d) = -1 (mod n) for some 0 <= j < r. if (a == 1) { return true; } int j = 0; while (a != n - 1) { if (++j == r) { return false; } a = squareMod(a, n); } return true; } }
public static void readBitmap( long bitmap, long labelId, MutableLongList[] labelsPerNode ) { while ( bitmap != 0 ) { int relativeNodeId = Long.numberOfTrailingZeros( bitmap ); if ( labelsPerNode[relativeNodeId] == null ) { labelsPerNode[relativeNodeId] = new LongArrayList(); } labelsPerNode[relativeNodeId].add( labelId ); bitmap &= bitmap - 1; } }
/** * Writes a right-zero-extended value to {@code out}. */ public static void writeRightZeroExtendedValue(ByteOutput out, int type, long value) { // Figure out how many bits are needed to represent the value. int requiredBits = 64 - Long.numberOfTrailingZeros(value); if (requiredBits == 0) { requiredBits = 1; } // Round up the requiredBits to a number of bytes. int requiredBytes = (requiredBits + 0x07) >> 3; // Scootch the first bits to be written down to the low-order bits. value >>= 64 - (requiredBytes * 8); /* * Write the header byte, which includes the type and * requiredBytes - 1. */ out.writeByte(type | ((requiredBytes - 1) << 5)); // Write the value, per se. while (requiredBytes > 0) { out.writeByte((byte) value); value >>= 8; requiredBytes--; } }
/** * Returns {@code true} if {@code x} represents a mathematical integer. * * <p>This is equivalent to, but not necessarily implemented as, the expression {@code * !Double.isNaN(x) && !Double.isInfinite(x) && x == Math.rint(x)}. */ @GwtIncompatible // java.lang.Math.getExponent, com.google.common.math.DoubleUtils public static boolean isMathematicalInteger(double x) { return isFinite(x) && (x == 0.0 || SIGNIFICAND_BITS - Long.numberOfTrailingZeros(getSignificand(x)) <= getExponent(x)); }
@Override public Buffer writeHexadecimalUnsignedLong(long v) { if (v == 0) { // Both a shortcut and required since the following code can't handle zero. return writeByte('0'); } int width = Long.numberOfTrailingZeros(Long.highestOneBit(v)) / 4 + 1; Segment tail = writableSegment(width); byte[] data = tail.data; for (int pos = tail.limit + width - 1, start = tail.limit; pos >= start; pos--) { data[pos] = DIGITS[(int) (v & 0xF)]; v >>>= 4; } tail.limit += width; size += width; return this; }
/** * Returns {@code true} if {@code x} represents a mathematical integer. * * <p>This is equivalent to, but not necessarily implemented as, the expression {@code * !Double.isNaN(x) && !Double.isInfinite(x) && x == Math.rint(x)}. */ @GwtIncompatible // java.lang.Math.getExponent, com.facebook.presto.jdbc.internal.guava.math.DoubleUtils public static boolean isMathematicalInteger(double x) { return isFinite(x) && (x == 0.0 || SIGNIFICAND_BITS - Long.numberOfTrailingZeros(getSignificand(x)) <= getExponent(x)); }
/** * Returns {@code true} if {@code x} represents a mathematical integer. * * <p>This is equivalent to, but not necessarily implemented as, the expression {@code * !Double.isNaN(x) && !Double.isInfinite(x) && x == Math.rint(x)}. */ @GwtIncompatible // java.lang.Math.getExponent, com.google.common.math.DoubleUtils public static boolean isMathematicalInteger(double x) { return isFinite(x) && (x == 0.0 || SIGNIFICAND_BITS - Long.numberOfTrailingZeros(getSignificand(x)) <= getExponent(x)); }
/** * Returns {@code true} if {@code x} represents a mathematical integer. * * <p>This is equivalent to, but not necessarily implemented as, the expression {@code * !Double.isNaN(x) && !Double.isInfinite(x) && x == Math.rint(x)}. */ @GwtIncompatible // java.lang.Math.getExponent, com.google.common.math.DoubleUtils public static boolean isMathematicalInteger(double x) { return isFinite(x) && (x == 0.0 || SIGNIFICAND_BITS - Long.numberOfTrailingZeros(getSignificand(x)) <= getExponent(x)); }