Package org.ddogleg.util
Class PrimitiveArrays
java.lang.Object
org.ddogleg.util.PrimitiveArrays
Various functions for manipulating primitive arrays
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublefeedbackIdxDOp(byte[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static doublefeedbackIdxDOp(double[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static doublefeedbackIdxDOp(float[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static doublefeedbackIdxDOp(int[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static doublefeedbackIdxDOp(long[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static doublefeedbackIdxDOp(short[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static int[]fillCounting(int length) static voidfillCounting(int[] array, int offset, int length) Sets each element within range to a number counting upstatic voidintersection(int[] setA, int sizeA, int[] setB, int sizeB, int valueMin, int valueMax, DogArray_I32 results, @Nullable DogArray_I8 work) Finds the intersection of two sets.static voidintersection(int[] setA, int sizeA, int[] setB, int sizeB, DogArray_I32 results, @Nullable DogArray_I8 work) Finds the itersection of two sets.static intlowerBound(byte[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic intlowerBound(double[] array, int offset, int length, double val) Finds the first index in 'array' for which val is not ≤ valstatic intlowerBound(float[] array, int offset, int length, float val) Finds the first index in 'array' for which val is not ≤ valstatic intlowerBound(int[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic intlowerBound(short[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic intlowerBoundU(byte[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic intmax(byte[] array, int offset, int length) Returns the value of the element with the maximum valuestatic doublemax(double[] array, int offset, int length) Returns the value of the element with the maximum valuestatic floatmax(float[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmax(int[] array, int offset, int length) Returns the value of the element with the maximum valuestatic longmax(long[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmax(short[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmaxIdx(byte[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmaxIdx(double[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmaxIdx(float[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmaxIdx(int[] array, int offset, int length) Returns the value of the element with the maximum valuestatic intmin(byte[] array, int offset, int length) Returns the value of the element with the minimum valuestatic doublemin(double[] array, int offset, int length) Returns the value of the element with the minimum valuestatic floatmin(float[] array, int offset, int length) Returns the value of the element with the minimum valuestatic intmin(int[] array, int offset, int length) Returns the value of the element with the minimum valuestatic longmin(long[] array, int offset, int length) Returns the value of the element with the minimum valuestatic intmin(short[] array, int offset, int length) Returns the value of the element with the minimum valuestatic intminIdx(byte[] array, int offset, int length) Returns the index of the element with the minimum valuestatic intminIdx(double[] array, int offset, int length) Returns the index of the element with the minimum valuestatic intminIdx(float[] array, int offset, int length) Returns the index of the element with the minimum valuestatic intminIdx(int[] array, int offset, int length) Returns the index of the element with the minimum valuestatic voidRandomly shuffle the arraystatic voidRandomly shuffle the arraystatic voidRandomly shuffle the arraystatic voidRandomly shuffle the arraystatic voidRandomly shuffle the arraystatic voidRandomly shuffle the arraystatic doublesumD(byte[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic doublesumD(double[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic doublesumD(float[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic doublesumD(int[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic doublesumD(long[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic doublesumD(short[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic voidunion(int[] setA, int sizeA, int[] setB, int sizeB, int valueMin, int valueMax, DogArray_I32 results, @Nullable DogArray_I8 work) Finds the intersection of two sets.
-
Constructor Details
-
PrimitiveArrays
public PrimitiveArrays()
-
-
Method Details
-
intersection
public static void intersection(int[] setA, int sizeA, int[] setB, int sizeB, DogArray_I32 results, @Nullable @Nullable DogArray_I8 work) Finds the itersection of two sets. Uses a algorithm that requires linear time and memory. Manually determines the min and max values contained in both sets.- Parameters:
setA- Set A of integers. Unsorted.sizeA- Number of elements in set AsetB- Set B of integers. Unsorted.sizeB- Number of elements in set Bwork- Work spaceresults- Output set that is the intersection. Sorted from least to greatest
-
intersection
public static void intersection(int[] setA, int sizeA, int[] setB, int sizeB, int valueMin, int valueMax, DogArray_I32 results, @Nullable @Nullable DogArray_I8 work) Finds the intersection of two sets. Uses a algorithm that requires linear time and memory.- Parameters:
setA- Set A of integers. Unsorted.sizeA- Number of elements in set AsetB- Set B of integers. Unsorted.sizeB- Number of elements in set BvalueMin- Minimum value in either setvalueMax- Maximum value in either setwork- Work spaceresults- Output set that is the intersection. Sorted from least to greatest
-
union
public static void union(int[] setA, int sizeA, int[] setB, int sizeB, int valueMin, int valueMax, DogArray_I32 results, @Nullable @Nullable DogArray_I8 work) Finds the intersection of two sets. Uses a algorithm that requires linear time and memory.- Parameters:
setA- Set A of integers. Unsorted.sizeA- Number of elements in set AsetB- Set B of integers. Unsorted.sizeB- Number of elements in set BvalueMin- Minimum value in either setvalueMax- Maximum value in either setwork- Work spaceresults- Output set that is the intersection. Sorted from least to greatest
-
fillCounting
public static void fillCounting(int[] array, int offset, int length) Sets each element within range to a number counting up -
fillCounting
public static int[] fillCounting(int length) -
shuffle
Randomly shuffle the array -
shuffle
Randomly shuffle the array -
shuffle
Randomly shuffle the array -
shuffle
Randomly shuffle the array -
shuffle
Randomly shuffle the array -
shuffle
Randomly shuffle the array -
min
public static int min(byte[] array, int offset, int length) Returns the value of the element with the minimum value -
min
public static int min(short[] array, int offset, int length) Returns the value of the element with the minimum value -
min
public static int min(int[] array, int offset, int length) Returns the value of the element with the minimum value -
min
public static long min(long[] array, int offset, int length) Returns the value of the element with the minimum value -
min
public static float min(float[] array, int offset, int length) Returns the value of the element with the minimum value -
min
public static double min(double[] array, int offset, int length) Returns the value of the element with the minimum value -
minIdx
public static int minIdx(byte[] array, int offset, int length) Returns the index of the element with the minimum value -
minIdx
public static int minIdx(int[] array, int offset, int length) Returns the index of the element with the minimum value -
minIdx
public static int minIdx(float[] array, int offset, int length) Returns the index of the element with the minimum value -
minIdx
public static int minIdx(double[] array, int offset, int length) Returns the index of the element with the minimum value -
max
public static int max(byte[] array, int offset, int length) Returns the value of the element with the maximum value -
max
public static int max(short[] array, int offset, int length) Returns the value of the element with the maximum value -
max
public static int max(int[] array, int offset, int length) Returns the value of the element with the maximum value -
max
public static long max(long[] array, int offset, int length) Returns the value of the element with the maximum value -
max
public static float max(float[] array, int offset, int length) Returns the value of the element with the maximum value -
max
public static double max(double[] array, int offset, int length) Returns the value of the element with the maximum value -
maxIdx
public static int maxIdx(byte[] array, int offset, int length) Returns the value of the element with the maximum value -
maxIdx
public static int maxIdx(int[] array, int offset, int length) Returns the value of the element with the maximum value -
maxIdx
public static int maxIdx(float[] array, int offset, int length) Returns the value of the element with the maximum value -
maxIdx
public static int maxIdx(double[] array, int offset, int length) Returns the value of the element with the maximum value -
lowerBound
public static int lowerBound(byte[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ val- Parameters:
offset- First index in the arraylength- Number of elements in the arrayval- The value for which the lower bound is being searched for.- Returns:
- lower bound index
-
lowerBoundU
public static int lowerBoundU(byte[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ val- Parameters:
array- unsigned byte arrayoffset- First index in the arraylength- Number of elements in the arrayval- The value for which the lower bound is being searched for.- Returns:
- lower bound index
-
lowerBound
public static int lowerBound(short[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ val- Parameters:
offset- First index in the arraylength- Number of elements in the arrayval- The value for which the lower bound is being searched for.- Returns:
- lower bound index
-
lowerBound
public static int lowerBound(int[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ val- Parameters:
offset- First index in the arraylength- Number of elements in the arrayval- The value for which the lower bound is being searched for.- Returns:
- lower bound index
-
lowerBound
public static int lowerBound(float[] array, int offset, int length, float val) Finds the first index in 'array' for which val is not ≤ val- Parameters:
offset- First index in the arraylength- Number of elements in the arrayval- The value for which the lower bound is being searched for.- Returns:
- lower bound index
-
lowerBound
public static int lowerBound(double[] array, int offset, int length, double val) Finds the first index in 'array' for which val is not ≤ val- Parameters:
offset- First index in the arraylength- Number of elements in the arrayval- The value for which the lower bound is being searched for.- Returns:
- lower bound index
-
sumD
public static double sumD(byte[] array, int offset, int length) Computes the sum of the array and stores the result in a double -
sumD
public static double sumD(short[] array, int offset, int length) Computes the sum of the array and stores the result in a double -
sumD
public static double sumD(int[] array, int offset, int length) Computes the sum of the array and stores the result in a double -
sumD
public static double sumD(long[] array, int offset, int length) Computes the sum of the array and stores the result in a double -
sumD
public static double sumD(float[] array, int offset, int length) Computes the sum of the array and stores the result in a double -
sumD
public static double sumD(double[] array, int offset, int length) Computes the sum of the array and stores the result in a double -
feedbackIdxDOp
public static double feedbackIdxDOp(byte[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array. Previous results are feedback into the current value being considered. -
feedbackIdxDOp
public static double feedbackIdxDOp(short[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array. Previous results are feedback into the current value being considered. -
feedbackIdxDOp
public static double feedbackIdxDOp(int[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array. Previous results are feedback into the current value being considered. -
feedbackIdxDOp
public static double feedbackIdxDOp(long[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array. Previous results are feedback into the current value being considered. -
feedbackIdxDOp
public static double feedbackIdxDOp(float[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array. Previous results are feedback into the current value being considered. -
feedbackIdxDOp
public static double feedbackIdxDOp(double[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array. Previous results are feedback into the current value being considered.
-