Package io.github.jbellis.jvector.util
Class ArrayUtil
java.lang.Object
io.github.jbellis.jvector.util.ArrayUtil
Methods for manipulating arrays.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 leastminSize, generally over-allocating exponentiallystatic char[]grow(char[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic double[]grow(double[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic float[]grow(float[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic int[]grow(int[] array) Returns a larger array, generally over-allocating exponentiallystatic int[]grow(int[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic long[]grow(long[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic short[]grow(short[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic <T> T[]grow(T[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentiallystatic byte[]growExact(byte[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic char[]growExact(char[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic double[]growExact(double[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic float[]growExact(float[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic int[]growExact(int[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic long[]growExact(long[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic short[]growExact(short[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic <T> T[]growExact(T[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocatingstatic intoversize(int minTargetSize, int bytesPerElement) Returns an array size >= minTargetSize, generally over-allocating exponentially to achieve amortized linear-time cost as the array grows.static intparseInt(char[] chars, int offset, int len, int radix) Parses the string argument as if it was an int value and returns the result.
-
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 inRamUsageEstimator.
-
growExact
public static <T> T[] growExact(T[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static <T> T[] grow(T[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentially -
growExact
public static short[] growExact(short[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static short[] grow(short[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentially -
growExact
public static float[] growExact(float[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static float[] grow(float[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentially -
growExact
public static double[] growExact(double[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static double[] grow(double[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentially -
growExact
public static int[] growExact(int[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static int[] grow(int[] array, int minSize) Returns an array whose size is at leastminSize, 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 specifiednewLengthwithout over-allocating -
grow
public static long[] grow(long[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentially -
growExact
public static byte[] growExact(byte[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static byte[] grow(byte[] array, int minSize) Returns an array whose size is at leastminSize, generally over-allocating exponentially -
growExact
public static char[] growExact(char[] array, int newLength) Returns a new array whose size is exact the specifiednewLengthwithout over-allocating -
grow
public static char[] grow(char[] array, int minSize) Returns an array whose size is at leastminSize, 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 arrayfrom- 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 arrayfrom- 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 arrayfrom- 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 arrayfrom- 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 arrayfrom- the initial index of range to be copied (inclusive)to- the final index of range to be copied (exclusive)
-