public void testPlus() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().add(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedSum = aUnsigned.plus(bUnsigned); assertEquals(expected, unsignedSum.longValue()); } } }
/** * Returns the result of adding this and {@code val}. If the result would have more than 64 bits, * returns the low 64 bits of the result. * * @deprecated Use {@link #plus(UnsignedLong)}. This method is scheduled to be removed in Guava * release 15.0. */ @Deprecated @Beta public UnsignedLong add(UnsignedLong val) { return plus(val); }
protected UnsignedLong toUnsignedLong64(long l) { if (l > Integer.MAX_VALUE) { return U64_START.plus(UnsignedLong.valueOf(l)); } else { return UnsignedLong.valueOf(l); } }
@Override public Counter plus(Number value) { return new Counter(getValue().plus(toUnsignedLong(value))); }
@Override public ValueType<UnsignedLong> delta(Number value) { UnsignedLong previous = toUnsignedLong(value); // If previous value is greater-than this one, we've wrapped if (previous.compareTo(getValue()) > 0) { if (NAN_ON_COUNTER_WRAP) { throw new ArithmeticException(); } UnsignedLong count32 = getValue().plus(MAX32).plus(UnsignedLong.ONE); // Still smaller, this is a 64-bit counter wrap if (previous.compareTo(count32) > 0) { return new Counter(MAX64.minus(previous).plus(getValue()).plus(UnsignedLong.ONE)); } // Process as 32-bit counter wrap else { return new Counter(MAX32.minus(previous).plus(getValue())).plus(UnsignedLong.ONE); } } // ...no counter wrap has occurred. else { return new Counter(getValue().minus(previous)); } }
protected void addWordNGrams(List<Integer> line, List<Long> hashes, int n) { if (pruneIdxSize == 0) { return; } for (int i = 0; i < hashes.size(); i++) { UnsignedLong h = toUnsignedLong64(hashes.get(i)); for (int j = i + 1; j < hashes.size() && j < i + n; j++) { long h2 = (long) hashes.get(j).intValue(); long coeff = 116049371L; if (h2 >= 0) { h = h.times(UnsignedLong.valueOf(coeff)).plus(UnsignedLong.valueOf(h2)); } else { h = h.times(UnsignedLong.valueOf(coeff)).minus(UnsignedLong.valueOf(-h2)); } int id = h.mod(UnsignedLong.valueOf(args.getBucketNumber())).intValue(); if (pruneIdxSize > 0) { int pruneId = getPruning(id); if (pruneId >= 0) { id = pruneId; } else { continue; } } line.add(nWords + id); } } }
public void testPlus() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned .bigIntegerValue() .add(bUnsigned.bigIntegerValue()) .longValue(); UnsignedLong unsignedSum = aUnsigned.plus(bUnsigned); assertEquals(expected, unsignedSum.longValue()); } } }