Skip to content

Commit 9707594

Browse files
authored
rename QuickerSort to ScratchQuickSort (#48160)
1 parent eb5f6d6 commit 9707594

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

base/sort.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ issorted(itr;
8686
issorted(itr, ord(lt,by,rev,order))
8787

8888
function partialsort!(v::AbstractVector, k::Union{Integer,OrdinalRange}, o::Ordering)
89-
_sort!(v, InitialOptimizations(QuickerSort(k)), o, (;))
89+
_sort!(v, InitialOptimizations(ScratchQuickSort(k)), o, (;))
9090
maybeview(v, k)
9191
end
9292

@@ -950,12 +950,12 @@ end
950950

951951

952952
"""
953-
QuickerSort(next::Algorithm=SMALL_ALGORITHM) <: Algorithm
954-
QuickerSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}=lo, next::Algorithm=SMALL_ALGORITHM) <: Algorithm
953+
ScratchQuickSort(next::Algorithm=SMALL_ALGORITHM) <: Algorithm
954+
ScratchQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}=lo, next::Algorithm=SMALL_ALGORITHM) <: Algorithm
955955
956-
Use the `QuickerSort` algorithm with the `next` algorithm as a base case.
956+
Use the `ScratchQuickSort` algorithm with the `next` algorithm as a base case.
957957
958-
`QuickerSort` is like `QuickSort`, but utilizes scratch space to operate faster and allow
958+
`ScratchQuickSort` is like `QuickSort`, but utilizes scratch space to operate faster and allow
959959
for the possibility of maintaining stability.
960960
961961
If `lo` and `hi` are provided, finds and sorts the elements in the range `lo:hi`, reordering
@@ -973,15 +973,15 @@ Characteristics:
973973
* *quadratic worst case runtime* in pathological cases
974974
(vanishingly rare for non-malicious input)
975975
"""
976-
struct QuickerSort{L<:Union{Integer,Missing}, H<:Union{Integer,Missing}, T<:Algorithm} <: Algorithm
976+
struct ScratchQuickSort{L<:Union{Integer,Missing}, H<:Union{Integer,Missing}, T<:Algorithm} <: Algorithm
977977
lo::L
978978
hi::H
979979
next::T
980980
end
981-
QuickerSort(next::Algorithm=SMALL_ALGORITHM) = QuickerSort(missing, missing, next)
982-
QuickerSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}) = QuickerSort(lo, hi, SMALL_ALGORITHM)
983-
QuickerSort(lo::Union{Integer, Missing}, next::Algorithm=SMALL_ALGORITHM) = QuickerSort(lo, lo, next)
984-
QuickerSort(r::OrdinalRange, next::Algorithm=SMALL_ALGORITHM) = QuickerSort(first(r), last(r), next)
981+
ScratchQuickSort(next::Algorithm=SMALL_ALGORITHM) = ScratchQuickSort(missing, missing, next)
982+
ScratchQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}) = ScratchQuickSort(lo, hi, SMALL_ALGORITHM)
983+
ScratchQuickSort(lo::Union{Integer, Missing}, next::Algorithm=SMALL_ALGORITHM) = ScratchQuickSort(lo, lo, next)
984+
ScratchQuickSort(r::OrdinalRange, next::Algorithm=SMALL_ALGORITHM) = ScratchQuickSort(first(r), last(r), next)
985985

