Skip to content

Commit

Permalink
make default value of rev keyword argument type stable (#24422)
Browse files Browse the repository at this point in the history
this lets us remove the method overwrite during sysimg build
  • Loading branch information
JeffBezanson authored Nov 1, 2017
1 parent 55736a0 commit 4b06266
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
14 changes: 9 additions & 5 deletions base/ordering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ ordtype(o::Perm, vs::AbstractArray) = ordtype(o.order, o.data)
ordtype(o::By, vs::AbstractArray) = try typeof(o.by(vs[1])) catch; Any end
ordtype(o::Ordering, vs::AbstractArray) = eltype(vs)

_ord(lt::typeof(isless), by::typeof(identity), order::Ordering) = order
_ord(lt::typeof(isless), by, order::Ordering) = By(by)
_ord(lt, by::typeof(identity), order::Ordering) = Lt(lt)
_ord(lt, by, order::Ordering) = Lt((x,y)->lt(by(x),by(y)))

ord(lt, by, rev::Void, order::Ordering=Forward) = _ord(lt, by, order)

function ord(lt, by, rev::Bool, order::Ordering=Forward)
o = (lt===isless) & (by===identity) ? order :
(lt===isless) & (by!==identity) ? By(by) :
(lt!==isless) & (by===identity) ? Lt(lt) :
Lt((x,y)->lt(by(x),by(y)))
rev ? ReverseOrdering(o) : o
o = _ord(lt, by, order)
return rev ? ReverseOrdering(o) : o
end

end
17 changes: 8 additions & 9 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ true
```
"""
issorted(itr;
lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) =
lt=isless, by=identity, rev::Union{Bool,Void}=nothing, order::Ordering=Forward) =
issorted(itr, ord(lt,by,rev,order))

function partialsort!(v::AbstractVector, k::Union{Int,OrdinalRange}, o::Ordering)
Expand Down Expand Up @@ -140,7 +140,7 @@ julia> a
```
"""
partialsort!(v::AbstractVector, k::Union{Int,OrdinalRange};
lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) =
lt=isless, by=identity, rev::Union{Bool,Void}=nothing, order::Ordering=Forward) =
partialsort!(v, k, ord(lt,by,rev,order))

"""
Expand Down Expand Up @@ -272,9 +272,8 @@ for s in [:searchsortedfirst, :searchsortedlast, :searchsorted]
@eval begin
$s(v::AbstractVector, x, o::Ordering) = (inds = indices(v, 1); $s(v,x,first(inds),last(inds),o))
$s(v::AbstractVector, x;
lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) =
lt=isless, by=identity, rev::Union{Bool,Void}=nothing, order::Ordering=Forward) =
$s(v,x,ord(lt,by,rev,order))
$s(v::AbstractVector, x) = $s(v, x, Forward)
end
end

Expand Down Expand Up @@ -604,7 +603,7 @@ function sort!(v::AbstractVector;
alg::Algorithm=defalg(v),
lt=isless,
by=identity,
rev::Bool=false,
rev::Union{Bool,Void}=nothing,
order::Ordering=Forward)
ordr = ord(lt,by,rev,order)
if ordr === Forward && isa(v,Vector) && eltype(v)<:Integer
Expand Down Expand Up @@ -695,7 +694,7 @@ function partialsortperm!(ix::AbstractVector{<:Integer}, v::AbstractVector,
k::Union{Int, OrdinalRange};
lt::Function=isless,
by::Function=identity,
rev::Bool=false,
rev::Union{Bool,Void}=nothing,
order::Ordering=Forward,
initialized::Bool=false)
if !initialized
Expand Down Expand Up @@ -746,7 +745,7 @@ function sortperm(v::AbstractVector;
alg::Algorithm=DEFAULT_UNSTABLE,
lt=isless,
by=identity,
rev::Bool=false,
rev::Union{Bool,Void}=nothing,
order::Ordering=Forward)
ordr = ord(lt,by,rev,order)
if ordr === Forward && isa(v,Vector) && eltype(v)<:Integer
Expand Down Expand Up @@ -795,7 +794,7 @@ function sortperm!(x::AbstractVector{<:Integer}, v::AbstractVector;
alg::Algorithm=DEFAULT_UNSTABLE,
lt=isless,
by=identity,
rev::Bool=false,
rev::Union{Bool,Void}=nothing,
order::Ordering=Forward,
initialized::Bool=false)
if indices(x,1) != indices(v,1)
Expand Down Expand Up @@ -862,7 +861,7 @@ function sort(A::AbstractArray, dim::Integer;
alg::Algorithm=DEFAULT_UNSTABLE,
lt=isless,
by=identity,
rev::Bool=false,
rev::Union{Bool,Void}=nothing,
order::Ordering=Forward,
initialized::Union{Bool,Void}=nothing)
if initialized !== nothing
Expand Down

0 comments on commit 4b06266

Please sign in to comment.