Skip to content

DisjointIntervals type? #202

@weymouth

Description

@weymouth

Would it be helpful to add a type holding a tuple of disjoint intervals. I personally need this for my application and coded it up just using Tuples

Base.:\(a::Interval, b::Interval) = filter(r->r.leftr.right,mapreduce(bᶜ-> a  bᶜ, TupleTools.vcat, -b))
Base.:-(a::Interval) = ((-Inf .. a.left),(a.right .. Inf))
Base.:\(A::Tuple,b::Interval) = mapreduce(a -> a\b, TupleTools.vcat, A)
Base.:(A::Tuple,B::Tuple) = filter(!isempty,Tuple(a  b for a in A, b in B))
Base.:(A::Tuple, b::Interval) = foldl((a,b)->isempty(a  b) ? (a, b) : (a  b,), A; init=b)
Base.:\(A::Tuple,B::Tuple) = mapreduce(a -> foldl(\, B; init = a), TupleTools.vcat, A)

We could define a DisjointIntervals type and make these operators a bit more robust. Any interest in that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions