Skip to content

Commit

Permalink
Explicit namespaces in sort-related docstrings (#53968)
Browse files Browse the repository at this point in the history
This represents the unexported names by the fully qualified namespace,
which makes it simpler to interpret the keyword arguments. Otherwise,
for example, it's not obvious where `Forward` comes from in the `sort`
docstring.

Also, replaces some occurrences of `instance <: Algorithm` by `instance
isa Algorithm`, which is the correct relation. This is also closer to
English, which helps with readability.

---------

Co-authored-by: Lilith Orion Hafner <[email protected]>
  • Loading branch information
jishnub and LilithHafner authored Apr 6, 2024
1 parent d963a34 commit c707a53
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function issorted(itr, order::Ordering)
end

"""
issorted(v, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)
issorted(v, lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
Test whether a collection is in sorted order. The keywords modify what
order is considered sorted, as described in the [`sort!`](@ref) documentation.
Expand Down Expand Up @@ -514,7 +514,7 @@ end
## sorting algorithm components ##

"""
_sort!(v::AbstractVector, a::Algorithm, o::Ordering, kw; t, offset)
_sort!(v::AbstractVector, a::Base.Sort.Algorithm, o::Base.Order.Ordering, kw; t, offset)
An internal function that sorts `v` using the algorithm `a` under the ordering `o`,
subject to specifications provided in `kw` (such as `lo` and `hi` in which case it only
Expand All @@ -539,7 +539,7 @@ function _sort! end
# TODO: delete this optimization when views have no overhead.
const UnwrappableSubArray = SubArray{T, 1, <:AbstractArray{T}, <:Tuple{AbstractUnitRange, Vararg{Number}}, true} where T
"""
SubArrayOptimization(next) <: Algorithm
SubArrayOptimization(next) isa Base.Sort.Algorithm
Unwrap certain known SubArrays because views have a performance overhead 😢
Expand All @@ -566,7 +566,7 @@ function _sort!(v::UnwrappableSubArray, a::SubArrayOptimization, o::Ordering, kw
end

"""
MissingOptimization(next) <: Algorithm
MissingOptimization(next) isa Base.Sort.Algorithm
Filter out missing values.
Expand Down Expand Up @@ -625,7 +625,7 @@ function send_to_end!(f::F, v::AbstractVector; lo=firstindex(v), hi=lastindex(v)
i - 1
end
"""
send_to_end!(f::Function, v::AbstractVector, o::DirectOrdering[, end_stable]; lo, hi)
send_to_end!(f::Function, v::AbstractVector, o::Base.Order.DirectOrdering[, end_stable]; lo, hi)
Return `(a, b)` where `v[a:b]` are the elements that are not sent to the end.
Expand Down Expand Up @@ -679,7 +679,7 @@ end


"""
IEEEFloatOptimization(next) <: Algorithm
IEEEFloatOptimization(next) isa Base.Sort.Algorithm
Move NaN values to the end, partition by sign, and reinterpret the rest as unsigned integers.
Expand Down Expand Up @@ -724,7 +724,7 @@ end


"""
BoolOptimization(next) <: Algorithm
BoolOptimization(next) isa Base.Sort.Algorithm
Sort `AbstractVector{Bool}`s using a specialized version of counting sort.
Expand All @@ -751,7 +751,7 @@ end


"""
IsUIntMappable(yes, no) <: Algorithm
IsUIntMappable(yes, no) isa Base.Sort.Algorithm
Determines if the elements of a vector can be mapped to unsigned integers while preserving
their order under the specified ordering.
Expand All @@ -773,7 +773,7 @@ end


"""
Small{N}(small=SMALL_ALGORITHM, big) <: Algorithm
Small{N}(small=SMALL_ALGORITHM, big) isa Base.Sort.Algorithm
Sort inputs with `length(lo:hi) <= N` using the `small` algorithm. Otherwise use the `big`
algorithm.
Expand Down Expand Up @@ -845,7 +845,7 @@ end


"""
CheckSorted(next) <: Algorithm
CheckSorted(next) isa Base.Sort.Algorithm
Check if the input is already sorted and for large inputs, also check if it is
reverse-sorted. The reverse-sorted check is unstable.
Expand All @@ -872,7 +872,7 @@ end


"""
ComputeExtrema(next) <: Algorithm
ComputeExtrema(next) isa Base.Sort.Algorithm
Compute the extrema of the input under the provided order.
Expand All @@ -898,7 +898,7 @@ end


"""
ConsiderCountingSort(counting=CountingSort(), next) <: Algorithm
ConsiderCountingSort(counting=CountingSort(), next) isa Base.Sort.Algorithm
If the input's range is small enough, use the `counting` algorithm. Otherwise, dispatch to
the `next` algorithm.
Expand Down Expand Up @@ -926,7 +926,7 @@ _sort!(v::AbstractVector, a::ConsiderCountingSort, o::Ordering, kw) = _sort!(v,


"""
CountingSort <: Algorithm
CountingSort() isa Base.Sort.Algorithm
Use the counting sort algorithm.
Expand Down Expand Up @@ -962,7 +962,7 @@ end


"""
ConsiderRadixSort(radix=RadixSort(), next) <: Algorithm
ConsiderRadixSort(radix=RadixSort(), next) isa Base.Sort.Algorithm
If the number of bits in the input's range is small enough and the input supports efficient
bitshifts, use the `radix` algorithm. Otherwise, dispatch to the `next` algorithm.
Expand All @@ -985,7 +985,7 @@ end


"""
RadixSort <: Algorithm
RadixSort() isa Base.Sort.Algorithm
Use the radix sort algorithm.
Expand Down Expand Up @@ -1040,8 +1040,8 @@ end


"""
ScratchQuickSort(next::Algorithm=SMALL_ALGORITHM) <: Algorithm
ScratchQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}=lo, next::Algorithm=SMALL_ALGORITHM) <: Algorithm
ScratchQuickSort(next::Base.Sort.Algorithm=Base.Sort.SMALL_ALGORITHM) isa Base.Sort.Algorithm
ScratchQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}=lo, next::Base.Sort.Algorithm=Base.Sort.SMALL_ALGORITHM) isa Base.Sort.Algorithm
Use the `ScratchQuickSort` algorithm with the `next` algorithm as a base case.
Expand Down Expand Up @@ -1157,7 +1157,7 @@ end


