Package org.ddogleg.util
Class PrimitiveArrays
java.lang.Object
org.ddogleg.util.PrimitiveArrays
Various functions for manipulating primitive arrays
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
feedbackIdxDOp
(byte[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static double
feedbackIdxDOp
(double[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static double
feedbackIdxDOp
(float[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static double
feedbackIdxDOp
(int[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static double
feedbackIdxDOp
(long[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static double
feedbackIdxDOp
(short[] array, int offset, int length, PrimitiveArrays.FeedbackIdxD op) Recursively computes a result from an array.static int[]
fillCounting
(int length) static void
fillCounting
(int[] array, int offset, int length) Sets each element within range to a number counting upstatic void
intersection
(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 void
intersection
(int[] setA, int sizeA, int[] setB, int sizeB, DogArray_I32 results, @Nullable DogArray_I8 work) Finds the itersection of two sets.static int
lowerBound
(byte[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic int
lowerBound
(double[] array, int offset, int length, double val) Finds the first index in 'array' for which val is not ≤ valstatic int
lowerBound
(float[] array, int offset, int length, float val) Finds the first index in 'array' for which val is not ≤ valstatic int
lowerBound
(int[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic int
lowerBound
(short[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic int
lowerBoundU
(byte[] array, int offset, int length, int val) Finds the first index in 'array' for which val is not ≤ valstatic int
max
(byte[] array, int offset, int length) Returns the value of the element with the maximum valuestatic double
max
(double[] array, int offset, int length) Returns the value of the element with the maximum valuestatic float
max
(float[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
max
(int[] array, int offset, int length) Returns the value of the element with the maximum valuestatic long
max
(long[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
max
(short[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
maxIdx
(byte[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
maxIdx
(double[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
maxIdx
(float[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
maxIdx
(int[] array, int offset, int length) Returns the value of the element with the maximum valuestatic int
min
(byte[] array, int offset, int length) Returns the value of the element with the minimum valuestatic double
min
(double[] array, int offset, int length) Returns the value of the element with the minimum valuestatic float
min
(float[] array, int offset, int length) Returns the value of the element with the minimum valuestatic int
min
(int[] array, int offset, int length) Returns the value of the element with the minimum valuestatic long
min
(long[] array, int offset, int length) Returns the value of the element with the minimum valuestatic int
min
(short[] array, int offset, int length) Returns the value of the element with the minimum valuestatic int
minIdx
(byte[] array, int offset, int length) Returns the index of the element with the minimum valuestatic int
minIdx
(double[] array, int offset, int length) Returns the index of the element with the minimum valuestatic int
minIdx
(float[] array, int offset, int length) Returns the index of the element with the minimum valuestatic int
minIdx
(int[] array, int offset, int length) Returns the index of the element with the minimum valuestatic void
Randomly shuffle the arraystatic void
Randomly shuffle the arraystatic void
Randomly shuffle the arraystatic void
Randomly shuffle the arraystatic void
Randomly shuffle the arraystatic void
Randomly shuffle the arraystatic double
sumD
(byte[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic double
sumD
(double[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic double
sumD
(float[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic double
sumD
(int[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic double
sumD
(long[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic double
sumD
(short[] array, int offset, int length) Computes the sum of the array and stores the result in a doublestatic void
union
(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.
-