Skip to content

Commit 310667b

Browse files
authored
Merge pull request #25420 from JuliaLang/jb/cmpissues
fix some issues with `cmp` and `isless`
2 parents aaa77ae + ada8b06 commit 310667b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

base/abstractarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ function isequal(A::AbstractArray, B::AbstractArray)
15481548
return true
15491549
end
15501550

1551-
function cmp(A::AbstractArray, B::AbstractArray)
1551+
function cmp(A::AbstractVector, B::AbstractVector)
15521552
for (a, b) in zip(A, B)
15531553
if !isequal(a, b)
15541554
return isless(a, b) ? -1 : 1
@@ -1557,7 +1557,7 @@ function cmp(A::AbstractArray, B::AbstractArray)
15571557
return cmp(length(A), length(B))
15581558
end
15591559

1560-
isless(A::AbstractArray, B::AbstractArray) = cmp(A, B) < 0
1560+
isless(A::AbstractVector, B::AbstractVector) = cmp(A, B) < 0
15611561

15621562
function (==)(A::AbstractArray, B::AbstractArray)
15631563
if axes(A) != axes(B)

base/linalg/adjtrans.jl

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ similar(A::AdjOrTrans, ::Type{T}, dims::Dims{N}) where {T,N} = similar(A.parent,
116116
parent(A::AdjOrTrans) = A.parent
117117
vec(v::AdjOrTransAbsVec) = v.parent
118118

119+
cmp(A::AdjOrTransAbsVec, B::AdjOrTransAbsVec) = cmp(parent(A), parent(B))
120+
isless(A::AdjOrTransAbsVec, B::AdjOrTransAbsVec) = isless(parent(A), parent(B))
119121

120122
### concatenation
121123
# preserve Adjoint/Transpose wrapper around vectors

base/strings/basic.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ one(::Union{T,Type{T}}) where {T<:AbstractString} = convert(T, "")
223223
"""
224224
cmp(a::AbstractString, b::AbstractString) -> Int
225225
226-
Compare two strings for equality. Return `0` if both strings have the same
227-
length and the character at each index is the same in both strings. Return `-1`
228-
if `a` is a substring of `b`, or if `a` comes before `b` in alphabetical order.
229-
Return `1` if `b` is a substring of `a`, or if `b` comes before `a` in
230-
alphabetical order (technically, lexicographical order by Unicode code points).
226+
Compare two strings. Return `0` if both strings have the same length and the character
227+
at each index is the same in both strings. Return `-1` if `a` is a prefix of `b`, or if
228+
`a` comes before `b` in alphabetical order. Return `1` if `b` is a prefix of `a`, or if
229+
`b` comes before `a` in alphabetical order (technically, lexicographical order by Unicode
230+
code points).
231231
232232
# Examples
233233
```jldoctest

0 commit comments

Comments
 (0)