Class BinSearch

java.lang.Object
io.deephaven.function.BinSearch

public class BinSearch extends Object
Functions for performing binary searches.
  • Constructor Details

    • BinSearch

      public BinSearch()
  • Method Details

    • binSearchIndex

      public static <T extends Comparable<? super T>> int binSearchIndex(T[] values, T key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • binSearchIndex

      public static <T extends Comparable<? super T>> int binSearchIndex(ObjectVector<T> values, T key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static <T extends Comparable<? super T>> int rawBinSearchIndex(T[] values, T key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static <T extends Comparable<? super T>> int rawBinSearchIndex(ObjectVector<T> values, T key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(char[] values, char key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(CharVector values, char key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(char[] values, char key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(CharVector values, char key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(byte[] values, byte key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(ByteVector values, byte key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(byte[] values, byte key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(ByteVector values, byte key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(short[] values, short key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(ShortVector values, short key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(short[] values, short key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(ShortVector values, short key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(int[] values, int key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(IntVector values, int key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(int[] values, int key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(IntVector values, int key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(long[] values, long key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(LongVector values, long key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(long[] values, long key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(LongVector values, long key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(float[] values, float key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(FloatVector values, float key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(float[] values, float key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(FloatVector values, float key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • binSearchIndex

      public static int binSearchIndex(double[] values, double key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index immediately before where the key would be inserted.
    • binSearchIndex

      public static int binSearchIndex(DoubleVector values, double key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static int rawBinSearchIndex(double[] values, double key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • rawBinSearchIndex

      public static int rawBinSearchIndex(DoubleVector values, double key, BinSearchAlgo choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search. Null values are not supported.
      key - key to search for. Null keys are not supported.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).