Class PrimitiveArrays

java.lang.Object
org.ddogleg.util.PrimitiveArrays

public class PrimitiveArrays extends Object
Various functions for manipulating primitive arrays
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 up
    static 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 ≤ val
    static int
    lowerBound(double[] array, int offset, int length, double val)
    Finds the first index in 'array' for which val is not ≤ val
    static int
    lowerBound(float[] array, int offset, int length, float val)
    Finds the first index in 'array' for which val is not ≤ val
    static int
    lowerBound(int[] array, int offset, int length, int val)
    Finds the first index in 'array' for which val is not ≤ val
    static int
    lowerBound(short[] array, int offset, int length, int val)
    Finds the first index in 'array' for which val is not ≤ val
    static int
    lowerBoundU(byte[] array, int offset, int length, int val)
    Finds the first index in 'array' for which val is not ≤ val
    static int
    max(byte[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static double
    max(double[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static float
    max(float[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    max(int[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static long
    max(long[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    max(short[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    maxIdx(byte[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    maxIdx(double[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    maxIdx(float[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    maxIdx(int[] array, int offset, int length)
    Returns the value of the element with the maximum value
    static int
    min(byte[] array, int offset, int length)
    Returns the value of the element with the minimum value
    static double
    min(double[] array, int offset, int length)
    Returns the value of the element with the minimum value
    static float
    min(float[] array, int offset, int length)
    Returns the value of the element with the minimum value
    static int
    min(int[] array, int offset, int length)
    Returns the value of the element with the minimum value
    static long
    min(long[] array, int offset, int length)
    Returns the value of the element with the minimum value
    static int
    min(short[] array, int offset, int length)
    Returns the value of the element with the minimum value
    static int
    minIdx(byte[] array, int offset, int length)
    Returns the index of the element with the minimum value
    static int
    minIdx(double[] array, int offset, int length)
    Returns the index of the element with the minimum value
    static int
    minIdx(float[] array, int offset, int length)
    Returns the index of the element with the minimum value
    static int
    minIdx(int[] array, int offset, int length)
    Returns the index of the element with the minimum value
    static void
    shuffle(byte[] array, int offset, int length, Random rand)
    Randomly shuffle the array
    static void
    shuffle(double[] array, int offset, int length, Random rand)
    Randomly shuffle the array
    static void
    shuffle(float[] array, int offset, int length, Random rand)
    Randomly shuffle the array
    static void
    shuffle(int[] array, int offset, int length, Random rand)
    Randomly shuffle the array
    static void
    shuffle(long[] array, int offset, int length, Random rand)
    Randomly shuffle the array
    static void
    shuffle(short[] array, int offset, int length, Random rand)
    Randomly shuffle the array
    static double
    sumD(byte[] array, int offset, int length)
    Computes the sum of the array and stores the result in a double
    static double
    sumD(double[] array, int offset, int length)
    Computes the sum of the array and stores the result in a double
    static double
    sumD(float[] array, int offset, int length)
    Computes the sum of the array and stores the result in a double
    static double
    sumD(int[] array, int offset, int length)
    Computes the sum of the array and stores the result in a double
    static double
    sumD(long[] array, int offset, int length)
    Computes the sum of the array and stores the result in a double
    static double
    sumD(short[] array, int offset, int length)
    Computes the sum of the array and stores the result in a double
    static 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 A
      setB - Set B of integers. Unsorted.
      sizeB - Number of elements in set B
      work - Work space
      results - 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 A
      setB - Set B of integers. Unsorted.
      sizeB - Number of elements in set B
      valueMin - Minimum value in either set
      valueMax - Maximum value in either set
      work - Work space
      results - 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 A
      setB - Set B of integers. Unsorted.
      sizeB - Number of elements in set B
      valueMin - Minimum value in either set
      valueMax - Maximum value in either set
      work - Work space
      results - 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

      public static void shuffle(byte[] array, int offset, int length, Random rand)
      Randomly shuffle the array
    • shuffle

      public static void shuffle(short[] array, int offset, int length, Random rand)
      Randomly shuffle the array
    • shuffle

      public static void shuffle(int[] array, int offset, int length, Random rand)
      Randomly shuffle the array
    • shuffle

      public static void shuffle(long[] array, int offset, int length, Random rand)
      Randomly shuffle the array
    • shuffle

      public static void shuffle(float[] array, int offset, int length, Random rand)
      Randomly shuffle the array
    • shuffle

      public static void shuffle(double[] array, int offset, int length, Random rand)
      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 array
      length - Number of elements in the array
      val - 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 array
      offset - First index in the array
      length - Number of elements in the array
      val - 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 array
      length - Number of elements in the array
      val - 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 array
      length - Number of elements in the array
      val - 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 array
      length - Number of elements in the array
      val - 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 array
      length - Number of elements in the array
      val - 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.