Skip to content

Commit cbc63ac

Browse files
LilithHafnerKristofferC
authored andcommitted
rename QuickerSort to ScratchQuickSort (#48160)
(cherry picked from commit 9707594)
1 parent ba490ff commit cbc63ac

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

@@ -953,12 +953,12 @@ end
953953

954954

955955
"""
956-
QuickerSort(next::Algorithm=SMALL_ALGORITHM) <: Algorithm
957-
QuickerSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}=lo, next::Algorithm=SMALL_ALGORITHM) <: Algorithm
956+
ScratchQuickSort(next::Algorithm=SMALL_ALGORITHM) <: Algorithm
957+
ScratchQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}=lo, next::Algorithm=SMALL_ALGORITHM) <: Algorithm
958958
959-
Use the `QuickerSort` algorithm with the `next` algorithm as a base case.
959+
Use the `ScratchQuickSort` algorithm with the `next` algorithm as a base case.
960960
961-
`QuickerSort` is like `QuickSort`, but utilizes scratch space to operate faster and allow
961+
`ScratchQuickSort` is like `QuickSort`, but utilizes scratch space to operate faster and allow
962962
for the possibility of maintaining stability.
963963
964964
If `lo` and `hi` are provided, finds and sorts the elements in the range `lo:hi`, reordering
@@ -976,15 +976,15 @@ Characteristics:
976976
* *quadratic worst case runtime* in pathological cases
977977
(vanishingly rare for non-malicious input)
978978
"""
979-
struct QuickerSort{L<:Union{Integer,Missing}, H<:Union{Integer,Missing}, T<:Algorithm} <: Algorithm
979+
struct ScratchQuickSort{L<:Union{Integer,Missing}, H<:Union{Integer,Missing}, T<:Algorithm} <: Algorithm
980980
lo::L
981981
hi::H
982982
next::T
983983
end
984-
QuickerSort(next::Algorithm=SMALL_ALGORITHM) = QuickerSort(missing, missing, next)
985-
QuickerSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}) = QuickerSort(lo, hi, SMALL_ALGORITHM)
986-
QuickerSort(lo::Union{Integer, Missing}, next::Algorithm=SMALL_ALGORITHM) = QuickerSort(lo, lo, next)
987-
QuickerSort(r::OrdinalRange, next::Algorithm=SMALL_ALGORITHM) = QuickerSort(first(r), last(r), next)
984+
ScratchQuickSort(next::Algorithm=SMALL_ALGORITHM) = ScratchQuickSort(missing, missing, next)
985+
ScratchQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}) = ScratchQuickSort(lo, hi, SMALL_ALGORITHM)
986+
ScratchQuickSort(lo::Union{Integer, Missing}, next::Algorithm=SMALL_ALGORITHM) = ScratchQuickSort(lo, lo, next)
987+
ScratchQuickSort(r::OrdinalRange, next::Algorithm=SMALL_ALGORITHM) = ScratchQuickSort(first(r), last(r), next)
988988

989989
# select a pivot, partition v[lo:hi] according
990990
# to the pivot, and store the result in t[lo:hi].
@@ -1023,7 +1023,7 @@ function partition!(t::AbstractVector, lo::Integer, hi::Integer, offset::Integer
10231023
pivot_index
10241024
end
10251025

1026-
function _sort!(v::AbstractVector, a::QuickerSort, o::Ordering, kw;
1026+
function _sort!(v::AbstractVector, a::ScratchQuickSort, o::Ordering, kw;
10271027
t=nothing, offset=nothing, swap=false, rev=false)
10281028
@getkw lo hi scratch
10291029

@@ -1041,7 +1041,7 @@ function _sort!(v::AbstractVector, a::QuickerSort, o::Ordering, kw;
10411041
end
10421042
swap = !swap
10431043

1044-
# For QuickerSort(), a.lo === a.hi === missing, so the first two branches get skipped
1044+
# For ScratchQuickSort(), a.lo === a.hi === missing, so the first two branches get skipped
10451045
if !ismissing(a.lo) && j <= a.lo # Skip sorting the lower part
10461046
swap && copyto!(v, lo, t, lo+offset, j-lo)
10471047
rev && reverse!(v, lo, j-1)
@@ -1239,7 +1239,7 @@ the initial optimizations because they can change the input vector's type and or
12391239
make them `UIntMappable`.
12401240
12411241
If the input is not [`UIntMappable`](@ref), then we perform a presorted check and dispatch
1242-
to [`QuickerSort`](@ref).
1242+
to [`ScratchQuickSort`](@ref).
12431243
12441244
Otherwise, we dispatch to [`InsertionSort`](@ref) for inputs with `length <= 40` and then
12451245
perform a presorted check ([`CheckSorted`](@ref)).
@@ -1271,7 +1271,7 @@ Consequently, we apply [`RadixSort`](@ref) for any reasonably long inputs that r
12711271
stage.
12721272
12731273
Finally, if the input has length less than 80, we dispatch to [`InsertionSort`](@ref) and
1274-
otherwise we dispatch to [`QuickerSort`](@ref).
1274+
otherwise we dispatch to [`ScratchQuickSort`](@ref).
12751275
"""
12761276
const DEFAULT_STABLE = InitialOptimizations(
12771277
IsUIntMappable(
@@ -1281,9 +1281,9 @@ const DEFAULT_STABLE = InitialOptimizations(
12811281
ConsiderCountingSort(
12821282
ConsiderRadixSort(
12831283
Small{80}(
1284-
QuickerSort())))))),
1284+
ScratchQuickSort())))))),
12851285
StableCheckSorted(
1286-
QuickerSort())))
1286+
ScratchQuickSort())))
12871287
"""
12881288
DEFAULT_UNSTABLE
12891289
@@ -1497,7 +1497,7 @@ function partialsortperm!(ix::AbstractVector{<:Integer}, v::AbstractVector,
14971497
end
14981498

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

15021502
maybeview(ix, k)
15031503
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)