Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ struct ConsiderRadixSort{T <: Algorithm, U <: Algorithm} <: Algorithm
next::U
end
ConsiderRadixSort(next) = ConsiderRadixSort(RadixSort(), next)
function _sort!(v::AbstractVector, a::ConsiderRadixSort, o::DirectOrdering, kw)
function _sort!(v::AbstractVector, a::ConsiderRadixSort, o::Ordering, kw)
@getkw lo hi mn mx
urange = uint_map(mx, o)-uint_map(mn, o)
bits = unsigned(top_set_bit(urange))
Expand Down Expand Up @@ -1016,7 +1016,7 @@ Each pass divides the input into `2^chunk_size == mask+1` buckets. To do this, i
`chunk_size` is larger for larger inputs and determined by an empirical heuristic.
"""
struct RadixSort <: Algorithm end
function _sort!(v::AbstractVector, a::RadixSort, o::DirectOrdering, kw)
function _sort!(v::AbstractVector, a::RadixSort, o::Ordering, kw)
@getkw lo hi mn mx scratch
umn = uint_map(mn, o)
urange = uint_map(mx, o)-umn
Expand Down
19 changes: 19 additions & 0 deletions test/sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,25 @@ end
@test partialsort!(view(copy(a), :, 6), 500:501) == [500, 501]
end

@testset "radix sort extensibility (#60184)" begin
# Note: these are internal behaviors and could break.
# These tests ensure that they don't break unintentionally.
struct A60184 u::UInt end

uint_order = Order.ord(isless, a -> a.u, false)

Sort.uint_map(a::A60184, ::typeof(uint_order)) = a.u
Sort.uint_unmap(::Type{A60184}, u::UInt, ::typeof(uint_order)) = A60184(u)
Sort.UIntMappable(::Type{A60184}, ::typeof(uint_order)) = UInt

v = map(A60184, rand(UInt, 3));
@test sort(v; order = uint_order) == A60184.(sort([a.u for a in v]))
v = map(A60184, rand(UInt, 41));
@test sort(v; order = uint_order) == A60184.(sort([a.u for a in v]))
v = map(A60184, rand(UInt, 401));
@test sort(v; order = uint_order) == A60184.(sort([a.u for a in v]))
end

# This testset is at the end of the file because it is slow.
@testset "searchsorted" begin
numTypes = [ Int8, Int16, Int32, Int64, Int128,
Expand Down