Skip to content

Commit

Permalink
use < and <= for the partial order on Set and IntSet
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 8, 2014
1 parent c85b103 commit 5cc0b7d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions base/intset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,5 @@ function isequal(s1::IntSet, s2::IntSet)
end

issubset(a::IntSet, b::IntSet) = isequal(a, intersect(a,b))
<(a::IntSet, b::IntSet) = (a<=b) && !isequal(a,b)
<=(a::IntSet, b::IntSet) = issubset(a, b)
2 changes: 1 addition & 1 deletion base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function setdiff(a::Set, b::Set)
end

isequal(l::Set, r::Set) = (length(l) == length(r)) && (l <= r)
isless(l::Set, r::Set) = (length(l) < length(r)) && (l <= r)
<(l::Set, r::Set) = (length(l) < length(r)) && (l <= r)
<=(l::Set, r::Set) = issubset(l, r)

function issubset(l, r)
Expand Down
8 changes: 4 additions & 4 deletions test/collections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ d = (String => String)[ a => "foo" for a in ["a","b","c"]]
@test !isempty(Set("banana", "apple"))
@test !isempty(Set(1, 1:10, "pear"))

# isless
@test isless(Set(), Set(1))
@test isless(Set(1), Set(1,2))
@test !isless(Set(3), Set(1,2))
# ordering
@test Set() < Set(1)
@test Set(1) < Set(1,2)
@test !(Set(3) < Set(1,2))
@test !(Set(3) > Set(1,2))
@test Set(1,2,3) > Set(1,2)
@test !(Set(3) <= Set(1,2))
Expand Down

0 comments on commit 5cc0b7d

Please sign in to comment.