Finds the index of the bin a number belongs to.
search_bin(arr, x)
The index i
such that arr[i] <= x <= arr[i+1]
.
A vector of size at least 2.
A number. Must be within the range of [arr[1]
, arr[length(arr)]
].
Finds the smallest index i
such that arr[i] <= x <= arr[i+1]
. Calls binarySearch_bin()
if length(arr) > 8
and calls naiveSearch_bin()
otherwise.
search_bin(1:10, seq(1, 10, by=0.5))
Run the code above in your browser using DataLab