@@ -5,8 +5,7 @@ module Sort
5
5
using Base. Order
6
6
7
7
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
10
9
11
10
import Base:
12
11
sort,
@@ -1474,11 +1473,6 @@ end
1474
1473
1475
1474
Variant of [`sort!`](@ref) that returns a sorted copy of `v` leaving `v` itself unmodified.
1476
1475
1477
- Uses `Base.copymutable` to support immutable collections and iterables.
1478
-
1479
- !!! compat "Julia 1.10"
1480
- `sort` of arbitrary iterables requires at least Julia 1.10.
1481
-
1482
1476
# Examples
1483
1477
```jldoctest
1484
1478
julia> v = [3, 1, 2];
@@ -1496,39 +1490,7 @@ julia> v
1496
1490
2
1497
1491
```
1498
1492
"""
1499
- function sort (v; kws... )
1500
- size = IteratorSize (v)
1501
- size == HasShape {0} () && throw (ArgumentError (" $v cannot be sorted" ))
1502
- size == IsInfinite () && throw (ArgumentError (" infinite iterator $v cannot be sorted" ))
1503
- sort! (copymutable (v); kws... )
1504
- end
1505
- sort (v:: AbstractVector ; kws... ) = sort! (copymutable (v); kws... ) # for method disambiguation
1506
- sort (:: AbstractString ; kws... ) =
1507
- throw (ArgumentError (" sort(::AbstractString) is not supported" ))
1508
- sort (:: Tuple ; kws... ) =
1509
- throw (ArgumentError (" sort(::Tuple) is only supported for NTuples" ))
1510
-
1511
- function sort (x:: NTuple{N} ; lt:: Function = isless, by:: Function = identity,
1512
- rev:: Union{Bool,Nothing} = nothing , order:: Ordering = Forward) where N
1513
- o = ord (lt,by,rev,order)
1514
- if N > 9
1515
- v = sort! (copymutable (x), DEFAULT_STABLE, o)
1516
- tuple ((v[i] for i in 1 : N). .. )
1517
- else
1518
- _sort (x, o)
1519
- end
1520
- end
1521
- _sort (x:: Union{NTuple{0}, NTuple{1}} , o:: Ordering ) = x
1522
- function _sort (x:: NTuple , o:: Ordering )
1523
- a, b = Base. IteratorsMD. split (x, Val (length (x)>> 1 ))
1524
- merge (_sort (a, o), _sort (b, o), o)
1525
- end
1526
- merge (x:: NTuple , y:: NTuple{0} , o:: Ordering ) = x
1527
- merge (x:: NTuple{0} , y:: NTuple , o:: Ordering ) = y
1528
- merge (x:: NTuple{0} , y:: NTuple{0} , o:: Ordering ) = x # Method ambiguity
1529
- merge (x:: NTuple , y:: NTuple , o:: Ordering ) =
1530
- (lt (o, y[1 ], x[1 ]) ? (y[1 ], merge (x, tail (y), o)... ) : (x[1 ], merge (tail (x), y, o)... ))
1531
-
1493
+ sort (v:: AbstractVector ; kws... ) = sort! (copymutable (v); kws... )
1532
1494
1533
1495
# # partialsortperm: the permutation to sort the first k elements of an array ##
1534
1496
0 commit comments