Class HeapUtil


  • public final class HeapUtil
    extends java.lang.Object
    Next power of 2, for heaps.

    Usually, you should prefer the version in the MathUtil class. This copy exists to avoid depending onto math from these data structures.

    Since:
    0.7.5
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int MAX_ARRAY_SIZE
      Maximum Java array size according to some sources.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private HeapUtil()
      Private constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int nextPow2Int​(int x)
      Find the next power of 2.
      static int nextSize​(int current)
      Next size if a heap exceeds the current capacity.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_ARRAY_SIZE

        private static final int MAX_ARRAY_SIZE
        Maximum Java array size according to some sources.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HeapUtil

        private HeapUtil()
        Private constructor. Static methods only.
    • Method Detail

      • nextPow2Int

        public static int nextPow2Int​(int x)
        Find the next power of 2.

        Classic bit operation, for signed 32-bit. Valid for positive integers only (0 otherwise).

        Parameters:
        x - original integer
        Returns:
        Next power of 2
      • nextSize

        public static int nextSize​(int current)
        Next size if a heap exceeds the current capacity.
        Parameters:
        current - Current capacity
        Returns:
        next heap size