From b756a7a25b28a35256aa8defe7a42da7f759841f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:24:09 -0400 Subject: [PATCH 1/4] add 1-arg methods for set comparisons --- base/abstractset.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/base/abstractset.jl b/base/abstractset.jl index 5d0d65dad2de6..a2eea18c29bf5 100644 --- a/base/abstractset.jl +++ b/base/abstractset.jl @@ -351,7 +351,8 @@ hasfastin(::Union{Type{<:AbstractSet},Type{<:AbstractDict},Type{<:AbstractRange} hasfastin(x) = hasfastin(typeof(x)) ⊇(a, b) = b ⊆ a - +issubset(a) = Fix2(issubset, a) +⊇(a) = Fix1(issubset, a) ## strict subset comparison function ⊊ end @@ -380,6 +381,8 @@ false ⊊(a, b::AbstractSet) = Set(a) ⊊ b ⊊(a, b) = Set(a) ⊊ Set(b) ⊋(a, b) = b ⊊ a +⊋(a) = Fix2(⊋, a) +⊊(a) = Fix2(⊊, a) function ⊈ end function ⊉ end @@ -404,6 +407,8 @@ false ⊈(a, b) = !⊆(a, b) ⊉(a, b) = b ⊈ a +⊉(a) = Fix2(⊉, a) +⊈(a) = Fix2(⊈, a) ## set equality comparison @@ -441,6 +446,8 @@ function issetequal(a, b) return issetequal(Set(a), Set(b)) end +issetequal(a) = Fix2(issetequal, a) + ## set disjoint comparison """ isdisjoint(a, b) -> Bool @@ -487,6 +494,8 @@ function isdisjoint(a::AbstractRange{T}, b::AbstractRange{T}) where T end end +isdisjoint(a) = Fix2(isdisjoint, a) + _overlapping_range_isdisjoint(a::AbstractRange{T}, b::AbstractRange{T}) where T = invoke(isdisjoint, Tuple{Any,Any}, a, b) function _overlapping_range_isdisjoint(a::AbstractRange{T}, b::AbstractRange{T}) where T<:Integer From 1144a43015bacd7b1b7a46297de878c3389bd13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:39:39 -0400 Subject: [PATCH 2/4] add tests for 1-arg forms of set comparisons --- test/sets.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/sets.jl b/test/sets.jl index 65444153c90d9..ebdcad1c8c563 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -364,7 +364,9 @@ end @test issubset(intersect(l,r), r) @test issubset(l, union(l,r)) @test issubset(r, union(l,r)) + @test issubset(union(l,r))(r) @test isdisjoint(l,l) == isempty(l) + @test isdisjoint(l)(l) == isempty(l) @test isdisjoint(l,r) == isempty(intersect(l,r)) if S === Vector @test sort(union(intersect(l,r),symdiff(l,r))) == sort(union(l,r)) @@ -381,6 +383,15 @@ end @test ⊋(S([1,2]), S([1])) @test !⊋(S([1]), S([1])) @test ⊉(S([1]), S([2])) + + @test ⊆(S([1,2]))(S([1])) + @test ⊊(S([1,2]))(S([1])) + @test !⊊(S([1]))(S([1])) + @test ⊈(S([2]))(S([1])) + @test ⊇(S([1]))(S([1,2])) + @test ⊋(S([1]))(S([1,2])) + @test !⊋(S([1]))(S([1])) + @test ⊉(S([2]))(S([1])) end let s1 = S([1,2,3,4]) @test s1 !== symdiff(s1) == s1 @@ -837,6 +848,8 @@ end @test !(B ⊉ A) @test !issetequal(A, B) @test !issetequal(B, A) + @test !issetequal(B)(A) + @test !issetequal(A)(B) for T = (Tuple, identity, Set, BitSet, Base.IdSet{Int}) @test issetequal(A, T(A)) @test issetequal(B, T(B)) From 415351d313c3b4e7e1346311bf41cb9ffb8b383f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Fri, 11 Aug 2023 22:50:39 -0400 Subject: [PATCH 3/4] add docs --- base/abstractset.jl | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/base/abstractset.jl b/base/abstractset.jl index a2eea18c29bf5..680bb76cadb0e 100644 --- a/base/abstractset.jl +++ b/base/abstractset.jl @@ -351,7 +351,31 @@ hasfastin(::Union{Type{<:AbstractSet},Type{<:AbstractDict},Type{<:AbstractRange} hasfastin(x) = hasfastin(typeof(x)) ⊇(a, b) = b ⊆ a + +""" + issubset(x) + +Create a function that compares its argument to `x` using [`issubset`](@ref), i.e. +a function equivalent to `y -> issubset(y, x)`. +The returned function is of type `Base.Fix2{typeof(issubset)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" issubset(a) = Fix2(issubset, a) + +""" + ⊇(x) + +Create a function that compares its argument to `x` using [`issubset`](@ref), i.e. +a function equivalent to `y -> issubset(x, y)`. +The returned function is of type `Base.Fix1{typeof(issubset)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" ⊇(a) = Fix1(issubset, a) ## strict subset comparison @@ -381,7 +405,30 @@ false ⊊(a, b::AbstractSet) = Set(a) ⊊ b ⊊(a, b) = Set(a) ⊊ Set(b) ⊋(a, b) = b ⊊ a + +""" + ⊋(x) + +Create a function that compares its argument to `x` using [`⊋`](@ref), i.e. +a function equivalent to `y -> y ⊋ x`. +The returned function is of type `Base.Fix2{typeof(⊋)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" ⊋(a) = Fix2(⊋, a) +""" + ⊊(x) + +Create a function that compares its argument to `x` using [`⊊`](@ref), i.e. +a function equivalent to `y -> y ⊊ x`. +The returned function is of type `Base.Fix2{typeof(⊊)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" ⊊(a) = Fix2(⊊, a) function ⊈ end @@ -407,7 +454,31 @@ false ⊈(a, b) = !⊆(a, b) ⊉(a, b) = b ⊈ a + +""" + ⊉(x) + +Create a function that compares its argument to `x` using [`⊉`](@ref), i.e. +a function equivalent to `y -> y ⊉ x`. +The returned function is of type `Base.Fix2{typeof(⊉)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" ⊉(a) = Fix2(⊉, a) + +""" + ⊈(x) + +Create a function that compares its argument to `x` using [`⊈`](@ref), i.e. +a function equivalent to `y -> y ⊈ x`. +The returned function is of type `Base.Fix2{typeof(⊈)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" ⊈(a) = Fix2(⊈, a) ## set equality comparison @@ -446,6 +517,17 @@ function issetequal(a, b) return issetequal(Set(a), Set(b)) end +""" + issetequal(x) + +Create a function that compares its argument to `x` using [`issetequal`](@ref), i.e. +a function equivalent to `y -> issetequal(y, x)`. +The returned function is of type `Base.Fix2{typeof(issetequal)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" issetequal(a) = Fix2(issetequal, a) ## set disjoint comparison @@ -494,6 +576,17 @@ function isdisjoint(a::AbstractRange{T}, b::AbstractRange{T}) where T end end +""" + isdisjoint(x) + +Create a function that compares its argument to `x` using [`isdisjoint`](@ref), i.e. +a function equivalent to `y -> isdisjoint(y, x)`. +The returned function is of type `Base.Fix2{typeof(isdisjoint)}`, which can be +used to implement specialized methods. + +!!! compat "Julia 1.11" + This functionality requires at least Julia 1.11. +""" isdisjoint(a) = Fix2(isdisjoint, a) _overlapping_range_isdisjoint(a::AbstractRange{T}, b::AbstractRange{T}) where T = invoke(isdisjoint, Tuple{Any,Any}, a, b) From 25485e2bba293b1ad9fce30972f3c2df09616e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:38:26 -0400 Subject: [PATCH 4/4] =?UTF-8?q?Fix1{typeof(issubset)}=20->=20Fix2{typeof(?= =?UTF-8?q?=E2=8A=87)}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/abstractset.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/abstractset.jl b/base/abstractset.jl index 680bb76cadb0e..9ea8d58c49999 100644 --- a/base/abstractset.jl +++ b/base/abstractset.jl @@ -368,15 +368,15 @@ issubset(a) = Fix2(issubset, a) """ ⊇(x) -Create a function that compares its argument to `x` using [`issubset`](@ref), i.e. -a function equivalent to `y -> issubset(x, y)`. -The returned function is of type `Base.Fix1{typeof(issubset)}`, which can be +Create a function that compares its argument to `x` using [`⊇`](@ref), i.e. +a function equivalent to `y -> y ⊇ x`. +The returned function is of type `Base.Fix2{typeof(⊇)}`, which can be used to implement specialized methods. !!! compat "Julia 1.11" This functionality requires at least Julia 1.11. """ -⊇(a) = Fix1(issubset, a) +⊇(a) = Fix2(⊇, a) ## strict subset comparison function ⊊ end