diff --git a/NEWS.md b/NEWS.md index b512e2c1b363b..429084fb4e451 100644 --- a/NEWS.md +++ b/NEWS.md @@ -362,9 +362,14 @@ This section lists changes that do not have deprecation warnings. trait; see its documentation for details. Types which support subtraction (operator `-`) must now implement `widen` for hashing to work inside heterogeneous arrays. + * `AbstractSet` objects are now considered equal by `==` and `isequal` if all of their + elements are equal ([#25368]). This has required changing the hashing algorithm + for `BitSet`. + * `findn(x::AbstractVector)` now return a 1-tuple with the vector of indices, to be consistent with higher order arrays ([#25365]). + Library improvements -------------------- diff --git a/base/bitset.jl b/base/bitset.jl index 1fe60771a13b7..9f9f4f1dbb94b 100644 --- a/base/bitset.jl +++ b/base/bitset.jl @@ -326,7 +326,7 @@ function _check0(a::Vector{UInt64}, b::Int, e::Int) true end -function issetequal(s1::BitSet, s2::BitSet) +function ==(s1::BitSet, s2::BitSet) # Swap so s1 has always the smallest offset if s1.offset > s2.offset s1, s2 = s2, s1 @@ -356,7 +356,7 @@ function issetequal(s1::BitSet, s2::BitSet) return true end -⊆(a::BitSet, b::BitSet) = a == intersect(a,b) +issubset(a::BitSet, b::BitSet) = a == intersect(a,b) ⊊(a::BitSet, b::BitSet) = a <= b && a != b diff --git a/base/set.jl b/base/set.jl index 972ada8638149..c8cee2bdbe866 100644 --- a/base/set.jl +++ b/base/set.jl @@ -261,9 +261,9 @@ function symdiff!(s::AbstractSet, itr) s end +==(l::AbstractSet, r::AbstractSet) = length(l) == length(r) && l ⊆ r # convenience functions for AbstractSet -# (if needed, only their synonyms issetequal, ⊊ and ⊆ must be specialized) -==(l::AbstractSet, r::AbstractSet) = issetequal(l, r) +# (if needed, only their synonyms ⊊ and ⊆ must be specialized) <( l::AbstractSet, r::AbstractSet) = l ⊊ r <=(l::AbstractSet, r::AbstractSet) = l ⊆ r @@ -284,7 +284,7 @@ julia> issubset([1, 2, 3], [1, 2]) false ``` """ -function ⊆(l, r) +function issubset(l, r) for elt in l if !in(elt, r) return false @@ -295,7 +295,7 @@ end # use the implementation below when it becoms as efficient # issubset(l, r) = all(_in(r), l) -const issubset = ⊆ +const ⊆ = issubset """ issetequal(a, b) @@ -313,6 +313,7 @@ true ``` """ issetequal(l, r) = length(l) == length(r) && l ⊆ r +issetequal(l::AbstractSet, r::AbstractSet) = l == r ⊊(l, r) = length(l) < length(r) && l ⊆ r ⊈(l, r) = !⊆(l, r)