"""
BracketedSort(target[, next::Algorithm]) <: Algorithm
BracketedSort(target[, next::Algorithm]) isa Base.Sort.Algorithm
Perform a partialsort for the elements that fall into the indices specified by the `target`
using BracketedSort with the `next` algorithm for subproblems.
Expand Down Expand Up @@ -1346,7 +1346,7 @@ end


"""
StableCheckSorted(next) <: Algorithm
StableCheckSorted(next) isa Base.Sort.Algorithm
Check if an input is sorted and/or reverse-sorted.
Expand Down Expand Up @@ -1446,7 +1446,7 @@ end
## default sorting policy ##

"""
InitialOptimizations(next) <: Algorithm
InitialOptimizations(next) isa Base.Sort.Algorithm
Attempt to apply a suite of low-cost optimizations to the input vector before sorting. These
optimizations may be automatically applied by the `sort!` family of functions when
Expand Down Expand Up @@ -1593,7 +1593,7 @@ defalg(v::AbstractArray{Missing}) = DEFAULT_UNSTABLE # for method disambiguation
defalg(v::AbstractArray{Union{}}) = DEFAULT_UNSTABLE # for method disambiguation

"""
sort!(v; alg::Algorithm=defalg(v), lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)
sort!(v; alg::Base.Sort.Algorithm=Base.Sort.defalg(v), lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
Sort the vector `v` in place. A stable algorithm is used by default: the
ordering of elements that compare equal is preserved. A specific algorithm can
Expand Down Expand Up @@ -1706,7 +1706,7 @@ function sort!(v::AbstractVector{T};
end

"""
sort(v; alg::Algorithm=defalg(v), lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)
sort(v; alg::Base.Sort.Algorithm=Base.Sort.defalg(v), lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
Variant of [`sort!`](@ref) that returns a sorted copy of `v` leaving `v` itself unmodified.
Expand Down Expand Up @@ -1829,7 +1829,7 @@ end
## sortperm: the permutation to sort an array ##

"""
sortperm(A; alg::Algorithm=DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward, [dims::Integer])
sortperm(A; alg::Base.Sort.Algorithm=Base.Sort.DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward, [dims::Integer])
Return a permutation vector or array `I` that puts `A[I]` in sorted order along the given dimension.
If `A` has more than one dimension, then the `dims` keyword argument must be specified. The order is specified
Expand Down Expand Up @@ -1907,7 +1907,7 @@ end


"""
sortperm!(ix, A; alg::Algorithm=DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward, [dims::Integer])
sortperm!(ix, A; alg::Base.Sort.Algorithm=Base.Sort.DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward, [dims::Integer])
Like [`sortperm`](@ref), but accepts a preallocated index vector or array `ix` with the same `axes` as `A`.
`ix` is initialized to contain the values `LinearIndices(A)`.
Expand Down Expand Up @@ -1995,7 +1995,7 @@ end
## sorting multi-dimensional arrays ##

"""
sort(A; dims::Integer, alg::Algorithm=defalg(A), lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)
sort(A; dims::Integer, alg::Base.Sort.Algorithm=Base.Sort.defalg(A), lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
Sort a multidimensional array `A` along the given dimension.
See [`sort!`](@ref) for a description of possible
Expand Down Expand Up @@ -2067,7 +2067,7 @@ end


"""
sort!(A; dims::Integer, alg::Algorithm=defalg(A), lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)
sort!(A; dims::Integer, alg::Base.Sort.Algorithm=Base.Sort.defalg(A), lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
Sort the multidimensional array `A` along dimension `dims`.
See the one-dimensional version of [`sort!`](@ref) for a description of
Expand Down Expand Up @@ -2139,7 +2139,7 @@ get_value(::Val{x}) where x = x
## uint mapping to allow radix sorting primitives other than UInts ##

"""
UIntMappable(T::Type, order::Ordering)
UIntMappable(T::Type, order::Base.Order.Ordering)
Return `typeof(uint_map(x::T, order))` if [`uint_map`](@ref) and
[`uint_unmap`](@ref) are implemented.
Expand All @@ -2149,7 +2149,7 @@ If either is not implemented, return `nothing`.
UIntMappable(T::Type, order::Ordering) = nothing

"""
uint_map(x, order::Ordering)::Unsigned
uint_map(x, order::Base.Order.Ordering)::Unsigned
Map `x` to an un unsigned integer, maintaining sort order.
Expand All @@ -2163,7 +2163,7 @@ See also: [`UIntMappable`](@ref) [`uint_unmap`](@ref)
function uint_map end

"""
uint_unmap(T::Type, u::Unsigned, order::Ordering)
uint_unmap(T::Type, u::Unsigned, order::Base.Order.Ordering)
Reconstruct the unique value `x::T` that uint_maps to `u`. Satisfies
`x === uint_unmap(T, uint_map(x::T, order), order)` for all `x <: T`.
Expand Down

0 comments on commit c707a53

Please sign in to comment.