Skip to content

Commit

Permalink
Allow non-Vector to be sorted with sort_int_range!
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Mar 5, 2020
1 parent 71d9375 commit 7d1a3a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ function sort!(v::AbstractVector;
rev::Union{Bool,Nothing}=nothing,
order::Ordering=Forward)
ordr = ord(lt,by,rev,order)
if ordr === Forward && isa(v,Vector) && eltype(v)<:Integer
if ordr === Forward && eltype(v)<:Integer
n = length(v)
if n > 1
min, max = extrema(v)
Expand All @@ -726,7 +726,7 @@ function sort!(v::AbstractVector;
end

# sort! for vectors of few unique integers
function sort_int_range!(x::Vector{<:Integer}, rangelen, minval)
function sort_int_range!(x::AbstractVector{<:Integer}, rangelen, minval)
offs = 1 - minval
n = length(x)

Expand Down
10 changes: 10 additions & 0 deletions test/sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,14 @@ end
@test isequal(a, [8,6,7,NaN,5,3,0,9])
end

@testset "sort!(::AbstractVector{<:Integer}) with short int range" begin
a = view([9:-1:0;], :)::SubArray
sort!(a)
@test issorted(a)

a = view([9:-1:0;], :)::SubArray
Base.Sort.sort_int_range!(a, 10, 0) # test it supports non-Vector
@test issorted(a)
end

end

0 comments on commit 7d1a3a2

Please sign in to comment.