Tabnine Logo
Integer.highestOneBit
Code IndexAdd Tabnine to your IDE (free)

How to use
highestOneBit
method
in
java.lang.Integer

Best Java code snippets using java.lang.Integer.highestOneBit (Showing top 20 results out of 2,430)

origin: netty/netty

/**
 * Calculates the minimum number of bits required to encode a value.  This can
 * then in turn be used to calculate the number of septets or octets (as
 * appropriate) to use to encode a length parameter.
 *
 * @param value The value to calculate the minimum number of bits required to encode
 * @return The minimum number of bits required to encode the supplied value
 */
private static int bitsToEncode(int value) {
  int highestOneBit = Integer.highestOneBit(value);
  int bitLength = 0;
  while ((highestOneBit >>= 1) != 0) {
    bitLength++;
  }
  return bitLength;
}
origin: google/guava

static int closedTableSize(int expectedEntries, double loadFactor) {
 // Get the recommended table size.
 // Round down to the nearest power of 2.
 expectedEntries = Math.max(expectedEntries, 2);
 int tableSize = Integer.highestOneBit(expectedEntries);
 // Check to make sure that we will not exceed the maximum load factor.
 if (expectedEntries > (int) (loadFactor * tableSize)) {
  tableSize <<= 1;
  return (tableSize > 0) ? tableSize : MAX_TABLE_SIZE;
 }
 return tableSize;
}
origin: apache/flink

/**
 * Decrements the given number down to the closest power of two. If the argument is a
 * power of two, it remains unchanged.
 *
 * @param value The value to round down.
 * @return The closest value that is a power of two and less or equal than the given value.
 */
public static int roundDownToPowerOf2(int value) {
  return Integer.highestOneBit(value);
}
origin: prestodb/presto

private static int log2Ceiling(int value)
{
  return Integer.highestOneBit(value - 1) << 1;
}
origin: google/guava

private static int expandedCapacity(int oldCapacity, int minCapacity) {
 if (minCapacity < 0) {
  throw new AssertionError("cannot store more than MAX_VALUE elements");
 }
 // careful of overflow!
 int newCapacity = oldCapacity + (oldCapacity >> 1) + 1;
 if (newCapacity < minCapacity) {
  newCapacity = Integer.highestOneBit(minCapacity - 1) << 1;
 }
 if (newCapacity < 0) {
  newCapacity = Integer.MAX_VALUE; // guaranteed to be >= newCapacity
 }
 return newCapacity;
}
origin: google/guava

private static int expandedCapacity(int oldCapacity, int minCapacity) {
 if (minCapacity < 0) {
  throw new AssertionError("cannot store more than MAX_VALUE elements");
 }
 // careful of overflow!
 int newCapacity = oldCapacity + (oldCapacity >> 1) + 1;
 if (newCapacity < minCapacity) {
  newCapacity = Integer.highestOneBit(minCapacity - 1) << 1;
 }
 if (newCapacity < 0) {
  newCapacity = Integer.MAX_VALUE; // guaranteed to be >= newCapacity
 }
 return newCapacity;
}
origin: google/guava

private static int expandedCapacity(int oldCapacity, int minCapacity) {
 if (minCapacity < 0) {
  throw new AssertionError("cannot store more than MAX_VALUE elements");
 }
 // careful of overflow!
 int newCapacity = oldCapacity + (oldCapacity >> 1) + 1;
 if (newCapacity < minCapacity) {
  newCapacity = Integer.highestOneBit(minCapacity - 1) << 1;
 }
 if (newCapacity < 0) {
  newCapacity = Integer.MAX_VALUE; // guaranteed to be >= newCapacity
 }
 return newCapacity;
}
origin: google/guava

static int expandedCapacity(int oldCapacity, int minCapacity) {
 if (minCapacity < 0) {
  throw new AssertionError("cannot store more than MAX_VALUE elements");
 }
 // careful of overflow!
 int newCapacity = oldCapacity + (oldCapacity >> 1) + 1;
 if (newCapacity < minCapacity) {
  newCapacity = Integer.highestOneBit(minCapacity - 1) << 1;
 }
 if (newCapacity < 0) {
  newCapacity = Integer.MAX_VALUE;
  // guaranteed to be >= newCapacity
 }
 return newCapacity;
}
origin: bumptech/glide

