/usr/share/julia/base/ordering.jl is in julia-common 0.4.7-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # This file is a part of Julia. License is MIT: http://julialang.org/license
module Order
## notions of element ordering ##
export # not exported by Base
Ordering, Forward, Reverse, Lexicographic,
By, Lt, Perm,
ReverseOrdering, ForwardOrdering, LexicographicOrdering,
DirectOrdering,
lt, ord, ordtype
abstract Ordering
immutable ForwardOrdering <: Ordering end
immutable ReverseOrdering{Fwd<:Ordering} <: Ordering
fwd::Fwd
end
ReverseOrdering(rev::ReverseOrdering) = rev.fwd
ReverseOrdering{Fwd}(fwd::Fwd) = ReverseOrdering{Fwd}(fwd)
typealias DirectOrdering Union{ForwardOrdering,ReverseOrdering{ForwardOrdering}}
const Forward = ForwardOrdering()
const Reverse = ReverseOrdering(Forward)
immutable LexicographicOrdering <: Ordering end
const Lexicographic = LexicographicOrdering()
immutable By{T} <: Ordering
by::T
end
immutable Lt{T} <: Ordering
lt::T
end
immutable Perm{O<:Ordering,V<:AbstractVector} <: Ordering
order::O
data::V
end
Perm{O<:Ordering,V<:AbstractVector}(o::O,v::V) = Perm{O,V}(o,v)
lt(o::ForwardOrdering, a, b) = isless(a,b)
lt(o::ReverseOrdering, a, b) = lt(o.fwd,b,a)
lt(o::By, a, b) = isless(o.by(a),o.by(b))
lt(o::Lt, a, b) = o.lt(a,b)
lt(o::LexicographicOrdering, a, b) = lexcmp(a,b) < 0
function lt(p::Perm, a::Integer, b::Integer)
da = p.data[a]
db = p.data[b]
lt(p.order, da, db) | (!lt(p.order, db, da) & (a < b))
end
function lt(p::Perm{LexicographicOrdering}, a::Integer, b::Integer)
c = lexcmp(p.data[a], p.data[b])
c != 0 ? c < 0 : a < b
end
ordtype(o::ReverseOrdering, vs::AbstractArray) = ordtype(o.fwd, vs)
ordtype(o::Perm, vs::AbstractArray) = ordtype(o.order, o.data)
# TODO: here, we really want the return type of o.by, without calling it
ordtype(o::By, vs::AbstractArray) = try typeof(o.by(vs[1])) catch; Any end
ordtype(o::Ordering, vs::AbstractArray) = eltype(vs)
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
end
end
|