Class ArrayUtil

java.lang.Object
io.github.jbellis.jvector.util.ArrayUtil

public final class ArrayUtil extends Object
Methods for manipulating arrays.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    copyOfSubArray(byte[] array, int from, int to)
    Copies the specified range of the given array into a new sub array.
    static float[]
    copyOfSubArray(float[] array, int from, int to)
    Copies the specified range of the given array into a new sub array.
    static int[]
    copyOfSubArray(int[] array, int from, int to)
    Copies the specified range of the given array into a new sub array.
    static long[]
    copyOfSubArray(long[] array, int from, int to)
    Copies the specified range of the given array into a new sub array.
    static <T> T[]
    copyOfSubArray(T[] array, int from, int to)
    Copies the specified range of the given array into a new sub array.
    static byte[]
    grow(byte[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static char[]
    grow(char[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static double[]
    grow(double[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static float[]
    grow(float[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static int[]
    grow(int[] array)
    Returns a larger array, generally over-allocating exponentially
    static int[]
    grow(int[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static long[]
    grow(long[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static short[]
    grow(short[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static <T> T[]
    grow(T[] array, int minSize)
    Returns an array whose size is at least minSize, generally over-allocating exponentially
    static byte[]
    growExact(byte[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static char[]
    growExact(char[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static double[]
    growExact(double[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static float[]
    growExact(float[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static int[]
    growExact(int[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static long[]
    growExact(long[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static short[]
    growExact(short[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static <T> T[]
    growExact(T[] array, int newLength)
    Returns a new array whose size is exact the specified newLength without over-allocating
    static int
    oversize(int minTargetSize, int bytesPerElement)
    Returns an array size >= minTargetSize, generally over-allocating exponentially to achieve amortized linear-time cost as the array grows.
    static int
    parseInt(char[] chars, int offset, int len, int radix)
    Parses the string argument as if it was an int value and returns the result.

    Methods inherited from class java.lang.Object

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

    • MAX_ARRAY_LENGTH

      public static final int MAX_ARRAY_LENGTH
  • Method Details

    • parseInt

      public static int parseInt(char[] chars, int offset, int len, int radix) throws NumberFormatException
      Parses the string argument as if it was an int value and returns the result. Throws NumberFormatException if the string does not represent an int quantity. The second argument specifies the radix to use when parsing the value.
      Parameters:
      chars - a string representation of an int quantity.
      radix - the base to use for conversion.
      Returns:
      int the value represented by the argument
      Throws:
      NumberFormatException - if the argument could not be parsed as an int quantity.
    • oversize

      public static int oversize(int minTargetSize, int bytesPerElement)
      Returns an array size >= minTargetSize, generally over-allocating exponentially to achieve amortized linear-time cost as the array grows.

      NOTE: this was originally borrowed from Python 2.4.2 listobject.c sources (attribution in LICENSE.txt), but has now been substantially changed based on discussions from java-dev thread with subject "Dynamic array reallocation algorithms", started on Jan 12 2010.

      Parameters:
      minTargetSize - Minimum required value to be returned.
      bytesPerElement - Bytes used by each element of the array. See constants in RamUsageEstimator.
    • growExact

      public static <T> T[] growExact(T[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static <T> T[] grow(T[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • growExact

      public static short[] growExact(short[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static short[] grow(short[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • growExact

      public static float[] growExact(float[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static float[] grow(float[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • growExact

      public static double[] growExact(double[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static double[] grow(double[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • growExact

      public static int[] growExact(int[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static int[] grow(int[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • grow

      public static int[] grow(int[] array)
      Returns a larger array, generally over-allocating exponentially
    • growExact

      public static long[] growExact(long[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static long[] grow(long[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • growExact

      public static byte[] growExact(byte[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static byte[] grow(byte[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • growExact

      public static char[] growExact(char[] array, int newLength)
      Returns a new array whose size is exact the specified newLength without over-allocating
    • grow

      public static char[] grow(char[] array, int minSize)
      Returns an array whose size is at least minSize, generally over-allocating exponentially
    • copyOfSubArray

      public static byte[] copyOfSubArray(byte[] array, int from, int to)
      Copies the specified range of the given array into a new sub array.
      Parameters:
      array - the input array
      from - the initial index of range to be copied (inclusive)
      to - the final index of range to be copied (exclusive)
    • copyOfSubArray

      public static int[] copyOfSubArray(int[] array, int from, int to)
      Copies the specified range of the given array into a new sub array.
      Parameters:
      array - the input array
      from - the initial index of range to be copied (inclusive)
      to - the final index of range to be copied (exclusive)
    • copyOfSubArray

      public static float[] copyOfSubArray(float[] array, int from, int to)
      Copies the specified range of the given array into a new sub array.
      Parameters:
      array - the input array
      from - the initial index of range to be copied (inclusive)
      to - the final index of range to be copied (exclusive)
    • copyOfSubArray

      public static <T> T[] copyOfSubArray(T[] array, int from, int to)
      Copies the specified range of the given array into a new sub array.
      Parameters:
      array - the input array
      from - the initial index of range to be copied (inclusive)
      to - the final index of range to be copied (exclusive)
    • copyOfSubArray

      public static long[] copyOfSubArray(long[] array, int from, int to)
      Copies the specified range of the given array into a new sub array.
      Parameters:
      array - the input array
      from - the initial index of range to be copied (inclusive)
      to - the final index of range to be copied (exclusive)