986986
# select a pivot, partition v[lo:hi] according
987987
# to the pivot, and store the result in t[lo:hi].
@@ -1020,7 +1020,7 @@ function partition!(t::AbstractVector, lo::Integer, hi::Integer, offset::Integer
10201020
pivot_index
10211021
end
10221022

1023-
function _sort!(v::AbstractVector, a::QuickerSort, o::Ordering, kw;
1023+
function _sort!(v::AbstractVector, a::ScratchQuickSort, o::Ordering, kw;
10241024
t=nothing, offset=nothing, swap=false, rev=false)
10251025
@getkw lo hi scratch
10261026

@@ -1038,7 +1038,7 @@ function _sort!(v::AbstractVector, a::QuickerSort, o::Ordering, kw;
10381038
end
10391039
swap = !swap
10401040

1041-
# For QuickerSort(), a.lo === a.hi === missing, so the first two branches get skipped
1041+
# For ScratchQuickSort(), a.lo === a.hi === missing, so the first two branches get skipped
10421042
if !ismissing(a.lo) && j <= a.lo # Skip sorting the lower part
10431043
swap && copyto!(v, lo, t, lo+offset, j-lo)
10441044
rev && reverse!(v, lo, j-1)
@@ -1236,7 +1236,7 @@ the initial optimizations because they can change the input vector's type and or
12361236
make them `UIntMappable`.
12371237
12381238
If the input is not [`UIntMappable`](@ref), then we perform a presorted check and dispatch
1239-
to [`QuickerSort`](@ref).
1239+
to [`ScratchQuickSort`](@ref).
12401240
12411241
Otherwise, we dispatch to [`InsertionSort`](@ref) for inputs with `length <= 40` and then
12421242
perform a presorted check ([`CheckSorted`](@ref)).
@@ -1268,7 +1268,7 @@ Consequently, we apply [`RadixSort`](@ref) for any reasonably long inputs that r
12681268
stage.
12691269
12701270
Finally, if the input has length less than 80, we dispatch to [`InsertionSort`](@ref) and
1271-
otherwise we dispatch to [`QuickerSort`](@ref).
1271+
otherwise we dispatch to [`ScratchQuickSort`](@ref).
12721272
"""
12731273
const DEFAULT_STABLE = InitialOptimizations(
12741274
IsUIntMappable(
@@ -1278,9 +1278,9 @@ const DEFAULT_STABLE = InitialOptimizations(
12781278
ConsiderCountingSort(
12791279
ConsiderRadixSort(
12801280
Small{80}(
1281-
QuickerSort())))))),
1281+
ScratchQuickSort())))))),
12821282
StableCheckSorted(
1283-
QuickerSort())))
1283+
ScratchQuickSort())))
12841284
"""
12851285
DEFAULT_UNSTABLE
12861286
@@ -1485,7 +1485,7 @@ function partialsortperm!(ix::AbstractVector{<:Integer}, v::AbstractVector,
14851485
end
14861486

14871487
# do partial quicksort
1488-
_sort!(ix, InitialOptimizations(QuickerSort(k)), Perm(ord(lt, by, rev, order), v), (;))
1488+
_sort!(ix, InitialOptimizations(ScratchQuickSort(k)), Perm(ord(lt, by, rev, order), v), (;))
14891489

14901490
maybeview(ix, k)
14911491
end

test/sorting.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ end
7979
end
8080

8181
@testset "stability" begin
82-
for Alg in [InsertionSort, MergeSort, Base.Sort.QuickerSort(), Base.DEFAULT_STABLE,
83-
Base.Sort.QuickerSort(missing, 1729), Base.Sort.QuickerSort(1729, missing)]
82+
for Alg in [InsertionSort, MergeSort, Base.Sort.ScratchQuickSort(), Base.DEFAULT_STABLE,
83+
Base.Sort.ScratchQuickSort(missing, 1729), Base.Sort.ScratchQuickSort(1729, missing)]
8484
@test issorted(sort(1:2000, alg=Alg, by=x->0))
8585
@test issorted(sort(1:2000, alg=Alg, by=x->x÷100))
8686
end
@@ -333,7 +333,7 @@ end
333333
@test c == v
334334

335335
# stable algorithms
336-
for alg in [MergeSort, Base.Sort.QuickerSort(), Base.Sort.QuickerSort(1:n), Base.DEFAULT_STABLE]
336+
for alg in [MergeSort, Base.Sort.ScratchQuickSort(), Base.Sort.ScratchQuickSort(1:n), Base.DEFAULT_STABLE]
337337
p = sortperm(v, alg=alg, rev=rev)
338338
p2 = sortperm(float(v), alg=alg, rev=rev)
339339
@test p == p2
@@ -381,7 +381,7 @@ end
381381
end
382382

383383
v = randn_with_nans(n,0.1)
384-
for alg in [InsertionSort, MergeSort, Base.Sort.QuickerSort(), Base.Sort.QuickerSort(1, n), Base.DEFAULT_UNSTABLE, Base.DEFAULT_STABLE],
384+
for alg in [InsertionSort, MergeSort, Base.Sort.ScratchQuickSort(), Base.Sort.ScratchQuickSort(1, n), Base.DEFAULT_UNSTABLE, Base.DEFAULT_STABLE],
385385
rev in [false,true]
386386
alg === InsertionSort && n >= 3000 && continue
387387
# test float sorting with NaNs
@@ -588,7 +588,7 @@ end
588588

589589
@testset "fallback" begin
590590
@test adaptive_sort_test(rand(1:typemax(Int32), len), by=x->x^2)# fallback
591-
@test adaptive_sort_test(rand(Int, len), by=x->0, trusted=Base.Sort.QuickerSort())
591+
@test adaptive_sort_test(rand(Int, len), by=x->0, trusted=Base.Sort.ScratchQuickSort())
592592
end
593593

594594
@test adaptive_sort_test(rand(Int, 20)) # InsertionSort
@@ -692,7 +692,7 @@ end
692692
# not allowed. Consequently, none of the behavior tested in this
693693
# testset is guaranteed to work in future minor versions of Julia.
694694

695-
safe_algs = [InsertionSort, MergeSort, Base.Sort.QuickerSort(), Base.DEFAULT_STABLE, Base.DEFAULT_UNSTABLE]
695+
safe_algs = [InsertionSort, MergeSort, Base.Sort.ScratchQuickSort(), Base.DEFAULT_STABLE, Base.DEFAULT_UNSTABLE]
696696

697697
n = 1000
698698
v = rand(1:5, n);
@@ -899,8 +899,8 @@ end
899899
@test issorted(sort(rand(Int8, 600)))
900900
end
901901

902-
@testset "QuickerSort API" begin
903-
bsqs = Base.Sort.QuickerSort
902+
@testset "ScratchQuickSort API" begin
903+
bsqs = Base.Sort.ScratchQuickSort
904904
@test bsqs(1, 2, MergeSort) === bsqs(1, 2, MergeSort)
905905
@test bsqs(missing, 2, MergeSort) === bsqs(missing, 2, MergeSort)
906906
@test bsqs(1, missing, MergeSort) === bsqs(1, missing, MergeSort)
@@ -918,10 +918,10 @@ end
918918
@test bsqs() === bsqs(missing, missing, InsertionSort)
919919
end
920920

921-
@testset "QuickerSort allocations on non-concrete eltype" begin
921+
@testset "ScratchQuickSort allocations on non-concrete eltype" begin
922922
v = Vector{Union{Nothing, Bool}}(rand(Bool, 10000))
923923
@test 4 == @allocations sort(v)
924-
@test 4 == @allocations sort(v; alg=Base.Sort.QuickerSort())
924+
@test 4 == @allocations sort(v; alg=Base.Sort.ScratchQuickSort())
925925
# it would be nice if these numbers were lower (1 or 2), but these
926926
# test that we don't have O(n) allocations due to type instability
927927
end

0 commit comments

Comments
 (0)