CloseOpenIntervals

Documentation for CloseOpenIntervals.

CloseOpenIntervals.AbstractCloseOpen โ€” Type
CloseOpen([start=0], U) <: AbstractUnitRange{Int}
SafeCloseOpen([start=0], U) <: AbstractUnitRange{Int}

Define close-open unit ranges, i.e. CloseOpen(0,10) iterates from from 0:9. Close-open ranges can be more convenient in some circumstances, e.g. when partitioning a larger array.


function foo(x)
  nt = Threads.nthreads()
  d, r = divrem(length(x), nt)
  i = firstindex(x)
  Threads.@sync for j in 1:nt
    stop = i + d + (r >= j)
    Threads.@spawn bar!($(@view(x[CloseOpen(i, stop)])))
    i = stop
  end
end

This saves a few -1s on the ends of the ranges if using a normal unit range.

SafeCloseOpen will not iterate if U <= start, while CloseOpen doesn't check for this, and thus the behavior is undefined in that case.

CloseOpenIntervals.CloseOpen โ€” Type
CloseOpen([start=0], U) <: AbstractUnitRange

Iterates over the range start:U-1. Guaranteed to iterate at least once, skipping initial empty check. See ?AbstractCloseOpen for more information.

CloseOpenIntervals.SafeCloseOpen โ€” Type
SafeCloseOpen([start=0], U) <: AbstractUnitRange

Iterates over the range start:U-1. Will not iterate if it isempty, like a typical range, making it generally the preferred choice over CloseOpen. See ?AbstractCloseOpen for more information.