How IntervalSets and UnitRanges compare in functionality?

IntervalSets.jl and UnitRanges

Both represent some intervals with start – end.

Both support operations on sets: in, union, intersect, and so on.

UnitRanges define indexing and iterator interface, which is not true sot IntervalSets, but it can be used for indexing with proper toindex transformation (see for example SampledSignals.jl indexed in seconds interval).

IntervalSets can have infinite elements. Ranges are always finite and have an optional step parameter, that defaults to one. But IntervalSets are also finite for some types, like ClosedInterval{Float64}(1,3)) – then it’s similar to 1:3 range.

So, looks like IntervalSets is an abstraction over UnitRanges for intervals of infinite number of elements?

1 Like

They don’t represent the same things.

julia> 2.5 in ClosedInterval{Float64}(1,3)
true

julia> 2.5 in 1:3
false

Intervals are not enumerable (… naturally)

5 Likes