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 faf5045 commit d3302c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ 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`.


Library improvements
--------------------

Expand Down
2 changes: 1 addition & 1 deletion 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
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 d3302c3

Please sign in to comment.