MCPcopy Create free account
hub / github.com/davidgiven/luje / binarySearch

Method binarySearch

lib/java/util/Arrays.java:181–198  ·  view source on GitHub ↗

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. @param array the sorted byte array

(byte[] array, byte value)

Source from the content-addressed store, hash-verified

179 * is {@code -index - 1} where the element would be inserted.
180 */
181 public static int binarySearch(byte[] array, byte value) {
182 int low = 0, mid = -1, high = array.length - 1;
183 while (low <= high) {
184 mid = (low + high) >>> 1;
185 if (value > array[mid]) {
186 low = mid + 1;
187 } else if (value == array[mid]) {
188 return mid;
189 } else {
190 high = mid - 1;
191 }
192 }
193 if (mid < 0) {
194 return -1;
195 }
196
197 return -mid - (value < array[mid] ? 1 : 2);
198 }
199
200 /**
201 * Performs a binary search for the specified element in the specified

Callers

nothing calls this directly

Calls 5

doubleToLongBitsMethod · 0.95
lessThanMethod · 0.95
floatToIntBitsMethod · 0.95
compareToMethod · 0.65
compareMethod · 0.65

Tested by

no test coverage detected