Java Code Examples for com.google.common.primitives.Ints#MAX_POWER_OF_TWO

The following examples show how to use com.google.common.primitives.Ints#MAX_POWER_OF_TWO . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: codebuff   File: Maps.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a capacity that is sufficient to keep the map from being resized as
 * long as it grows no larger than expectedSize and the load factor is >= its
 * default (0.75).
 */


static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 2
Source Project: codebuff   File: Maps.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a capacity that is sufficient to keep the map from being resized as
 * long as it grows no larger than expectedSize and the load factor is >= its
 * default (0.75).
 */


static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 3
Source Project: codebuff   File: Maps.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a capacity that is sufficient to keep the map from being resized as
 * long as it grows no larger than expectedSize and the load factor is >= its
 * default (0.75).
 */


static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 4
Source Project: codebuff   File: Maps.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a capacity that is sufficient to keep the map from being resized as
 * long as it grows no larger than expectedSize and the load factor is >= its
 * default (0.75).
 */


static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 5
Source Project: fastjgame   File: AptReflectUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a capacity that is sufficient to keep the map from being resized as long as it grows no
 * larger than expectedSize and the load factor is ≥ its default (0.75).
 */
public static int capacity(int expectedSize) {
    if (expectedSize < 3) {
        return 3;
    }

    if (expectedSize < Ints.MAX_POWER_OF_TWO) {
        // This is the calculation used in JDK8 to resize when a putAll
        // happens; it seems to be the most conservative calculation we
        // can make.  0.75 is the default load factor.
        return (int) ((float) expectedSize / 0.75F + 1.0F);
    }

    return Integer.MAX_VALUE; // any large value
}
 
Example 6
Source Project: fastjgame   File: MathUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int roundToPowerOfTwo(int value) {
    if (value < 0) {
        throw new IllegalArgumentException("Given value:" + value + ". Expecting value >= 0.");
    }
    int n = -1 >>> Integer.numberOfLeadingZeros(value - 1);
    return (n < 0) ? 1 : (n >= Ints.MAX_POWER_OF_TWO) ? Ints.MAX_POWER_OF_TWO : n + 1;
}
 
Example 7
Source Project: xtext-extras   File: Maps2.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Copied from {@link Maps#capacity(int)}.
 */
private static int capacity(int expectedSize) {
	if (expectedSize < 3) {
		Preconditions.checkArgument(expectedSize >= 0);
		return expectedSize + 1;
	}
	if (expectedSize < Ints.MAX_POWER_OF_TWO) {
		return expectedSize + expectedSize / 3;
	}
	return Integer.MAX_VALUE; // any large value
}
 
Example 8
private static int capacity(int initialSize) {
	if (initialSize < 3)
		return initialSize + 1;
	else if (initialSize < Ints.MAX_POWER_OF_TWO)
		return initialSize + initialSize / 3;
	else
		return Integer.MAX_VALUE;
}
 
Example 9
Source Project: codebuff   File: Maps.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns a capacity that is sufficient to keep the map from being resized as
 * long as it grows no larger than expectedSize and the load factor is >= its
 * default (0.75).
 */
static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 10
Source Project: codebuff   File: Striped.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}
 
Example 11
Source Project: codebuff   File: Striped.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}
 
Example 12
Source Project: codebuff   File: Striped.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}
 
Example 13
Source Project: codebuff   File: Striped.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}
 
Example 14
Source Project: codebuff   File: Striped.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}