-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This creates operation specific find methods internally and implements supporting methods for manipulating ranges. There's also a more thorough testing of inference.
- Loading branch information
Showing
43 changed files
with
1,785 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
name = "StaticRanges" | ||
uuid = "d8176aec-3168-11e9-3c98-e3954798be3a" | ||
authors = ["zchristensen "] | ||
version = "0.5.12" | ||
version = "0.6.0" | ||
|
||
[deps] | ||
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" | ||
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
|
||
[compat] | ||
ArrayInterface = "2" | ||
IntervalSets = "0.4" | ||
OffsetArrays = "1" | ||
StaticArrays = "0.12.1" | ||
julia = "1" | ||
|
||
[extras] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" | ||
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test", "Dates", "Documenter", "IntervalSets"] | ||
test = ["Test", "Dates", "Documenter", "IntervalSets", "OffsetArrays", "StaticArrays"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
@propagate_inbounds function find_firsteq(x, r::AbstractRange) | ||
@boundscheck if !in(x, r) | ||
return nothing | ||
end | ||
return unsafe_findvalue(x, r) | ||
end | ||
|
||
function find_firsteq(x, a) | ||
for (i, a_i) in pairs(a) | ||
x == a_i && return i | ||
end | ||
return nothing | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
find_firstgt(x, r::OneToUnion) = _find_firstgt_oneto(x, r) | ||
|
||
@inline function _find_firstgt_oneto(x::Integer, r) | ||
if x >= last(r) | ||
return nothing | ||
elseif x < 1 | ||
return 1 | ||
else | ||
return x + 1 | ||
end | ||
end | ||
|
||
@inline function _find_firstgt_oneto(x, r) | ||
idx = round(Integer, x, RoundUp) | ||
if idx > x | ||
if idx < 1 | ||
return nothing | ||
elseif idx >= last(r) | ||
return 1 | ||
else | ||
return idx | ||
end | ||
else | ||
return _find_firstgt_oneto(idx, r) | ||
end | ||
end | ||
|
||
find_firstgt(x, r::AbstractUnitRange) = _find_firstgt_unit(x, r) | ||
|
||
@inline function _find_firstgt_unit(x::Integer, r) | ||
if x >= last(r) | ||
return nothing | ||
elseif x < first(r) | ||
return firstindex(r) | ||
else | ||
# b/c +1 get's to the value isequal and we want greater | ||
return (x - first(r)) + 2 | ||
end | ||
end | ||
|
||
@inline function _find_firstgt_unit(x, r) | ||
xnew = round(Integer, x, RoundUp) | ||
if xnew > x | ||
if xnew >= lastindex(r) | ||
return nothing | ||
elseif xnew < firstindex(r) | ||
return firstindex(r) | ||
else | ||
return unsafe_findvalue(xnew, r) | ||
end | ||
else | ||
return _find_firstgt_unit(xnew, r) | ||
end | ||
end | ||
|
||
@inline function find_firstgt(x, r::AbstractRange{T}) where {T} | ||
if step(r) > zero(T) | ||
idx = unsafe_findvalue(x, r) | ||
if idx < firstindex(r) | ||
return firstindex(r) | ||
elseif idx > lastindex(r) | ||
return nothing | ||
elseif (@inbounds(r[idx]) == x) & (idx != lastindex(r)) | ||
return idx + oneunit(idx) | ||
else | ||
return nothing | ||
end | ||
elseif step(r) < zero(T) | ||
idx = unsafe_findvalue(x, r) | ||
if idx > lastindex(r) | ||
return lastindex(r) | ||
elseif idx < firstindex(r) | ||
return nothing | ||
elseif (@inbounds(r[idx]) == x) & (idx != firstindex(r)) | ||
return idx - oneunit(idx) | ||
else | ||
return nothing | ||
end | ||
else # isempty(r) | ||
return nothing | ||
end | ||
end | ||
|
||
function find_firstgt(x, a) | ||
for (i, a_i) in pairs(a) | ||
a_i > x && return i | ||
end | ||
return nothing | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
find_firstgteq(x, r::AbstractUnitRange) = _find_firstgteq_unit(x, r) | ||
function _find_firstgteq_unit(x::Integer, r) | ||
if x > last(r) | ||
return nothing | ||
elseif x < first(r) | ||
return firstindex(r) | ||
else | ||
return unsafe_findvalue(x, r) | ||
end | ||
end | ||
|
||
function _find_firstgteq_unit(x, r) | ||
if last(r) < x | ||
return nothing | ||
elseif first(r) > x | ||
return firstindex(r) | ||
else | ||
return _find_firstgteq_unit(round(Integer, x, RoundUp), r) | ||
end | ||
end | ||
|
||
@inline function find_firstgteq(x, r::AbstractRange{T}) where {T} | ||
if step(r) > zero(T) | ||
idx = unsafe_findvalue(x, r) | ||
if lastindex(r) < idx | ||
return nothing | ||
elseif firstindex(r) > idx | ||
return firstindex(r) | ||
elseif @inbounds(r[idx]) == x | ||
return idx | ||
else | ||
return idx + oneunit(idx) | ||
end | ||
elseif step(r) < zero(T) | ||
if first(r) >= x | ||
return firstindex(r) | ||
else | ||
return nothing | ||
end | ||
else # isempty(r) | ||
return nothing | ||
end | ||
end | ||
|
||
function find_firstgteq(x, a) | ||
for (i, a_i) in pairs(a) | ||
a_i >= x && return i | ||
end | ||
return nothing | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
@inline function find_firstlt(x, r::AbstractUnitRange) | ||
if first(r) >= x | ||
return nothing | ||
else | ||
return firstindex(r) | ||
end | ||
end | ||
|
||
@inline function find_firstlt(x, r::AbstractRange{T}) where {T} | ||
if step(r) > zero(T) | ||
if first(r) >= x | ||
return nothing | ||
else | ||
return firstindex(r) | ||
end | ||
elseif step(r) < zero(T) | ||
idx = unsafe_findvalue(x, r) | ||
if lastindex(r) <= idx | ||
return nothing | ||
elseif firstindex(r) > idx | ||
return firstindex(r) | ||
elseif @inbounds(r[idx]) < x | ||
return idx | ||
else | ||
return idx + oneunit(idx) | ||
end | ||
else | ||
return nothing | ||
end | ||
end | ||
|
||
function find_firstlt(x, a) | ||
for (i, a_i) in pairs(a) | ||
a_i < x && return i | ||
end | ||
return nothing | ||
end | ||
|
Oops, something went wrong.
8017458
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
8017458
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/12145
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: