Skip to content

Commit

Permalink
Reduce the range of elements sorted by partialsort (#47191)
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Vana <petvana@centrum.cz>
  • Loading branch information
LilithHafner and petvana authored Oct 24, 2022
1 parent 13c0060 commit a8bf137
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ issorted(itr;
issorted(itr, ord(lt,by,rev,order))

function partialsort!(v::AbstractVector, k::Union{Integer,OrdinalRange}, o::Ordering)
sort!(v, PartialQuickSort(k), o)
sort!(v, _PartialQuickSort(k), o)
maybeview(v, k)
end

Expand Down Expand Up @@ -436,6 +436,8 @@ struct PartialQuickSort{L<:Union{Integer,Missing}, H<:Union{Integer,Missing}} <:
end
PartialQuickSort(k::Integer) = PartialQuickSort(missing, k)
PartialQuickSort(k::OrdinalRange) = PartialQuickSort(first(k), last(k))
_PartialQuickSort(k::Integer) = PartialQuickSort(k, k)
_PartialQuickSort(k::OrdinalRange) = PartialQuickSort(k)

"""
InsertionSort
Expand Down Expand Up @@ -1082,7 +1084,7 @@ function partialsortperm!(ix::AbstractVector{<:Integer}, v::AbstractVector,
end

# do partial quicksort
sort!(ix, PartialQuickSort(k), Perm(ord(lt, by, rev, order), v))
sort!(ix, _PartialQuickSort(k), Perm(ord(lt, by, rev, order), v))

maybeview(ix, k)
end
Expand Down

0 comments on commit a8bf137

Please sign in to comment.