Skip to content

Commit

Permalink
Link to sort! in the docs of searchsorted* and update examples (#…
Browse files Browse the repository at this point in the history
…48449)

The keyword arguments are explained in `sort!`, and it would be good to know where to look. Also, I've added an example of how to use the `by` keyword argument in each case.
  • Loading branch information
jishnub authored Jan 31, 2023
1 parent b48104d commit 768d537
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ according to the order specified by the `by`, `lt` and `rev` keywords, assuming
is already sorted in that order. Return an empty range located at the insertion point
if `a` does not contain values equal to `x`.
See [`sort!`](@ref) for an explanation of the keyword arguments `by`, `lt` and `rev`.
See also: [`insorted`](@ref), [`searchsortedfirst`](@ref), [`sort`](@ref), [`findall`](@ref).
# Examples
Expand All @@ -313,6 +315,9 @@ julia> searchsorted([1, 2, 4, 5, 5, 7], 9) # no match, insert at end
julia> searchsorted([1, 2, 4, 5, 5, 7], 0) # no match, insert at start
1:0
julia> searchsorted([1=>"one", 2=>"two", 2=>"two", 4=>"four"], 2=>"two", by=first) # compare the keys of the pairs
2:3
```
""" searchsorted

Expand All @@ -325,6 +330,8 @@ specified order. Return `lastindex(a) + 1` if `x` is greater than all values in
`insert!`ing `x` at this index will maintain sorted order.
See [`sort!`](@ref) for an explanation of the keyword arguments `by`, `lt` and `rev`.
See also: [`searchsortedlast`](@ref), [`searchsorted`](@ref), [`findfirst`](@ref).
# Examples
Expand All @@ -343,6 +350,9 @@ julia> searchsortedfirst([1, 2, 4, 5, 5, 7], 9) # no match, insert at end
julia> searchsortedfirst([1, 2, 4, 5, 5, 7], 0) # no match, insert at start
1
julia> searchsortedfirst([1=>"one", 2=>"two", 4=>"four"], 3=>"three", by=first) # Compare the keys of the pairs
3
```
""" searchsortedfirst

Expand All @@ -353,6 +363,8 @@ Return the index of the last value in `a` less than or equal to `x`, according t
specified order. Return `firstindex(a) - 1` if `x` is less than all values in `a`. `a` is
assumed to be sorted.
See [`sort!`](@ref) for an explanation of the keyword arguments `by`, `lt` and `rev`.
# Examples
```jldoctest
julia> searchsortedlast([1, 2, 4, 5, 5, 7], 4) # single match
Expand All @@ -369,6 +381,9 @@ julia> searchsortedlast([1, 2, 4, 5, 5, 7], 9) # no match, insert at end
julia> searchsortedlast([1, 2, 4, 5, 5, 7], 0) # no match, insert at start
0
julia> searchsortedlast([1=>"one", 2=>"two", 4=>"four"], 3=>"three", by=first) # compare the keys of the pairs
2
```
""" searchsortedlast

Expand Down

0 comments on commit 768d537

Please sign in to comment.