Example usage for com.google.common.math LongMath log2

List of usage examples for com.google.common.math LongMath log2

Introduction

In this page you can find the example usage for com.google.common.math LongMath log2.

Prototype

@SuppressWarnings("fallthrough")

public static int log2(long x, RoundingMode mode) 

Source Link

Document

Returns the base-2 logarithm of x , rounded according to the specified rounding mode.

Usage

From source file:org.apache.solr.client.solrj.retry.FlexibleBoundedExponentialBackoffRetry.java

/**
 * @param baseSleepTimeNanos//from ww  w . j av a2s . c  o  m
 *          initial amount of time to wait between retries
 * @param maxSleepTimeNanos
 *          max time in nanos to sleep on each retry
 * @param maxRetries
 *          max number of times to retry
 * @param maxElapsedTimeNanos
 *          max time in nanos to spend across all retries
 */
public FlexibleBoundedExponentialBackoffRetry(long baseSleepTimeNanos, long maxSleepTimeNanos, int maxRetries,
        long maxElapsedTimeNanos) {

    Preconditions.checkArgument(baseSleepTimeNanos >= 0, "baseSleepTimeNanos must not be negative: %s",
            baseSleepTimeNanos);
    Preconditions.checkArgument(maxSleepTimeNanos >= baseSleepTimeNanos,
            "maxSleepNanos: %s must not be less than baseSleepTimeNanos: %s", maxSleepTimeNanos,
            baseSleepTimeNanos);
    Preconditions.checkArgument(maxRetries >= 0, "maxRetries must not be negative: %s", maxRetries);
    Preconditions.checkArgument(maxElapsedTimeNanos >= 0, "maxElapsedTimeNanos must not be negative: %s",
            maxElapsedTimeNanos);

    baseSleepTimeNanos = Math.max(1, baseSleepTimeNanos);
    this.baseSleepTimeNanos = baseSleepTimeNanos;
    this.maxSleepTimeNanos = maxSleepTimeNanos;
    this.maxRetries = maxRetries;
    this.maxElapsedTimeNanos = maxElapsedTimeNanos;
    this.retriesLimit = LongMath.log2(Long.MAX_VALUE / baseSleepTimeNanos, RoundingMode.DOWN) - 2;
}

From source file:org.apache.beam.runners.dataflow.worker.OrderedCode.java

/** Return floor(log2(n)) for positive integer n. Returns -1 iff n == 0. */
int log2Floor(long n) {
    if (n < 0) {
        throw new IllegalArgumentException("must be non-negative");
    }// w  w  w . j a v  a2 s .  c  o  m
    return n == 0 ? -1 : LongMath.log2(n, RoundingMode.FLOOR);
}

From source file:org.apache.beam.sdk.io.gcp.spanner.OrderedCode.java

/**
 * Return floor(log2(n)) for positive integer n.  Returns -1 iff n == 0.
 *
 *//*from www. j ava2s.co  m*/
@VisibleForTesting
int log2Floor(long n) {
    checkArgument(n >= 0);
    return n == 0 ? -1 : LongMath.log2(n, RoundingMode.FLOOR);
}