當前位置: 首頁>>代碼示例>>Java>>正文


Java LongMath.pow方法代碼示例

本文整理匯總了Java中com.google.common.math.LongMath.pow方法的典型用法代碼示例。如果您正苦於以下問題:Java LongMath.pow方法的具體用法?Java LongMath.pow怎麽用?Java LongMath.pow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.math.LongMath的用法示例。


在下文中一共展示了LongMath.pow方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bitsForNumElementsWithLoadFactor

import com.google.common.math.LongMath; //導入方法依賴的package包/類
static int bitsForNumElementsWithLoadFactor(long numElements) {
    if (numElements == 0) {
        return 1;
    }

    int candidateBits = Long.bitCount(numElements) == 1 ?
            Math.max(1, Long.numberOfTrailingZeros(numElements)) :
            Long.numberOfTrailingZeros(Long.highestOneBit(numElements) << 1L);

    //May need an extra bit due to load factor
    if (((long) (LongMath.pow(2, candidateBits) * 0.75)) < numElements) {
        candidateBits++;
    }

    return candidateBits;
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:17,代碼來源:QuotientFilter.java

示例2: IdGenerator

import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
 * @param alphabet the alphabet of legal characters for IDs generated by this generator
 * @param perturb whether or not to perturb generated IDs by a random perturbation to avoid
 *                collisions in distributed key generation. Pass {@code false} if this generator
 *                is used to generate a sort key that is a secondary key where ordering
 *                conflicts can be deterministically resolved by the primary key. This setting
 *                only applies to the {@code generate...} methods.
 */
public IdGenerator(IdAlphabet alphabet, boolean perturb) {
    mAlphabet = alphabet;
    mPerturb = perturb;

    // Find the maximum number of digits we'd need to encode an unsigned long if the radix were
    // uniform for the entire string.
    // ceil(log_RADIX(Long.MAX + 1))
    mLongUniformRadixLength = (int) Math.ceil(LOG_LONG / Math.log(alphabet.radix()));
    mMostSignificantUnit = LongMath.pow(alphabet.radix(), mLongUniformRadixLength - 1);

    mMaxSafeMostSignificantDigit = (int) (Long.MAX_VALUE / mMostSignificantUnit);
    mMaxSafeMostSignificantValue = mMaxSafeMostSignificantDigit * mMostSignificantUnit;

    // The first character may have additional restrictions, so we have less chars to work with
    // for the first digit. If we still have enough digits, we'll proceed and just use a special
    // mapping for the leading digit. Otherwise, we'll pad by a leading zero, thus making the
    // remaining encoding the common case.

    // So, what most-significant digit do we need to encode the max unsigned value?
    PartialDivisionResult div = transformToSignedDivision(-1);
    int maxMostSignficantDigit = div.partialMostSignificantDigit +
            (int) (div.partialRemainder / mMostSignificantUnit);
    mLongEncodedLength = maxMostSignficantDigit < alphabet.leadingRadix() ?
            mLongUniformRadixLength : mLongUniformRadixLength + 1;
}
 
開發者ID:vanadium-archive,項目名稱:todos,代碼行數:34,代碼來源:IdGenerator.java

示例3: toL

import com.google.common.math.LongMath; //導入方法依賴的package包/類
private static Long toL(String value) {
	if (null == value) {
		return 0L;
	}
	
	int idxSep = value.indexOf(SEPARATOR_CHAR);
	if (idxSep > -1) {
		value = value.substring(idxSep + 1);
	}
	
	long r = 0;
	int length = value.length();
	for (int i = 0; i < length; i++) {
		long val = LongMath.pow(RADIX, (length - i - 1));
		char c = value.charAt(i);
		int tmp = KEYS.indexOf(c);
		r += (tmp * val);
	}

	return r;
}
 
開發者ID:jronrun,項目名稱:benayn,代碼行數:22,代碼來源:Scale62.java

示例4: getBytes

import com.google.common.math.LongMath; //導入方法依賴的package包/類
protected static byte[] getBytes(long sum, int arraySize) {
    final byte[] b = new byte[arraySize];
    for (int i = 0; i < b.length; i++) {
        final int reverseIndex = b.length - 1 - i;
        final long factor = LongMath.pow(256, reverseIndex);
        final long base = sum / factor;
        b[i] = UnsignedBytes.checkedCast(base);
        sum = sum - (base * factor);
    }
    return b;
}
 
開發者ID:kaspersorensen,項目名稱:kafka-record-updater,代碼行數:12,代碼來源:SegmentFileUpdater.java

示例5: getLong

import com.google.common.math.LongMath; //導入方法依賴的package包/類
protected static long getLong(byte[] b) {
    long sum = 0;
    for (int i = 0; i < b.length; i++) {
        final int reverseIndex = b.length - 1 - i;
        final long factor = LongMath.pow(256, reverseIndex);
        final int base = UnsignedBytes.toInt(b[i]);
        sum += base * factor;
    }
    return sum;
}
 
開發者ID:kaspersorensen,項目名稱:kafka-record-updater,代碼行數:11,代碼來源:SegmentFileUpdater.java

示例6: pow

import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Benchmark int pow(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += LongMath.pow(positive[j], exponents[j]);
  }
  return tmp;
}
 
