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


Java UnsignedLongs.remainder方法代碼示例

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


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

示例1: squareMod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
@Override
long squareMod(long a, long m) {
  long aHi = a >>> 32; // < 2^31
  long aLo = a & 0xFFFFFFFFL; // < 2^32

  /*
   * a^2 == aHi^2 * 2^64 + aHi * aLo * 2^33 + aLo^2
   *     == (aHi^2 * 2^32 + aHi * aLo * 2) * 2^32 + aLo^2
   * We carry out this computation in modular arithmetic.  Since times2ToThe32Mod accepts any
   * unsigned long, we don't have to do a mod on every operation, only when intermediate
   * results can exceed 2^63.
   */
  long result = times2ToThe32Mod(aHi * aHi /* < 2^62 */, m); // < m < 2^63
  long hiLo = aHi * aLo * 2;
  if (hiLo < 0) {
    hiLo = UnsignedLongs.remainder(hiLo, m);
  }
  // hiLo < 2^63
  result += hiLo; // result < 2^64
  result = times2ToThe32Mod(result, m); // result < m < 2^63
  return plusMod(
      result,
      UnsignedLongs.remainder(aLo * aLo /* < 2^64 */, m),
      m);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:26,代碼來源:LongMath.java

示例2: mulMod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
@Override
long mulMod(long a, long b, long m) {
  long aHi = a >>> 32; // < 2^31
  long bHi = b >>> 32; // < 2^31
  long aLo = a & 0xFFFFFFFFL; // < 2^32
  long bLo = b & 0xFFFFFFFFL; // < 2^32

  /*
   * a * b == aHi * bHi * 2^64 + (aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo.
   *       == (aHi * bHi * 2^32 + aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo
   *
   * We carry out this computation in modular arithmetic. Since times2ToThe32Mod accepts any
   * unsigned long, we don't have to do a mod on every operation, only when intermediate
   * results can exceed 2^63.
   */
  long result = times2ToThe32Mod(aHi * bHi /* < 2^62 */, m); // < m < 2^63
  result += aHi * bLo; // aHi * bLo < 2^63, result < 2^64
  if (result < 0) {
    result = UnsignedLongs.remainder(result, m);
  }
  // result < 2^63 again
  result += aLo * bHi; // aLo * bHi < 2^63, result < 2^64
  result = times2ToThe32Mod(result, m); // result < m < 2^63
  return plusMod(result, UnsignedLongs.remainder(aLo * bLo /* < 2^64 */, m), m);
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:26,代碼來源:LongMath.java

示例3: squareMod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
@Override
long squareMod(long a, long m) {
  long aHi = a >>> 32; // < 2^31
  long aLo = a & 0xFFFFFFFFL; // < 2^32

  /*
   * a^2 == aHi^2 * 2^64 + aHi * aLo * 2^33 + aLo^2
   *     == (aHi^2 * 2^32 + aHi * aLo * 2) * 2^32 + aLo^2
   * We carry out this computation in modular arithmetic.  Since times2ToThe32Mod accepts any
   * unsigned long, we don't have to do a mod on every operation, only when intermediate
   * results can exceed 2^63.
   */
  long result = times2ToThe32Mod(aHi * aHi /* < 2^62 */, m); // < m < 2^63
  long hiLo = aHi * aLo * 2;
  if (hiLo < 0) {
    hiLo = UnsignedLongs.remainder(hiLo, m);
  }
  // hiLo < 2^63
  result += hiLo; // result < 2^64
  result = times2ToThe32Mod(result, m); // result < m < 2^63
  return plusMod(result, UnsignedLongs.remainder(aLo * aLo /* < 2^64 */, m), m);
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:23,代碼來源:LongMath.java

示例4: assemble

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
@Override
void assemble(M68KAssemblyContext context) throws IOException {
    context.sizeNotAllowed();
    if (context.requireNumberOfOperands(1)) {
        final Value alignmentValue = evaluateExpressionOperand(context, 0);
        if (alignmentValue != null) {
            final CardinalValueVisitor alignmentVisitor = context.cardinalValueVisitor;
            alignmentVisitor.reset(1, NEGATIVE_VALUE_ERROR_FACTORY);
            Value.accept(alignmentValue, alignmentVisitor);
            final long alignment = alignmentVisitor.getValue();
            if (alignment != 0) {
                final long remainder = UnsignedLongs.remainder(context.programCounter, alignment);
                final long paddingSize = remainder == 0 ? 0 : alignment - remainder;

                for (long i = 0; UnsignedLongs.compare(i, paddingSize) < 0; i++) {
                    context.appendByte((byte) 0);
                }
            } else {
                context.addTentativeMessage(new AlignmentMustNotBeZeroOrNegativeErrorMessage());
            }
        }
    }
}
 
開發者ID:reasm,項目名稱:reasm-m68k,代碼行數:24,代碼來源:AlignDirective.java

示例5: times2ToThe32Mod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
/**
 * Returns (a * 2^32) mod m. a may be any unsigned long.
 */
private long times2ToThe32Mod(long a, long m) {
  int remainingPowersOf2 = 32;
  do {
    int shift = Math.min(remainingPowersOf2, Long.numberOfLeadingZeros(a));
    // shift is either the number of powers of 2 left to multiply a by, or the biggest shift
    // possible while keeping a in an unsigned long.
    a = UnsignedLongs.remainder(a << shift, m);
    remainingPowersOf2 -= shift;
  } while (remainingPowersOf2 > 0);
  return a;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:15,代碼來源:LongMath.java

示例6: mulMod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
@Override
long mulMod(long a, long b, long m) {
  long aHi = a >>> 32; // < 2^31
  long bHi = b >>> 32; // < 2^31
  long aLo = a & 0xFFFFFFFFL; // < 2^32
  long bLo = b & 0xFFFFFFFFL; // < 2^32

  /*
   * a * b == aHi * bHi * 2^64 + (aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo.
   *       == (aHi * bHi * 2^32 + aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo
   *
   * We carry out this computation in modular arithmetic. Since times2ToThe32Mod accepts any
   * unsigned long, we don't have to do a mod on every operation, only when intermediate
   * results can exceed 2^63.
   */
  long result = times2ToThe32Mod(aHi * bHi /* < 2^62 */, m); // < m < 2^63
  result += aHi * bLo; // aHi * bLo < 2^63, result < 2^64
  if (result < 0) {
    result = UnsignedLongs.remainder(result, m);
  }
  // result < 2^63 again
  result += aLo * bHi; // aLo * bHi < 2^63, result < 2^64
  result = times2ToThe32Mod(result, m); // result < m < 2^63
  return plusMod(
      result,
      UnsignedLongs.remainder(aLo * bLo /* < 2^64 */, m),
      m);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:29,代碼來源:LongMath.java

示例7: times2ToThe32Mod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
/**
 * Returns (a * 2^32) mod m. a may be any unsigned long.
 */

private long times2ToThe32Mod(long a, long m) {
  int remainingPowersOf2 = 32;
  do {
    int shift = Math.min(remainingPowersOf2, Long.numberOfLeadingZeros(a));
    // shift is either the number of powers of 2 left to multiply a by, or the biggest shift
    // possible while keeping a in an unsigned long.
    a = UnsignedLongs.remainder(a << shift, m);
    remainingPowersOf2 -= shift;
  } while (remainingPowersOf2 > 0);
  return a;
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:16,代碼來源:LongMath.java

示例8: times2ToThe32Mod

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
/** Returns (a * 2^32) mod m. a may be any unsigned long. */
private long times2ToThe32Mod(long a, long m) {
  int remainingPowersOf2 = 32;
  do {
    int shift = Math.min(remainingPowersOf2, Long.numberOfLeadingZeros(a));
    // shift is either the number of powers of 2 left to multiply a by, or the biggest shift
    // possible while keeping a in an unsigned long.
    a = UnsignedLongs.remainder(a << shift, m);
    remainingPowersOf2 -= shift;
  } while (remainingPowersOf2 > 0);
  return a;
}
 
開發者ID:google,項目名稱:guava,代碼行數:13,代碼來源:LongMath.java

示例9: getWantedSlot

import com.google.common.primitives.UnsignedLongs; //導入方法依賴的package包/類
private static long getWantedSlot(long hash, long capacity) {
  return UnsignedLongs.remainder(hash, capacity);
}
 
開發者ID:spotify,項目名稱:sparkey-java,代碼行數:4,代碼來源:IndexHash.java


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