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

How to use
numberOfLeadingZeros
method
in
java.lang.Integer

Best Java code snippets using java.lang.Integer.numberOfLeadingZeros (Showing top 20 results out of 4,212)

origin: ReactiveX/RxJava

/**
 * Find the next larger positive power of two value up from the given value. If value is a power of two then
 * this value will be returned.
 *
 * @param value from which next positive power of two will be found.
 * @return the next positive power of 2 or this value if it is a power of 2.
 */
public static int roundToPowerOfTwo(final int value) {
  return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
origin: netty/netty

private static int log2(int val) {
  // compute the (0-based, with lsb = 0) position of highest set bit i.e, log2
  return INTEGER_SIZE_MINUS_ONE - Integer.numberOfLeadingZeros(val);
}
origin: netty/netty

/**
 * Fast method of finding the next power of 2 greater than or equal to the supplied value.
 *
 * <p>If the value is {@code <= 0} then 1 will be returned.
 * This method is not suitable for {@link Integer#MIN_VALUE} or numbers greater than 2^30.
 *
 * @param value from which to search for next power of 2
 * @return The next power of 2 or the value itself if it is a power of 2
 */
public static int findNextPositivePowerOfTwo(final int value) {
  assert value > Integer.MIN_VALUE && value < 0x40000000;
  return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
origin: LMAX-Exchange/disruptor

/**
 * Calculate the next power of 2, greater than or equal to x.<p>
 * From Hacker's Delight, Chapter 3, Harry S. Warren Jr.
 *
 * @param x Value to round up
 * @return The next power of 2 from x inclusive
 */
public static int ceilingNextPowerOfTwo(final int x)
{
  return 1 << (32 - Integer.numberOfLeadingZeros(x - 1));
}
origin: prestodb/presto

private static int encodedLengthSize(int length)
{
  if (length < 128) {
    return 1;
  }
  int numberOfBits = 32 - Integer.numberOfLeadingZeros(length);
  int numberOfBytes = (numberOfBits + 7) / 8;
  return numberOfBytes + 1;
}
origin: redisson/redisson

/**
 * Find the next larger positive power of two value up from the given value. If value is a power of two then
 * this value will be returned.
 *
 * @param value from which next positive power of two will be found.
 * @return the next positive power of 2 or this value if it is a power of 2.
 */
public static int roundToPowerOfTwo(final int value) {
  return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
origin: apache/flink

public static int getBitSize(long value) {
  if (value > Integer.MAX_VALUE) {
    return 64 - Integer.numberOfLeadingZeros((int) (value >> 32));
  } else {
    return 32 - Integer.numberOfLeadingZeros((int) value);
  }
}
origin: redisson/redisson

int computeListIndex( int len ) {
  int powIndex = 32-Integer.numberOfLeadingZeros(len-1);
  return powIndex;
}
origin: redisson/redisson

/**
 * Fast method of finding the next power of 2 greater than or equal to the supplied value.
 *
 * <p>If the value is {@code <= 0} then 1 will be returned.
 * This method is not suitable for {@link Integer#MIN_VALUE} or numbers greater than 2^30.
 *
 * @param value from which to search for next power of 2
 * @return The next power of 2 or the value itself if it is a power of 2
 */
public static int findNextPositivePowerOfTwo(final int value) {
  assert value > Integer.MIN_VALUE && value < 0x40000000;
  return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
origin: redisson/redisson

private static int log2(int val) {
  // compute the (0-based, with lsb = 0) position of highest set bit i.e, log2
  return INTEGER_SIZE_MINUS_ONE - Integer.numberOfLeadingZeros(val);
}
origin: redisson/redisson

int computeLen( int len ) {
  int powIndex = 32-Integer.numberOfLeadingZeros(len-1);
  return 1<<powIndex;
}
origin: netty/netty

private static int validateAndCalculatePageShifts(int pageSize) {
  if (pageSize < MIN_PAGE_SIZE) {
    throw new IllegalArgumentException("pageSize: " + pageSize + " (expected: " + MIN_PAGE_SIZE + ")");
  }
  if ((pageSize & pageSize - 1) != 0) {
    throw new IllegalArgumentException("pageSize: " + pageSize + " (expected: power of 2)");
  }
  // Logarithm base 2. At this point we know that pageSize is a power of two.
  return Integer.SIZE - 1 - Integer.numberOfLeadingZeros(pageSize);
}
origin: netty/netty

/**
 * Calculates compression level on the basis of block size.
 */
private static int compressionLevel(int blockSize) {
  if (blockSize < MIN_BLOCK_SIZE || blockSize > MAX_BLOCK_SIZE) {
    throw new IllegalArgumentException(String.format(
        "blockSize: %d (expected: %d-%d)", blockSize, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE));
  }
  int compressionLevel = 32 - Integer.numberOfLeadingZeros(blockSize - 1); // ceil of log2
  compressionLevel = Math.max(0, compressionLevel - COMPRESSION_LEVEL_BASE);
  return compressionLevel;
}
origin: redisson/redisson

private static int validateAndCalculatePageShifts(int pageSize) {
  if (pageSize < MIN_PAGE_SIZE) {
    throw new IllegalArgumentException("pageSize: " + pageSize + " (expected: " + MIN_PAGE_SIZE + ")");
  }
  if ((pageSize & pageSize - 1) != 0) {
    throw new IllegalArgumentException("pageSize: " + pageSize + " (expected: power of 2)");
  }
  // Logarithm base 2. At this point we know that pageSize is a power of two.
  return Integer.SIZE - 1 - Integer.numberOfLeadingZeros(pageSize);
}
origin: redisson/redisson

/**
 * Calculates compression level on the basis of block size.
 */
private static int compressionLevel(int blockSize) {
  if (blockSize < MIN_BLOCK_SIZE || blockSize > MAX_BLOCK_SIZE) {
    throw new IllegalArgumentException(String.format(
        "blockSize: %d (expected: %d-%d)", blockSize, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE));
  }
  int compressionLevel = 32 - Integer.numberOfLeadingZeros(blockSize - 1); // ceil of log2
  compressionLevel = Math.max(0, compressionLevel - COMPRESSION_LEVEL_BASE);
  return compressionLevel;
}
origin: google/guava

private static int log10Floor(int x) {
 /*
  * Based on Hacker's Delight Fig. 11-5, the two-table-lookup, branch-free implementation.
  *
  * The key idea is that based on the number of leading zeros (equivalently, floor(log2(x))), we
  * can narrow the possible floor(log10(x)) values to two. For example, if floor(log2(x)) is 6,
  * then 64 <= x < 128, so floor(log10(x)) is either 1 or 2.
  */
 int y = maxLog10ForLeadingZeros[Integer.numberOfLeadingZeros(x)];
 /*
  * y is the higher of the two possible values of floor(log10(x)). If x < 10^y, then we want the
  * lower of the two possible values, or y - 1, otherwise, we want y.
  */
 return y - lessThanBranchFree(x, powersOf10[y]);
}
origin: google/guava

/**
 * Returns the smallest power of two greater than or equal to {@code x}. This is equivalent to
 * {@code checkedPow(2, log2(x, CEILING))}.
 *
 * @throws IllegalArgumentException if {@code x <= 0}
 * @throws ArithmeticException of the next-higher power of two is not representable as an {@code
 *     int}, i.e. when {@code x > 2^30}
 * @since 20.0
 */
@Beta
public static int ceilingPowerOfTwo(int x) {
 checkPositive("x", x);
 if (x > MAX_SIGNED_POWER_OF_TWO) {
  throw new ArithmeticException("ceilingPowerOfTwo(" + x + ") not representable as an int");
 }
 return 1 << -Integer.numberOfLeadingZeros(x - 1);
}
origin: neo4j/neo4j

public NodeLabelsCache( NumberArrayFactory cacheFactory, int highLabelId, int chunkSize )
{
  this.cache = cacheFactory.newDynamicLongArray( chunkSize, 0 );
  this.spillOver = cacheFactory.newDynamicLongArray( chunkSize / 5, 0 ); // expect way less of these
  this.bitsPerLabel = max( Integer.SIZE - numberOfLeadingZeros( highLabelId ), 1 );
  this.worstCaseLongsNeeded = ((bitsPerLabel * (highLabelId + 1 /*length slot*/)) - 1) / Long.SIZE + 1;
  this.putClient = new Client( worstCaseLongsNeeded );
}
origin: libgdx/libgdx

@Override
public Mesh obtain (VertexAttributes vertexAttributes, int vertexCount, int indexCount) {
  for (int i = 0, n = freeMeshes.size; i < n; ++i) {
    final Mesh mesh = freeMeshes.get(i);
    if (mesh.getVertexAttributes().equals(vertexAttributes) && mesh.getMaxVertices() >= vertexCount
      && mesh.getMaxIndices() >= indexCount) {
      freeMeshes.removeIndex(i);
      usedMeshes.add(mesh);
      return mesh;
    }
  }
  vertexCount = 1 + (int)Short.MAX_VALUE;
  indexCount = Math.max(1 + (int)Short.MAX_VALUE, 1 << (32 - Integer.numberOfLeadingZeros(indexCount - 1)));
  Mesh result = new Mesh(false, vertexCount, indexCount, vertexAttributes);
  usedMeshes.add(result);
  return result;
}
origin: libgdx/libgdx

@Override
public Mesh obtain (VertexAttributes vertexAttributes, int vertexCount, int indexCount) {
  for (int i = 0, n = freeMeshes.size; i < n; ++i) {
    final Mesh mesh = freeMeshes.get(i);
    if (mesh.getVertexAttributes().equals(vertexAttributes) && mesh.getMaxVertices() >= vertexCount
      && mesh.getMaxIndices() >= indexCount) {
      freeMeshes.removeIndex(i);
      usedMeshes.add(mesh);
      return mesh;
    }
  }
  vertexCount = 1 + (int)Short.MAX_VALUE;
  indexCount = Math.max(1 + (int)Short.MAX_VALUE, 1 << (32 - Integer.numberOfLeadingZeros(indexCount - 1)));
  Mesh result = new Mesh(false, vertexCount, indexCount, vertexAttributes);
  usedMeshes.add(result);
  return result;
}
java.langIntegernumberOfLeadingZeros

Javadoc

Determines the number of leading zeros in the specified integer prior to the #highestOneBit(int).

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,
  • getInteger,
  • doubleValue,
  • toBinaryString,
  • byteValue,
  • bitCount,
  • shortValue,
  • highestOneBit

Popular in Java

  • Start an intent from android
  • findViewById (Activity)
  • setContentView (Activity)
  • setScale (BigDecimal)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top 12 Jupyter Notebook extensions
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