開發者ID:sander120786,項目名稱:guava-libraries,代碼行數:9,代碼來源:LongMathBenchmark.java

示例7: buildChartAndTableEntries

import com.google.common.math.LongMath; //導入方法依賴的package包/類
private void buildChartAndTableEntries(List<Offer> sortedList, OfferPayload.Direction direction, List<XYChart.Data> data, ObservableList<OfferListItem> offerTableList) {
    data.clear();
    double accumulatedAmount = 0;
    List<OfferListItem> offerTableListTemp = new ArrayList<>();
    for (Offer offer : sortedList) {
        Price price = offer.getPrice();
        if (price != null) {
            double amount = (double) offer.getAmount().value / LongMath.pow(10, offer.getAmount().smallestUnitExponent());
            accumulatedAmount += amount;
            offerTableListTemp.add(new OfferListItem(offer, accumulatedAmount));

            double priceAsDouble = (double) price.getValue() / LongMath.pow(10, price.smallestUnitExponent());
            if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) {
                if (direction.equals(OfferPayload.Direction.SELL))
                    data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount));
                else
                    data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount));
            } else {
                if (direction.equals(OfferPayload.Direction.BUY))
                    data.add(0, new XYChart.Data<>(priceAsDouble, accumulatedAmount));
                else
                    data.add(new XYChart.Data<>(priceAsDouble, accumulatedAmount));
            }
        }
    }
    offerTableList.setAll(offerTableListTemp);
}
 
開發者ID:bisq-network,項目名稱:exchange,代碼行數:28,代碼來源:OfferBookChartViewModel.java

示例8: pur

import com.google.common.math.LongMath; //導入方法依賴的package包/類
private static long pur(int p) {
	return LongMath.pow(2, p); //(long) Math.pow(2, p)   2^p
}
 
開發者ID:jronrun,項目名稱:benayn,代碼行數:4,代碼來源:SimplePurview.java

示例9: calcIncLength

import com.google.common.math.LongMath; //導入方法依賴的package包/類
private void calcIncLength(int len) {
	this.increaseLengthAt = LongMath.pow(numberSystem.getDigits()
			.length(), len);
}
 
開發者ID:pfichtner,項目名稱:jcrunch,代碼行數:5,代碼來源:Mutator.java

示例10: getMaximalAffinityMask

import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
public long getMaximalAffinityMask() {
	return LongMath.pow(2, Runtime.getRuntime().availableProcessors())-1;
}
 
開發者ID:jbosboom,項目名稱:streamjit,代碼行數:5,代碼來源:NullAffinityStrategy.java

示例11: pow

import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
 * 平方
 * 
 * @param k
 *            平方次數,不能為負數, k=0時返回1.
 */
public static long pow(long b, int k) {
	return LongMath.pow(b, k);
}
 
開發者ID:zhangjunfang,項目名稱:util,代碼行數:10,代碼來源:MathUtil.java


注:本文中的com.google.common.math.LongMath.pow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。