Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,8 @@ function isequal(A::AbstractArray, B::AbstractArray)
end

function cmp(A::AbstractVector, B::AbstractVector)
ai1, bi1 = firstindex(A), firstindex(B)
isequal(ai1, bi1) || return cmp(ai1, bi1)
for (a, b) in zip(A, B)
if !isequal(a, b)
return isless(a, b) ? -1 : 1
Expand All @@ -3040,7 +3042,8 @@ end
"""
isless(A::AbstractVector, B::AbstractVector)

Return `true` when `A` is less than `B` in lexicographic order.
Return `true` when `A` is less than `B`. Vectors are first compared by
their starting indices, and then lexicographically by their elements.
"""
isless(A::AbstractVector, B::AbstractVector) = cmp(A, B) < 0

Expand Down
12 changes: 12 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,18 @@ end
@test cmp([UInt8(1), UInt8(0)], [UInt8(0), UInt8(0)]) == 1
@test cmp([UInt8(1), UInt8(0)], [UInt8(1), UInt8(0)]) == 0
@test cmp([UInt8(0), UInt8(0)], [UInt8(1), UInt8(1)]) == -1

x = [1, 2, 3]
y = OffsetVector(x, -1)
@test cmp(x, y) == 1
@test cmp(y, x) == -1
@test !isless(x, y)
@test isless(y, x)

y2 = OffsetVector([1, 2, 3], 0)
@test cmp(x, y2) == 0
@test !isless(x, y2)
@test !isless(y2, x)
end

@testset "sort on arrays" begin
Expand Down