当前位置: 首页>>代码示例>>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;未经允许,请勿转载。