Skip to content

Commit 1cb85ad

Browse files
Revert "Support sorting iterators (#46104)" (#52010)
Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
1 parent f26947b commit 1cb85ad

File tree

3 files changed

+3
-78
lines changed

3 files changed

+3
-78
lines changed

base/sort.jl

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ module Sort
55
using Base.Order
66

77
using Base: copymutable, midpoint, require_one_based_indexing, uinttype,
8-
sub_with_overflow, add_with_overflow, OneTo, BitSigned, BitIntegerType, top_set_bit,
9-
IteratorSize, HasShape, IsInfinite, tail
8+
sub_with_overflow, add_with_overflow, OneTo, BitSigned, BitIntegerType, top_set_bit
109

1110
import Base:
1211
sort,
@@ -1474,12 +1473,6 @@ end
14741473
14751474
Variant of [`sort!`](@ref) that returns a sorted copy of `v` leaving `v` itself unmodified.
14761475
1477-
Returns something [`similar`](@ref) to `v` when `v` is an `AbstractArray` and uses
1478-
[`collect`](@ref) to support arbitrary non-`AbstractArray` iterables.
1479-
1480-
!!! compat "Julia 1.10"
1481-
`sort` of arbitrary iterables requires at least Julia 1.10.
1482-
14831476
# Examples
14841477
```jldoctest
14851478
julia> v = [3, 1, 2];
@@ -1497,39 +1490,7 @@ julia> v
14971490
2
14981491
```
14991492
"""
1500-
function sort(v; kws...)
1501-
size = IteratorSize(v)
1502-
size == HasShape{0}() && throw(ArgumentError("$v cannot be sorted"))
1503-
size == IsInfinite() && throw(ArgumentError("infinite iterator $v cannot be sorted"))
1504-
sort!(collect(v); kws...)
1505-
end
1506-
sort(v::AbstractVector; kws...) = sort!(copymutable(v); kws...) # for method disambiguation
1507-
sort(::AbstractString; kws...) =
1508-
throw(ArgumentError("sort(::AbstractString) is not supported"))
1509-
sort(::Tuple; kws...) =
1510-
throw(ArgumentError("sort(::Tuple) is only supported for NTuples"))
1511-
1512-
function sort(x::NTuple{N}; lt::Function=isless, by::Function=identity,
1513-
rev::Union{Bool,Nothing}=nothing, order::Ordering=Forward) where N
1514-
o = ord(lt,by,rev,order)
1515-
if N > 9
1516-
v = sort!(collect(x), DEFAULT_STABLE, o)
1517-
tuple((v[i] for i in 1:N)...)
1518-
else
1519-
_sort(x, o)
1520-
end
1521-
end
1522-
_sort(x::Union{NTuple{0}, NTuple{1}}, o::Ordering) = x
1523-
function _sort(x::NTuple, o::Ordering)
1524-
a, b = Base.IteratorsMD.split(x, Val(length(x)>>1))
1525-
merge(_sort(a, o), _sort(b, o), o)
1526-
end
1527-
merge(x::NTuple, y::NTuple{0}, o::Ordering) = x
1528-
merge(x::NTuple{0}, y::NTuple, o::Ordering) = y
1529-
merge(x::NTuple{0}, y::NTuple{0}, o::Ordering) = x # Method ambiguity
1530-
merge(x::NTuple, y::NTuple, o::Ordering) =
1531-
(lt(o, y[1], x[1]) ? (y[1], merge(x, tail(y), o)...) : (x[1], merge(tail(x), y, o)...))
1532-
1493+
sort(v::AbstractVector; kws...) = sort!(copymutable(v); kws...)
15331494

15341495
## partialsortperm: the permutation to sort the first k elements of an array ##
15351496

stdlib/REPL/src/docview.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ log_nonpublic_access(expr, ::Module, _) = expr
184184

185185
function insert_internal_warning(md::Markdown.MD, internal_access::Set{Pair{Module,Symbol}})
186186
if !isempty(internal_access)
187-
items = Any[Any[Markdown.Paragraph(Any[Markdown.Code("", s)])] for s in sort("$mod.$sym" for (mod, sym) in internal_access)]
187+
items = Any[Any[Markdown.Paragraph(Any[Markdown.Code("", s)])] for s in sort!(["$mod.$sym" for (mod, sym) in internal_access])]
188188
admonition = Markdown.Admonition("warning", "Warning", Any[
189189
Markdown.Paragraph(Any["The following bindings may be internal; they may change or be removed in future versions:"]),
190190
Markdown.List(items, -1, false)])

test/sorting.jl

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,6 @@ end
8888
vcat(2000, (x:x+99 for x in 1900:-100:100)..., 1:99)
8989
end
9090

91-
function tuple_sort_test(x)
92-
@test issorted(sort(x))
93-
length(x) > 9 && return # length > 9 uses a vector fallback
94-
@test 0 == @allocated sort(x)
95-
end
96-
@testset "sort(::NTuple)" begin
97-
@test sort((9,8,3,3,6,2,0,8)) == (0,2,3,3,6,8,8,9)
98-
@test sort((9,8,3,3,6,2,0,8), by=x->x÷3) == (2,0,3,3,8,6,8,9)
99-
for i in 1:40
100-
tuple_sort_test(tuple(rand(i)...))
101-
end
102-
@test_throws ArgumentError sort((1,2,3.0))
103-
end
104-
10591
@testset "partialsort" begin
10692
@test partialsort([3,6,30,1,9],3) == 6
10793
@test partialsort([3,6,30,1,9],3:4) == [6,9]
@@ -544,28 +530,6 @@ end
544530
@test isequal(a, [8,6,7,NaN,5,3,0,9])
545531
end
546532

547-
@testset "sort!(iterable)" begin
548-
gen = (x % 7 + 0.1x for x in 1:50)
549-
@test sort(gen) == sort!(collect(gen))
550-
gen = (x % 7 + 0.1y for x in 1:10, y in 1:5)
551-
@test sort(gen; dims=1) == sort!(collect(gen); dims=1)
552-
@test sort(gen; dims=2) == sort!(collect(gen); dims=2)
553-
554-
@test_throws ArgumentError("dimension out of range") sort(gen; dims=3)
555-
556-
@test_throws UndefKeywordError(:dims) sort(gen)
557-
@test_throws UndefKeywordError(:dims) sort(collect(gen))
558-
@test_throws UndefKeywordError(:dims) sort!(collect(gen))
559-
560-
@test_throws ArgumentError sort("string")
561-
@test_throws ArgumentError("1 cannot be sorted") sort(1)
562-
563-
@test sort(Set((1, 3, 6))) == [1, 3, 6]
564-
@test sort(Dict((1=>9, 3=>2, 6=>5))) == [1=>9, 3=>2, 6=>5]
565-
@test sort(keys(Dict((1=>2, 3=>5, 6=>9)))) == [1, 3, 6]
566-
@test sort(values(Dict((1=>9, 3=>2, 6=>5)))) == [2, 5, 9]
567-
end
568-
569533
@testset "sort!(::AbstractVector{<:Integer}) with short int range" begin
570534
a = view([9:-1:0;], :)::SubArray
571535
sort!(a)

0 commit comments

Comments
 (0)