-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add superset function #42
Conversation
src/interval.jl
Outdated
""" | ||
superset(intervals::AbstractArray{<:AbstractInterval}) -> Interval | ||
|
||
Create a single interval which encompasses all of the provided intervals. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be worthwhile to mention that this is the smallest such interval?
src/interval.jl
Outdated
Create a single interval which encompasses all of the provided intervals. | ||
""" | ||
function superset(intervals::AbstractArray{<:AbstractInterval}) | ||
left = minimum(Intervals.LeftEndpoint.(intervals)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be more efficient to only make one pass over the array by providing the function as an argument to maximum
and minimum
, e.g.
left = minimum(LeftEndpoint, intervals)
right = maximum(RightEndpoint, intervals)
(Also note that the module prefix shouldn't be necessary within the module.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I was developing this in the REPL which is why I have the module prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it isn't more efficient:
julia> @btime superset([1..2, 4..5]) # minimum(LeftEndpoint.(intervals))
123.302 ns (5 allocations: 416 bytes)
Interval{Int64}(1, 5, Inclusivity(true, true))
julia> @btime superset([1..2, 4..5]) # minimum(LeftEndpoint, intervals)
1.363 μs (17 allocations: 640 bytes)
Interval{Int64}(1, 5, Inclusivity(true, true))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's... really weird. 🤔
src/deprecated.jl
Outdated
|
||
# BEGIN Intervals 0.1 deprecations | ||
|
||
@deprecate less_than_disjoint(a, b) is_less_than_disjoint(a, b) true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to reuse some Base terminology here and call it like isless_disjoint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is better. Do you think that greater_than_disjoint(a, b)
should be deprecated to isless_disjoint(b, a)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that seems reasonable.
Codecov Report
@@ Coverage Diff @@
## master #42 +/- ##
==========================================
+ Coverage 98.07% 98.12% +0.04%
==========================================
Files 6 6
Lines 208 213 +5
==========================================
+ Hits 204 209 +5
Misses 4 4
Continue to review full report at Codecov.
|
Tests pass on Julia 0.6. Looks like some breaking changes happened in 0.7 since #30 |
Looks like that was JuliaLang/julia#27302. |
Rebased on top of #43 which should address the 0.7 issues |
32-bit issues on AppVeyor with Coverage. Intervals test all pass. |
src/interval.jl
Outdated
""" | ||
≪(a::AbstractInterval, b::AbstractInterval) -> Bool | ||
less_than_disjoint(a::AbstractInterval, b::AbstractInterval) -> Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just change the reference here to isless_disjoint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up removing the reference here as there isn't a isgreater_disjoint
for the other docstring. Additionally, this specific docstring will only appear with help?> ≪
and not with help?> isless_disjoint
/ help?> less_than_disjoint
src/interval.jl
Outdated
@@ -228,26 +231,26 @@ end | |||
Base.:⊈(a::AbstractInterval, b::AbstractInterval) = !issubset(a, b) | |||
Base.:⊉(a::AbstractInterval, b::AbstractInterval) = !issubset(b, a) | |||
|
|||
function overlaps(a::AbstractInterval, b::AbstractInterval) | |||
function isoverlapping(a::AbstractInterval, b::AbstractInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think overlaps
is easier to read and has precedent with contains
as a predicate name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though contains
is deprecated in 0.7 in favor of occursin
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same deal with plural predicate though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Jeff's rule of thumb for 2-arg predicates is that it reads like English if the function is put between the arguments. To that end, a overlaps b
makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change these back. Mainly I was thinking about these after changing less_than_disjoint
to isless_disjoint
and was thinking these should also start with is
for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Votes are to leave this as overlaps
?
src/interval.jl
Outdated
left = max(LeftEndpoint(a), LeftEndpoint(b)) | ||
right = min(RightEndpoint(a), RightEndpoint(b)) | ||
|
||
return left <= right | ||
end | ||
|
||
function contiguous(a::AbstractInterval, b::AbstractInterval) | ||
function iscontiguous(a::AbstractInterval, b::AbstractInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is
implies a predicate with one value. I think contiguous
is fine but I don't have an issue with changing this. If you do change it, however, it should be arecontiguous
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based upon Alex's comment should this be contiguouswith
? For example a contiguouswith b
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively: adjacentto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to go with the "adjacent" terminology rather than "contiguous," I think adjacent
itself is a fine enough name. That said, I don't really have a problem with contiguous
, but I find continugouswith
to be a bit of a mouthful.
I'm going to move the "is" changes to another PR as they seem more controversial (see #45) |
superset
function that creates an interval which encompasses all of the intervals within an arrayRename interval check functions to start with "is" (with deprecations)Interval
constructor which takesEndpoint
s