Skip to content

Commit 768d537

Browse files
authored
Link to sort! in the docs of searchsorted* and update examples (#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.
1 parent b48104d commit 768d537

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

base/sort.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ according to the order specified by the `by`, `lt` and `rev` keywords, assuming
295295
is already sorted in that order. Return an empty range located at the insertion point
296296
if `a` does not contain values equal to `x`.
297297
298+
See [`sort!`](@ref) for an explanation of the keyword arguments `by`, `lt` and `rev`.
299+
298300
See also: [`insorted`](@ref), [`searchsortedfirst`](@ref), [`sort`](@ref), [`findall`](@ref).
299301
300302
# Examples
@@ -313,6 +315,9 @@ julia> searchsorted([1, 2, 4, 5, 5, 7], 9) # no match, insert at end
313315
314316
julia> searchsorted([1, 2, 4, 5, 5, 7], 0) # no match, insert at start
315317
1:0
318+
319+
julia> searchsorted([1=>"one", 2=>"two", 2=>"two", 4=>"four"], 2=>"two", by=first) # compare the keys of the pairs
320+
2:3
316321
```
317322
""" searchsorted
318323

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

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

0 commit comments

Comments
 (0)