Example usage for com.google.common.primitives UnsignedLong doubleValue

List of usage examples for com.google.common.primitives UnsignedLong doubleValue

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedLong doubleValue.

Prototype

@Override
public double doubleValue() 

Source Link

Document

Returns the value of this UnsignedLong as a double , analogous to a widening primitive conversion from long to double , and correctly rounded.

Usage

From source file:com.streametry.jumphash.JumpHash.java

/** Jump Consistent Hashing algorithm
 *
 * @param buckets number of buckets/*from ww w  .j  av a 2  s . c o m*/
 * @param keyHash hash of a key
 * @return selected bucket
 */
public static int consistent(int buckets, long keyHash) {

    UnsignedLong key = fromLongBits(keyHash);

    long b = -1, j = 0;
    while (j < buckets) {
        b = j;

        key = key.times(constant).plus(ONE);
        UnsignedLong keyShift = fromLongBits(key.longValue() >>> 33).plus(ONE);

        j = (long) ((b + 1) * (constant2 / keyShift.doubleValue()));
    }

    return (int) b;
}