@Override
public float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth,
  int requestedHeight) {
 int minIntegerFactor = Math.min(sourceHeight / requestedHeight, sourceWidth / requestedWidth);
 return minIntegerFactor == 0 ? 1f : 1f / Integer.highestOneBit(minIntegerFactor);
}
origin: google/guava

/**
 * Returns an array size suitable for the backing array of a hash table that uses open addressing
 * with linear probing in its implementation. The returned size is the smallest power of two that
 * can hold setSize elements with the desired load factor.
 */
@VisibleForTesting
static int chooseTableSize(int setSize) {
 if (setSize == 1) {
  return 2;
 }
 // Correct the size for open addressing to match desired load factor.
 // Round up to the next highest power of 2.
 int tableSize = Integer.highestOneBit(setSize - 1) << 1;
 while (tableSize * DESIRED_LOAD_FACTOR < setSize) {
  tableSize <<= 1;
 }
 return tableSize;
}
origin: prestodb/presto

static int closedTableSize(int expectedEntries, double loadFactor) {
 // Get the recommended table size.
 // Round down to the nearest power of 2.
 expectedEntries = Math.max(expectedEntries, 2);
 int tableSize = Integer.highestOneBit(expectedEntries);
 // Check to make sure that we will not exceed the maximum load factor.
 if (expectedEntries > (int) (loadFactor * tableSize)) {
  tableSize <<= 1;
  return (tableSize > 0) ? tableSize : MAX_TABLE_SIZE;
 }
 return tableSize;
}
origin: bumptech/glide

@Override
public float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth,
  int requestedHeight) {
 int maxIntegerFactor = (int) Math.ceil(Math.max(sourceHeight / (float) requestedHeight,
     sourceWidth / (float) requestedWidth));
 int lesserOrEqualSampleSize = Math.max(1, Integer.highestOneBit(maxIntegerFactor));
 int greaterOrEqualSampleSize =
   lesserOrEqualSampleSize << (lesserOrEqualSampleSize < maxIntegerFactor ? 1 : 0);
 return 1f / greaterOrEqualSampleSize;
}
origin: google/guava

/**
 * Returns the largest power of two less than or equal to {@code x}. This is equivalent to {@code
 * checkedPow(2, log2(x, FLOOR))}.
 *
 * @throws IllegalArgumentException if {@code x <= 0}
 * @since 20.0
 */
@Beta
public static int floorPowerOfTwo(int x) {
 checkPositive("x", x);
 return Integer.highestOneBit(x);
}
origin: google/guava

/**
 * Returns an array size suitable for the backing array of a hash table that uses open addressing
 * with linear probing in its implementation. The returned size is the smallest power of two that
 * can hold setSize elements with the desired load factor. Always returns at least setSize + 2.
 */
@VisibleForTesting
static int chooseTableSize(int setSize) {
 setSize = Math.max(setSize, 2);
 // Correct the size for open addressing to match desired load factor.
 if (setSize < CUTOFF) {
  // Round up to the next highest power of 2.
  int tableSize = Integer.highestOneBit(setSize - 1) << 1;
  while (tableSize * DESIRED_LOAD_FACTOR < setSize) {
   tableSize <<= 1;
  }
  return tableSize;
 }
 // The table can't be completely full or we'll get infinite reprobes
 checkArgument(setSize < MAX_TABLE_SIZE, "collection too large");
 return MAX_TABLE_SIZE;
}
origin: redisson/redisson

public FSTIdentity2IdMap(int initialSize) {
  if (initialSize < 2) {
    initialSize = 2;
  }
  initialSize = adjustSize(initialSize * GROFAC);
  mKeys = new Object[initialSize];
  mValues = new int[initialSize];
  mNumberOfElements = 0;
  mask = (Integer.highestOneBit(initialSize) << 1) - 1;
  klen = initialSize - 4;
}
origin: apache/incubator-druid

public static int maxIntsInBufferForBytes(int numBytes)
{
 int maxSizePer = (CompressedPools.BUFFER_SIZE - bufferPadding(numBytes)) / numBytes;
 // round down to the nearest power of 2
 return Integer.highestOneBit(maxSizePer);
}
origin: google/guava

/**
 * Ensures that this {@code CompactHashMap} has the smallest representation in memory, given its
 * current size.
 */
