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 . 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 check out the related API usage on the sidebar.
Example 1
Source File: Maps.java    From codebuff with 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 File: Maps.java    From codebuff with 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 File: Maps.java    From codebuff with 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 File: Maps.java    From codebuff with 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 File: AptReflectUtils.java    From fastjgame with 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 File: MathUtils.java    From fastjgame with 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 File: Maps2.java    From xtext-extras with 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
Source File: CollectionLiterals.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
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 File: Maps.java    From codebuff with 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 File: Striped.java    From codebuff with 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 File: Striped.java    From codebuff with 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 File: Striped.java    From codebuff with 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 File: Striped.java    From codebuff with 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 File: Striped.java    From codebuff with 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;
}