JuliaLang/julia — pull request #1620 by kmsquire (2012-11-27 23:49:56+00:00)
Title: Clean up search_sorted* functions

* Use 1-based indexing for searching subarrays
* Allow to be defined on AbstractVectors
* Make search_sorted and alias for search_sorted_first
* Round out functions with search_sorted_first_gt,
search_sorted_last_lt (+ tests)
* Added documentation

### Discussion

Recent commit df7a323 exposed a more general interface to `search_sorted*()` functions, allowing the caller to optionally specify the range to call. This interface was inconsistent between `search_sorted()` (1-based) and `search_sorted_{first,last}()` (0-based, range 0:length(a)+1). The first item above address this issue, using 1-based indexing; internally, 0-based indexing is still used (and this is the 'proper' way to do binary search--see http://www.tbray.org/ongoing/When/200x/2003/03/22/Binary)

Some additional deficiencies/idiosyncracies were identified (see https://github.com/JuliaLang/julia/commit/df7a323600#commitcomment-2212563) and are addressed by this commit.