simplify union
Codecov Report
Merging #113 (52d628e) into master (b3f0d6e) will decrease coverage by
0.16%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #113 +/- ##
==========================================
- Coverage 98.81% 98.64% -0.17%
==========================================
Files 3 3
Lines 253 222 -31
==========================================
- Hits 250 219 -31
Misses 3 3
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/interval.jl | 98.86% <100.00%> (-0.30%) |
:arrow_down: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
Anything wrong with this PR? It nicely gets rid of all those special cases.
Behavior doesn't change at all, as evidenced by no test changes. Just stumbled across this piece of code when fixing https://github.com/JuliaMath/IntervalSets.jl/pull/112.
I have checked some benchmarks, there weren't any degressions.
I found some type instability, but this is the same behavior as on the current master.
julia> @code_warntype (1 .. 3) ∪ (2.0 .. 5.0)
MethodInstance for union(::ClosedInterval{Int64}, ::ClosedInterval{Float64})
from union(d1::IntervalSets.TypedEndpointsInterval, d2::IntervalSets.TypedEndpointsInterval) in IntervalSets at /home/hyrodium/.julia/dev/IntervalSets/src/interval.jl:126
Arguments
#self#::Core.Const(union)
d1::ClosedInterval{Int64}
d2::ClosedInterval{Float64}
Body::Union{ClosedInterval{Float64}, ClosedInterval{Int64}}
1 ── %1 = IntervalSets.isempty(d1)::Bool
└─── goto #3 if not %1
2 ── return d2
3 ── %4 = IntervalSets.isempty(d2)::Bool
└─── goto #5 if not %4
4 ── return d1
5 ── %7 = (∈)(d1)::Base.Fix2{typeof(in), ClosedInterval{Int64}}
│ %8 = IntervalSets.endpoints(d2)::Tuple{Float64, Float64}
│ %9 = IntervalSets.any(%7, %8)::Bool
└─── goto #7 if not %9
6 ── goto #10
7 ── %12 = (∈)(d2)::Base.Fix2{typeof(in), ClosedInterval{Float64}}
│ %13 = IntervalSets.endpoints(d1)::Tuple{Int64, Int64}
│ %14 = IntervalSets.any(%12, %13)::Bool
└─── goto #9 if not %14
8 ── goto #10
9 ── %17 = IntervalSets.ArgumentError("Cannot construct union of disjoint sets.")::Any
└─── IntervalSets.throw(%17)
10 ┄ %19 = IntervalSets._union(d1, d2)::ClosedInterval{Float64}
└─── return %19
Note that there is no this type instability with intersect.