## org.apache.mahout.math
Class BinarySearch

    java.lang.Object
      org.apache.mahout.math.BinarySearch

    public final class BinarySearch

extends Object

Method Summary
`static int` `binarySearchFromTo(byte[] array, byte value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.
`static int` `binarySearchFromTo(char[] array, char value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.
`static int` `binarySearchFromTo(double[] array, double value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.
`static int` `binarySearchFromTo(float[] array, float value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.
`static int` `binarySearchFromTo(int[] array, int value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.
`static int` `binarySearchFromTo(long[] array, long value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.
`static int` `binarySearchFromTo(short[] array, short value, int from, int to)` Performs a binary search for the specified element in the specified ascending sorted array.

`static

`<T extends Comparable<T>> int`

`

`binarySearchFromTo(T[] array, T object, int from, int to)`
Performs a binary search for the specified element in the specified ascending sorted array.

`static

`<T> int`

`

`binarySearchFromTo(T[] array, T object, int from, int to, Comparator<? super T> comparator)`
Performs a binary search for the specified element in the specified ascending sorted array using the `Comparator` to compare elements.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### binarySearchFromTo

    public static int binarySearchFromTo(byte[] array,
                                         byte value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `byte` array to search.
    `value` - the `byte` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static int binarySearchFromTo(char[] array,
                                         char value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `char` array to search.
    `value` - the `char` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static int binarySearchFromTo(double[] array,
                                         double value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `double` array to search.
    `value` - the `double` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static int binarySearchFromTo(float[] array,
                                         float value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `float` array to search.
    `value` - the `float` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static int binarySearchFromTo(int[] array,
                                         int value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `int` array to search.
    `value` - the `int` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static int binarySearchFromTo(long[] array,
                                         long value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `long` array to search.
    `value` - the `long` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static <T extends Comparable<T>> int binarySearchFromTo(T[] array,
                                                                   T object,
                                                                   int from,
                                                                   int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `Object` array to search.
    `object` - the `Object` element to find
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

### binarySearchFromTo

    public static <T> int binarySearchFromTo(T[] array,
                                             T object,
                                             int from,
                                             int to,
                                             Comparator<? super T> comparator)

  Performs a binary search for the specified element in the specified ascending sorted array using the `Comparator` to compare elements. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted array to search
    `object` - the element to find
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
    `comparator` - the `Comparator` used to compare the elements.
  Returns:
    the non-negative index of the element, or a negative index which

### binarySearchFromTo

    public static int binarySearchFromTo(short[] array,
                                         short value,
                                         int from,
                                         int to)

  Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.

  Parameters:
    `array` - the sorted `short` array to search.
    `value` - the `short` element to find.
    `from` - the first index to sort, inclusive.
    `to` - the last index to sort, inclusive.
  Returns:
    the non-negative index of the element, or a negative index which is `-index - 1` where the element would be inserted.

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.