public void trimToSize() {
 int size = this.size;
 if (size < entries.length) {
  resizeEntries(size);
 }
 // size / loadFactor gives the table size of the appropriate load factor,
 // but that may not be a power of two. We floor it to a power of two by
 // keeping its highest bit. But the smaller table may have a load factor
 // larger than what we want; then we want to go to the next power of 2 if we can
 int minimumTableSize = Math.max(1, Integer.highestOneBit((int) (size / loadFactor)));
 if (minimumTableSize < MAXIMUM_CAPACITY) {
  double load = (double) size / minimumTableSize;
  if (load > loadFactor) {
   minimumTableSize <<= 1; // increase to next power if possible
  }
 }
 if (minimumTableSize < table.length) {
  resizeTable(minimumTableSize);
 }
}
origin: google/guava

/**
 * Ensures that this {@code CompactHashSet} has the smallest representation in memory, given its
 * current size.
 */
public void trimToSize() {
 int size = this.size;
 if (size < entries.length) {
  resizeEntries(size);
 }
 // size / loadFactor gives the table size of the appropriate load factor,
 // but that may not be a power of two. We floor it to a power of two by
 // keeping its highest bit. But the smaller table may have a load factor
 // larger than what we want; then we want to go to the next power of 2 if we can
 int minimumTableSize = Math.max(1, Integer.highestOneBit((int) (size / loadFactor)));
 if (minimumTableSize < MAXIMUM_CAPACITY) {
  double load = (double) size / minimumTableSize;
  if (load > loadFactor) {
   minimumTableSize <<= 1; // increase to next power if possible
  }
 }
 if (minimumTableSize < table.length) {
  resizeTable(minimumTableSize);
 }
}
origin: prestodb/presto

/**
 * Returns the largest power of two less than or equal to {@code x}. This is equivalent to {@code
 * checkedPow(2, log2(x, FLOOR))}.
 *
 * @throws IllegalArgumentException if {@code x <= 0}
 * @since 20.0
 */
@Beta
public static int floorPowerOfTwo(int x) {
 checkPositive("x", x);
 return Integer.highestOneBit(x);
}
origin: bumptech/glide

private static int getSampleSize(GifHeader gifHeader, int targetWidth, int targetHeight) {
 int exactSampleSize = Math.min(gifHeader.getHeight() / targetHeight,
   gifHeader.getWidth() / targetWidth);
 int powerOfTwoSampleSize = exactSampleSize == 0 ? 0 : Integer.highestOneBit(exactSampleSize);
 // Although functionally equivalent to 0 for BitmapFactory, 1 is a safer default for our code
 // than 0.
 int sampleSize = Math.max(1, powerOfTwoSampleSize);
 if (Log.isLoggable(TAG, Log.VERBOSE) && sampleSize > 1) {
  Log.v(TAG, "Downsampling GIF"
    + ", sampleSize: " + sampleSize
    + ", target dimens: [" + targetWidth + "x" + targetHeight + "]"
    + ", actual dimens: [" + gifHeader.getWidth() + "x" + gifHeader.getHeight() + "]");
 }
 return sampleSize;
}
java.langIntegerhighestOneBit

Javadoc

Determines the highest (leftmost) bit of the specified integer that is 1 and returns the bit mask value for that bit. This is also referred to as the Most Significant 1 Bit. Returns zero if the specified integer is zero.

Popular methods of Integer

  • parseInt
    Parses the specified string as a signed integer value using the specified radix. The ASCII character
  • toString
    Converts the specified signed integer into a string representation based on the specified radix. The
  • valueOf
    Parses the specified string as a signed integer value using the specified radix.
  • intValue
    Gets the primitive value of this int.
  • <init>
    Constructs a new Integer from the specified string.
  • toHexString
    Returns a string representation of the integer argument as an unsigned integer in base 16.The unsign
  • equals
    Compares this instance with the specified object and indicates if they are equal. In order to be equ
  • compareTo
    Compares this Integer object to another object. If the object is an Integer, this function behaves l
  • hashCode
  • compare
    Compares two int values.
  • longValue
    Returns the value of this Integer as along.
  • decode
    Parses the specified string and returns a Integer instance if the string can be decoded into an inte
  • longValue,
  • decode,
  • numberOfLeadingZeros,
  • getInteger,
  • doubleValue,
  • toBinaryString,
  • byteValue,
  • bitCount,
  • shortValue

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • requestLocationUpdates (LocationManager)
  • addToBackStack (FragmentTransaction)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Reference (javax.naming)
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now