Introduction
StaticRanges
StaticRanges.DynamicAxis
StaticRanges.GapRange
StaticRanges.MutableRange
StaticRanges.StaticRange
StaticRanges.find_first
StaticRanges.find_last
StaticRanges.grow_end
StaticRanges.grow_end!
StaticRanges.DynamicAxis
— TypeDynamicAxis(n::Int)
A range spanning 1
to n
by steps of 1
. The value of n
can be changed after construction, but cannot be any less than 0
.
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 Vector{Int64}:
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
StaticRanges.MutableRange
— TypeMutableRange(r::AbstractRange)
Wraps a parent range making it mutable.
StaticRanges.StaticRange
— TypeStaticRange{T,R}
Wraps a range parametrically, making it static.
julia> using StaticRanges
julia> StaticRange(1:10)
static(1:10)
julia> StaticRange{Float64}(1.0:1:10)
static(1.0:1.0:10.0)
StaticRanges.find_first
— Methodfind_first(predicate::Function, A)
Return the index or key of the first element of A for which predicate returns true. Return nothing if there is no such element.
Indices or keys are of the same type as those returned by keys(A) and pairs(A).
Examples
julia> using StaticRanges
julia> A = [1, 4, 2, 2];
julia> find_first(iseven, A)
2
julia> find_first(x -> x>10, A) # returns nothing, but not printed in the REPL
julia> find_first(isequal(4), A)
2
julia> find_first(iseven, [1 4; 2 2])
CartesianIndex(2, 1)
StaticRanges.find_last
— Methodfind_last(predicate::Function, A)
Return the index or key of the last element of A for which predicate returns true. Return nothing if there is no such element.
Indices or keys are of the same type as those returned by keys(A) and pairs(A).
Examples
julia> using StaticRanges
julia> find_last(iseven, [1, 4, 2, 2])
4
julia> find_last(x -> x>10, [1, 4, 2, 2]) # returns nothing, but not printed in the REPL
julia> find_last(isequal(4), [1, 4, 2, 2])
2
julia> find_last(iseven, [1 4; 2 2])
CartesianIndex(2, 2)
StaticRanges.grow_end!
— Methodgrow_end!
StaticRanges.grow_end
— Methodgrow_end
"Find" Functions
"find" methods (findall
, findfirst
, findlast
, filter
, and count
) for operators that can produce fixed methods (e.g., <(1) -> Base.Fix2(<, 1)
) have been optimized. This includes <
, <=
, >
, >=
, ==
, and !=
operators.
For example, find_all
is able to preserve ranges as opposed to findall
.
julia> @btime findall(<(5), $fr)
142.072 ns (3 allocations: 208 bytes)
2-element Array{Int64,1}:
1
2
julia> @btime find_all(<(5), $fr)
0.027 ns (0 allocations: 0 bytes)
1:2
julia> r = 1:10
1:10
julia> mr = MutableRange(r)
UnitMRange(1:10)
julia> findall(or(<(4), >(12)), mr)
7-element Vector{Int64}:
1
2
3
7
8
9
10
julia> find_all(or(<(4), >(6)), r)
7-element GapRange{Int64, UnitRange{Int64}, UnitRange{Int64}}:
1
2
3
7
8
9
10
julia> @btime filter(or(<(4), >(6)), $r)
124.496 ns (3 allocations: 320 bytes)
7-element Vector{Int64}:
1
2
3
7
8
9
10
julia> @btime filter(or(<(4), >(6)), $mr)
72.911 ns (3 allocations: 208 bytes)
7-element Vector{Int64,1}:
1
2
3
7
8
9
10