Order Functions
Optimized for Order
StaticRanges.ordmax
— Functionordmax(x) = ordmax(x, order(x))
ordmax(x::T, ::Ordering) -> T
Finds the maximum of x
using information about its ordering.
StaticRanges.ordmin
— Functionordmin(x) = ordmin(x, order(x))
ordmin(x::T, ::Ordering) -> T
Finds the minimum of x
using information about its ordering.
StaticRanges.find_max
— Functionfind_max(x)
Returns the index of the maximum value for x
. Differes from findmax
by accounting for any sorting.
StaticRanges.find_min
— Functionfind_min(x)
Returns the index of the minimum value for x
. Differes from findmin
by accounting for any sorting.
StaticRanges.is_within
— Functionis_within(x, y) -> Bool
Returns true
if all of x
is found within y
.
StaticRanges.gtmax
— Functiongtmax(x, y) -> Bool
Returns true
if the maximum of x
is greater than that of y
.
StaticRanges.ltmax
— Functionltmax(x, y) -> Bool
Returns true
if the maximum of x
is less than that of y
.
StaticRanges.eqmax
— Functioneqmax(x, y) -> Bool
Returns true
if the maximum of x
and y
are equal.
StaticRanges.gtmin
— Functiongtmin(x, y) -> Bool
Returns true
if the minimum of x
is greater than that of y
.
StaticRanges.ltmin
— Functionltmin(x, y) -> Bool
Returns true
if the minimum of x
is less than that of y
.
StaticRanges.eqmin
— Functioneqmin(x, y) -> Bool
Returns true
if the minimum of x
and y
are equal.
StaticRanges.group_max
— Functiongroup_max(x, y[, z...])
Returns the maximum value of all collctions.
StaticRanges.group_min
— Functiongroup_min(x, y[, z...])
Returns the minimum value of all collctions.
StaticRanges.cmpmax
— Functioncmpmax(x, y)
StaticRanges.cmpmin
— Functioncmpmin(x, y)
StaticRanges.min_of_group_max
— Functionmin_of_group_max(x, y)
Returns the minimum of maximum of x
and y
. Functionally equivalent to min(maximum(x), maximum(y))
but uses trait information about ordering for improved performance.
StaticRanges.max_of_group_min
— Functionmax_of_group_min(x, y)
Returns the maximum of minimum of x
and y
. Functionally equivalent to max(minimum(x), minimum(y))
but uses trait information about ordering for improved performance.
Search and Sort
Order traits
Internally it provides an intermediate structure for chaining functions an arbitrary number of functions.
julia> fxn1 = <(4) | >(8)
(::StaticRanges.ChainedFix{typeof(|),Base.Fix2{typeof(<),Int64},Base.Fix2{typeof(>),Int64}}) (generic function with 3 methods)
julia> fxn2 = <(4) | >(8) & iseven
(::StaticRanges.ChainedFix{typeof(|),Base.Fix2{typeof(<),Int64},StaticRanges.ChainedFix{typeof(&),Base.Fix2{typeof(>),Int64},typeof(iseven)}}) (generic function with 3 methods)
julia> fxn1(10)
true
julia> fxn1(11)
true
julia> fxn2(10)
true
julia> fxn2(11)
false
This becomes particularly useful when trying to preserve a range in a type stable manner. Without knowing the specific functions that compose the conditional operator in findall
at compile time it's impossible to determine whether the output should be a continuous range or discrete vector.
julia> findall(i -> >(4)(i) & <(8)(i), fr)
2-element Array{Int64,1}:
3
4
julia> find_all(>(4) & <(8), fr)
3:4
StaticRanges.find_first
— Functionfind_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
— Functionfind_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.merge_sort
— Functionmerge_sort(x, y)
Merge's and collections x
, and y
, while accounting for their sorting.
StaticRanges.vcat_sort
— Functionvcat_sort(x, y)
Returns a sorted concatenation of x
and y
.
Examples
julia> using StaticRanges
julia> StaticRanges.vcat_sort(1:10) # it's already sorted, nothing happens
1:10
julia> StaticRanges.vcat_sort([3, 1, 2, 5]) # sort unordered collection
4-element Array{Int64,1}:
1
2
3
5
julia> StaticRanges.vcat_sort([3, 4, 5], [1, 2, 5])
6-element Array{Int64,1}:
1
2
3
4
5
5