From d0ddb7c012c0b4bf08c06bfac1c894f82830cda6 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Tue, 8 Nov 2022 14:10:56 +0600 Subject: [PATCH 1/3] Improve backwards compatibility in sorting --- base/sort.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/base/sort.jl b/base/sort.jl index e7e767146abb6..aeed555c909bb 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -414,6 +414,8 @@ abstract type Algorithm end struct InsertionSortAlg <: Algorithm end struct MergeSortAlg <: Algorithm end struct AdaptiveSortAlg <: Algorithm end +struct QuickSortAlg <: Algorithm end # Exists for backward compatability +# and redirects to PartialQuickSort(missing, missing). """ PartialQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}) @@ -473,7 +475,7 @@ Characteristics: * *quadratic worst case runtime* in pathological cases (vanishingly rare for non-malicious input) """ -const QuickSort = PartialQuickSort(missing, missing) +const QuickSort = QuickSortAlg() """ MergeSort @@ -570,6 +572,12 @@ function partition!(t::AbstractVector, lo::Integer, hi::Integer, o::Ordering, v: pivot, lo-trues end +# This method exists for backwards compatability with dispatch on sort!(..., ::QuickSortAlg, ...) +function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::QuickSortAlg, + o::Ordering, t::AbstractVector=similar(v), swap=false, rev=false; + check_presorted=true) + sort!(v, lo, hi, PartialQuickSort(missing, missing), o, t, swap, rev; check_presorted) +end function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::PartialQuickSort, o::Ordering, t::AbstractVector=similar(v), swap=false, rev=false; check_presorted=true) From bd3264c21943c491d58ffb7fdb7595a6b5664a61 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Tue, 8 Nov 2022 17:07:05 +0600 Subject: [PATCH 2/3] whitespace --- base/sort.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/sort.jl b/base/sort.jl index aeed555c909bb..94868dc09079b 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -573,7 +573,7 @@ function partition!(t::AbstractVector, lo::Integer, hi::Integer, o::Ordering, v: end # This method exists for backwards compatability with dispatch on sort!(..., ::QuickSortAlg, ...) -function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::QuickSortAlg, +function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::QuickSortAlg, o::Ordering, t::AbstractVector=similar(v), swap=false, rev=false; check_presorted=true) sort!(v, lo, hi, PartialQuickSort(missing, missing), o, t, swap, rev; check_presorted) From f5d4457d9ed554ba3946d56b992779795da3850f Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Tue, 8 Nov 2022 22:20:58 +0600 Subject: [PATCH 3/3] take a much simpler approach --- base/sort.jl | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/base/sort.jl b/base/sort.jl index 94868dc09079b..b4227e6fb5d3e 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -414,8 +414,6 @@ abstract type Algorithm end struct InsertionSortAlg <: Algorithm end struct MergeSortAlg <: Algorithm end struct AdaptiveSortAlg <: Algorithm end -struct QuickSortAlg <: Algorithm end # Exists for backward compatability -# and redirects to PartialQuickSort(missing, missing). """ PartialQuickSort(lo::Union{Integer, Missing}, hi::Union{Integer, Missing}) @@ -475,7 +473,8 @@ Characteristics: * *quadratic worst case runtime* in pathological cases (vanishingly rare for non-malicious input) """ -const QuickSort = QuickSortAlg() +const QuickSort = PartialQuickSort(missing, missing) +const QuickSortAlg = PartialQuickSort{Missing, Missing} # Exists for backward compatibility """ MergeSort @@ -572,12 +571,6 @@ function partition!(t::AbstractVector, lo::Integer, hi::Integer, o::Ordering, v: pivot, lo-trues end -# This method exists for backwards compatability with dispatch on sort!(..., ::QuickSortAlg, ...) -function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::QuickSortAlg, - o::Ordering, t::AbstractVector=similar(v), swap=false, rev=false; - check_presorted=true) - sort!(v, lo, hi, PartialQuickSort(missing, missing), o, t, swap, rev; check_presorted) -end function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::PartialQuickSort, o::Ordering, t::AbstractVector=similar(v), swap=false, rev=false; check_presorted=true)