当前位置: 首页>>代码示例>>Java>>正文


Java UnsignedLongs类代码示例

本文整理汇总了Java中com.google.common.primitives.UnsignedLongs的典型用法代码示例。如果您正苦于以下问题:Java UnsignedLongs类的具体用法?Java UnsignedLongs怎么用?Java UnsignedLongs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnsignedLongs类属于com.google.common.primitives包,在下文中一共展示了UnsignedLongs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: fromString

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
 * Returns PortNumber instance from String representation.
 *
 * @param s String representation equivalent to {@link PortNumber#toString()}
 * @return {@link PortNumber} instance
 * @throws IllegalArgumentException if given String was malformed
 */
public static PortNumber fromString(String s) {
    checkNotNull(s);
    checkArgument(!s.isEmpty(), "cannot be empty");

    if (isAsciiDecimal(s.charAt(0))) {
        // unsigned decimal string
        return portNumber(s);
    } else if (s.startsWith("[")) {
        // named PortNumber
        Matcher matcher = NAMED.matcher(s);
        checkArgument(matcher.matches(), "Invalid named PortNumber %s", s);

        String name = matcher.group("name");
        String num = matcher.group("num");
        return portNumber(UnsignedLongs.parseUnsignedLong(num), name);
    }

    // Logical
    if (s.startsWith("UNKNOWN(") && s.endsWith(")")) {
        return portNumber(s.substring("UNKNOWN(".length(), s.length() - 1));
    } else {
        return Logical.valueOf(s).instance;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:32,代码来源:PortNumber.java

示例3: 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

示例4: 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

示例5: parseUnsignedLong

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
public static long parseUnsignedLong(String st, TExecutionContext context)
{
    Object truncated = CastUtils.truncateNonDigits(st, context);

    if (truncated instanceof String)
        st = (String)truncated;
    else
        st = CastUtils.truncateNonDigitPlainString(((BigDecimal)truncated).toPlainString(),
                                                   context);

    long value;
    try 
    {
        value = UnsignedLongs.parseUnsignedLong(st);
    } catch (NumberFormatException e) { // overflow error
        context.reportOverflow(e.getMessage());

        // check wether the value is too big or too small
        if (st.charAt(0) == '-')
            value = 0;
        else
            value = UnsignedLongs.MAX_VALUE;
    }
    return value;
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:26,代码来源:CastUtils.java

示例6: newInstance

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public YamlProject<T> newInstance(final Branch branch) {
  try {
    // If the branch name contains '/' then use its MD5 hash
    // as the project name, but otherwise use the branch name
    // for backwards compatibility.
    final String hashedName = UnsignedLongs.toString(Hashing.md5().hashString(
        branch.getName(), Charsets.UTF_8).asLong(), 16);
    final String projectName =
        branch.getName().indexOf('/') == -1 ? branch.getName() : hashedName;
    final YamlProject<T> project = new YamlProject<T>(
        (YamlMultiBranchProject<T>) getOwner(),
        projectName, null /* module */);

    // Set the display name so that it is always the branch name.
    project.setDisplayName(branch.getName());

    project.setBranch(branch);

    return decorate(project);
  } catch (IOException e) {
    logger.log(SEVERE, e.getMessage(), e);
    return null;
  }
}
 
开发者ID:jenkinsci,项目名称:yaml-project-plugin,代码行数:27,代码来源:YamlProjectFactory.java

示例7: 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

示例8: deserialize

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
 * Deserialize circuit id from byte string.
 *
 * @param circuitId the circuit id byte string
 * @return a Circuit Id
 */
public static CircuitId deserialize(byte[] circuitId) {
    String cIdString = new String(circuitId, StandardCharsets.US_ASCII);
    List<String> splittedCircuitId = Lists.newArrayList(cIdString.split(SEPARATOR));
    checkArgument(splittedCircuitId.size() > 1, "Illegal circuit id.");
    // remove last element (vlan id)
    String vlanId = splittedCircuitId.remove(splittedCircuitId.size() - 1);

    // Reconstruct device Id
    String connectPoint = String.join(SEPARATOR, splittedCircuitId);

    String[] splittedConnectPoint = connectPoint.split(DEVICE_PORT_SEPARATOR);
    // Check connect point is valid or not
    checkArgument(splittedConnectPoint.length == 2,
                  "Connect point must be in \"deviceUri/portNumber\" format");

    // Check the port number is a number or not
    UnsignedLongs.decode(splittedConnectPoint[1]);

    return new CircuitId(connectPoint, VlanId.vlanId(vlanId));
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:27,代码来源:CircuitId.java

示例9: compareTo

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
 * Lexicographically compare two arrays.
 *
 * @param buffer1 left operand: a byte[] or null
 * @param buffer2 right operand: a byte[] or null
 * @param memoryOffset1 Where to start comparing in the left buffer (pure memory address if buffer1 is null, or relative otherwise)
 * @param memoryOffset2 Where to start comparing in the right buffer (pure memory address if buffer1 is null, or relative otherwise)
 * @param length1 How much to compare from the left buffer
 * @param length2 How much to compare from the right buffer
 * @return 0 if equal, < 0 if left is less than right, etc.
 */

public static int compareTo(Object buffer1, long memoryOffset1, int length1,
                     Object buffer2, long memoryOffset2, int length2)
{
    int minLength = Math.min(length1, length2);

    /*
     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
     * time is no slower than comparing 4 bytes at a time even on 32-bit.
     * On the other hand, it is substantially faster on 64-bit.
     */
    int wordComparisons = minLength & ~7;
    for (int i = 0; i < wordComparisons ; i += Longs.BYTES)
    {
        long lw = theUnsafe.getLong(buffer1, memoryOffset1 + (long) i);
        long rw = theUnsafe.getLong(buffer2, memoryOffset2 + (long) i);

        if (lw != rw)
        {
            if (BIG_ENDIAN) {
                return UnsignedLongs.compare(lw, rw);
            }

            return UnsignedLongs.compare(Long.reverseBytes(lw), Long.reverseBytes(rw));
        }
    }

    for (int i = wordComparisons ; i < minLength ; i++)
    {
        int b1 = theUnsafe.getByte(buffer1, memoryOffset1 + i) & 0xFF;
        int b2 = theUnsafe.getByte(buffer2, memoryOffset2 + i) & 0xFF;
        if (b1 != b2) {
            return b1 - b2;
        }
    }

    return length1 - length2;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:50,代码来源:FastByteOperations.java

示例10: 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

示例11: 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

示例12: logState

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
 * Logs the current the state of the permutation.
 * Intended only for debugging purposes.
 *
 * @param message message to be used as title of the current state
 */

private void logState(String message) {
    String logEntry = message + "[ ";
    for (int y = 0; y < 5; y++) {
        logEntry += "\t[ ";
        for (int x = 0; x < 5; x++) {
            logEntry += "0x" + UnsignedLongs.toString(this.state[x][y], 16) + ", ";
        }
        logEntry += " ]";
    }
    logEntry += " ]";

    //Log.debug(logEntry);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:21,代码来源:Keccak.java

示例13: memcmp

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
private static final int memcmp(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) {
  int lLen = lEnd - lStart;
  int rLen = rEnd - rStart;
  int n = Math.min(rLen, lLen);
  long lPos = laddr + lStart;
  long rPos = raddr + rStart;

  while (n > 7) {
    long leftLong = PlatformDependent.getLong(lPos);
    long rightLong = PlatformDependent.getLong(rPos);
    if (leftLong != rightLong) {
      return UnsignedLongs.compare(Long.reverseBytes(leftLong), Long.reverseBytes(rightLong));
    }
    lPos += 8;
    rPos += 8;
    n -= 8;
  }

  while (n-- != 0) {
    byte leftByte = PlatformDependent.getByte(lPos);
    byte rightByte = PlatformDependent.getByte(rPos);
    if (leftByte != rightByte) {
      return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
    }
    lPos++;
    rPos++;
  }

  if (lLen == rLen) {
    return 0;
  }

  return lLen > rLen ? 1 : -1;

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:36,代码来源:ByteFunctionHelpers.java

示例14: decodeLogicalPort

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
private String decodeLogicalPort() {
    Logical logical = LOGICAL.get().get(number);
    if (logical != null) {
        // enum name
        return logical.toString();
    }
    return String.format("UNKNOWN(%s)", UnsignedLongs.toString(number));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:9,代码来源:PortNumber.java

示例15: compareTo

import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
 * Lexicographically compare two arrays.
 *
 * @param buffer1       left operand: a byte[] or null
 * @param buffer2       right operand: a byte[] or null
 * @param memoryOffset1 Where to start comparing in the left buffer (pure memory address if buffer1 is null, or relative otherwise)
 * @param memoryOffset2 Where to start comparing in the right buffer (pure memory address if buffer1 is null, or relative otherwise)
 * @param length1       How much to compare from the left buffer
 * @param length2       How much to compare from the right buffer
 * @return 0 if equal, < 0 if left is less than right, etc.
 */

public static int compareTo(Object buffer1, long memoryOffset1, int length1,
                            Object buffer2, long memoryOffset2, int length2) {
    int minLength = Math.min(length1, length2);

    /*
     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
     * time is no slower than comparing 4 bytes at a time even on 32-bit.
     * On the other hand, it is substantially faster on 64-bit.
     */
    int wordComparisons = minLength & ~7;
    for (int i = 0; i < wordComparisons; i += Longs.BYTES) {
        long lw = THE_UNSAFE.getLong(buffer1, memoryOffset1 + (long) i);
        long rw = THE_UNSAFE.getLong(buffer2, memoryOffset2 + (long) i);

        if (lw != rw) {
            if (BIG_ENDIAN) {
                return UnsignedLongs.compare(lw, rw);
            }

            return UnsignedLongs.compare(Long.reverseBytes(lw), Long.reverseBytes(rw));
        }
    }

    for (int i = wordComparisons; i < minLength; i++) {
        int b1 = THE_UNSAFE.getByte(buffer1, memoryOffset1 + i) & 0xFF;
        int b2 = THE_UNSAFE.getByte(buffer2, memoryOffset2 + i) & 0xFF;
        if (b1 != b2) {
            return b1 - b2;
        }
    }

    return length1 - length2;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:46,代码来源:FastByteOperations.java


注:本文中的com.google.common.primitives.UnsignedLongs类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。