Skip to content

Don't call sort! and partialsort! "in-place" #58901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ maybeview(v, k::Integer) = v[k]
"""
partialsort!(v, k; by=identity, lt=isless, rev=false)

Partially sort the vector `v` in place so that the value at index `k` (or
Mutate the vector `v` so that the value at index `k` (or
range of adjacent values if `k` is a range) occurs
at the position where it would appear if the array were fully sorted. If `k` is a single
index, that value is returned; if `k` is a range, an array of values at those indices is
Expand Down Expand Up @@ -1625,10 +1625,11 @@ defalg(v) = DEFAULT_STABLE
"""
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
be selected via the `alg` keyword (see [Sorting Algorithms](@ref) for available
algorithms).
Mutate the vector `v` so that it is sorted.

A stable algorithm is used by default: the ordering of elements that
compare equal is preserved. A specific algorithm can be selected via the
`alg` keyword (see [Sorting Algorithms](@ref) for available algorithms).

Elements are first transformed with the function `by` and then compared
according to either the function `lt` or the ordering `order`. Finally, the
Expand Down Expand Up @@ -1745,7 +1746,7 @@ end
Variant of [`sort!`](@ref) that returns a sorted copy of `v` leaving `v` itself unmodified.

When calling `sort` on the [`keys`](@ref) or [`values](@ref) of a dictionary, `v` is
collected and then sorted in place.
collected and then sorted.

!!! compat "Julia 1.12"
Sorting `NTuple`s requires Julia 1.12 or later.
Expand Down Expand Up @@ -2289,7 +2290,7 @@ UIntMappable(T::Type, order::ReverseOrdering) = UIntMappable(T, order.fwd)

### Vectors

# Convert v to unsigned integers in place, maintaining sort order.
# Convert v to unsigned integers in-place, maintaining sort order.
function uint_map!(v::AbstractVector, lo::Integer, hi::Integer, order::Ordering)
u = reinterpret(UIntMappable(eltype(v), order), v)
@inbounds for i in lo:hi
Expand Down