Range Types
There are static and mutable versions of most ranges present in the Base
module of Julia. The basic terminology used herein is as follows:
- Static: fully parameterized through parametric typing (similar to how
Val
is used) - Fixed: all parameters are immutable fields of a
struct
. This is how all ranges inBase
are composed. - Dynamic: all parameters are mutable fields of a
struct
. This is how a handful of ranges in this package are composed.
The vast majority of the time a fixed range is the appropriate choice. There are some situations (perhaps few) where alternatives may be extremely convenient. For example, a static range may be helpful when the exact same parameters are frequently being accessed and don't need to change (e.g., a component of a filter in a processing pipeline). Mutable ranges may be helpful when referring to a range that is accessed rarely but may change (e.g., descriptive parameters of a plot's axis). However, this package is intentionally built without many assumptions of how it should be used. For example, safe methods for mutating ranges without violating the same assumptions of their original construction are provided but access to their fields are not obfuscated beyond overloading the setproperty!
method
Static Ranges
StaticRanges.OneToSRange
— TypeOneToSRange
A static range that parallels OneTo
in behavior.
StaticRanges.UnitSRange
— TypeUnitSRange
A static range parameterized by a start
and stop
of type T
, filled with elements spaced by 1
from start
until stop
is exceeded. The syntax a:b
with a
and b
both Integer
s creates a UnitRange
.
StaticRanges.LinSRange
— TypeLinSRange
A static range with len linearly spaced elements between its start and stop. The size of the spacing is controlled by len, which must be an Int.
StaticRanges.StepSRange
— TypeStepSRange
A static range with elements of type T
with spacing of type S
. The step between each element is constant, and the range is defined in terms of a start
and stop
of type T
and a step
of type S
. Neither T
nor S
should be floating point types.
StaticRanges.StepSRangeLen
— TypeStepSRangeLen
A static range r
where r[i]
produces values of type T
(in the second form, T
is deduced automatically), parameterized by a ref
erence value, a step
, and the len
gth. By default ref
is the starting value r[1]
, but alternatively you can supply it as the value of r[offset]
for some other index 1 <= offset <= len
. In conjunction with TwicePrecision
this can be used to implement ranges that are free of roundoff error.
Mutable Ranges
StaticRanges.OneToMRange
— TypeOneToMRange
A mutable range that parallels OneTo
in behavior.
StaticRanges.UnitMRange
— TypeUnitMRange
A mutable range parameterized by a start
and stop
of type T
, filled with elements spaced by 1
from start
until stop
is exceeded. The syntax a:b
with a
and b
both Integer
s creates a UnitRange
.
StaticRanges.LinMRange
— TypeLinMRange
A mutable range with len linearly spaced elements between its start and stop. The size of the spacing is controlled by len, which must be an Int.
StaticRanges.StepMRange
— TypeStepMRange
A mutable range with elements of type T
with spacing of type S
. The step between each element is constant, and the range is defined in terms of a start
and stop
of type T
and a step
of type S
. Neither T
nor S
should be floating point types.
StaticRanges.StepMRangeLen
— TypeStepMRangeLen
A mutable range r
where r[i]
produces values of type T
(in the second form, T
is deduced automatically), parameterized by a ref
erence value, a step
, and the len
gth. By default ref
is the starting value r[1]
, but alternatively you can supply it as the value of r[offset]
for some other index 1 <= offset <= len
. In conjunction with TwicePrecision
this can be used to implement ranges that are free of roundoff error.
Abstract Ranges
StaticRanges.OneToRange
— TypeOneToRange
Supertype for OneToSRange
and OneToMRange
. It's subtypes should behave identically to Base.OneTo
.
StaticRanges.AbstractLinRange
— TypeAbstractLinRange
Supertype for mutable or static ranges with len
linearly spaced elements between its start
and stop
.
StaticRanges.AbstractStepRangeLen
— TypeAbstractStepRangeLen
Supertype for StepSRangeLen
and StepMRangeLen
. It's subtypes should behave identically to StepRangeLen
.
StaticRanges.AbstractStepRange
— TypeAbstractStepRange
Supertype for StepSRange
and StepMRange
. It's subtypes should behave identically to StepRange
.
Special Ranges
StaticRanges.GapRange
— TypeGapRange{T,F,L}
Represents a range that is broken up by gaps making it noncontinuous. This allows more compact storage of numbers where the majority are known to be continuous.
Examples
julia> using StaticRanges
julia> findall(and(>(4), <(10)), 1:10)
5-element Array{Int64,1}:
5
6
7
8
9
julia> find_all(or(<(4), >(6)), 1:10)
7-element GapRange{Int64,UnitRange{Int64},UnitRange{Int64}}:
1
2
3
7
8
9
10