Skip to content

Commit

Permalink
make == the "primary" operator and add NEWS
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Jan 7, 2018
1 parent ddebc08 commit 08a3a30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
4 changes: 2 additions & 2 deletions base/bitset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
9 changes: 5 additions & 4 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 08a3a30

Please sign in to comment.