/** * Searches an array for the specified value using the binary search algorithm. * The range must be sorted prior to making this call. If it is not sorted, the * results are undefined. If the range contains multiple elements with the * specified value, there is no guarantee which one will be found. * * @param a * the array to be searched. * @param key * the value to be searched for. * @return index of the search key, if it is contained in the array; otherwise, * {@code (-(<i>insertion point</i>) - 1)}. The <i>insertion point</i> * is defined as the the point at which the value would be inserted into * the array: the index of the first element greater than the key, or * the length of the array, if all elements in the array are less than * the specified key. Note that this guarantees that the return value * will be ≥ 0 if and only if the key is found. * @see java.util.Arrays */ public static int binarySearch(final byte[] a, final byte key) { return binarySearch(a, 0, a.length, key); } /**
/** * Searches an array for the specified value using the binary search algorithm * and a specified comparator. The range must be sorted following the comparator * prior to making this call. If it is not sorted, the results are undefined. If * the range contains multiple elements with the specified value, there is no * guarantee which one will be found. * * @param a * the array to be searched. * @param key * the value to be searched for. * @param c * a comparator. * @return index of the search key, if it is contained in the array; otherwise, * {@code (-(<i>insertion point</i>) - 1)}. The <i>insertion point</i> * is defined as the the point at which the value would be inserted into * the array: the index of the first element greater than the key, or * the length of the array, if all elements in the array are less than * the specified key. Note that this guarantees that the return value * will be ≥ 0 if and only if the key is found. * @see java.util.Arrays */ public static int binarySearch(final byte[] a, final byte key, final ByteComparator c) { return binarySearch(a, 0, a.length, key, c); } /** The size of a digit used during radix sort (must be a power of 2). */