Skip to content

Commit

Permalink
Prep for breaking package up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokazama committed Apr 14, 2020
1 parent f91efcf commit 1805c36
Show file tree
Hide file tree
Showing 30 changed files with 304 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StaticRanges"
uuid = "d8176aec-3168-11e9-3c98-e3954798be3a"
authors = ["zchristensen "]
version = "0.6.4"
version = "0.6.5"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# StaticRanges

[![Build Status](https://travis-ci.com/Tokazama/StaticRanges.jl.svg?branch=master)](https://travis-ci.com/Tokazama/StaticRanges.jl)
[![codecov](https://codecov.io/gh/Tokazama/StaticRanges.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/Tokazama/StaticRanges.jl)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://Tokazama.github.io/StaticRanges.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://Tokazama.github.io/StaticRanges.jl/dev)

Expand Down
17 changes: 17 additions & 0 deletions src/Find/Find.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

include("findin.jl")
include("findvalue.jl")
include("find_firsteq.jl")
include("find_firstgt.jl")
include("find_firstlt.jl")
include("find_firstgteq.jl")
include("find_firstlteq.jl")
include("find_lasteq.jl")
include("find_lastgt.jl")
include("find_lastlt.jl")
include("find_lastgteq.jl")
include("find_lastlteq.jl")
include("findall.jl")
include("findlast.jl")
include("findfirst.jl")

40 changes: 40 additions & 0 deletions src/Find/find_firsteq.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

"""
find_firsteq(val, collection)
Return the first index of `collection` where the element is equal to `val`.
If no element of `collection` is equal to `val`, `nothing` is returned.
"""
function find_firsteq(x, r::AbstractRange)
if !in(x, r)
return nothing
else
return unsafe_findvalue(x, r)
end
end

find_firsteq(x, r::OneToUnion) = _find_firsteq_oneto(x, r)

function _find_firsteq_oneto(x::Integer, r)
if (x < 1) | (x > last(r))
return nothing
else
return x
end
end

function _find_firsteq_oneto(x, r)
idx = round(Integer, x)
if idx == x
return _find_firsteq_oneto(idx, r)
else
return nothing
end
end

function find_firsteq(x, a)
for (i, a_i) in pairs(a)
x == a_i && return i
end
return nothing
end
9 changes: 9 additions & 0 deletions src/find_firstgt.jl → src/Find/find_firstgt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

"""
find_firstgt(val, collection)
Return the first index of `collection` where the element is greater than `val`.
If no element of `collection` is greater than `val`, `nothing` is returned.
"""
function find_firstgt end


###
### OneToUnion
###
Expand Down
9 changes: 9 additions & 0 deletions src/find_firstgteq.jl → src/Find/find_firstgteq.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

"""
find_firstgteq(val, collection)
Return the first index of `collection` where the element is greater than or equal
to `val`. If no element of `collection` is greater than or equal to `val`, `nothing`
is returned.
"""
function find_firstgteq end

###
### OneToUnion
###
Expand Down
8 changes: 8 additions & 0 deletions src/find_firstlt.jl → src/Find/find_firstlt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

"""
find_firstlt(val, collection)
Return the first index of `collection` where the element is less than `val`.
If no element of `collection` is less than `val`, `nothing` is returned.
"""
function find_firstlt end

@inline function find_firstlt(x, r::AbstractUnitRange)
if (first(r) >= x) | isempty(r)
return nothing
Expand Down
10 changes: 10 additions & 0 deletions src/find_firstlteq.jl → src/Find/find_firstlteq.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

"""
find_firstlteq(val, collection)
Return the first index of `collection` where the element is less than or equal to
`val`. If no element of `collection` is less than or equal to `val`, `nothing`
is returned.
"""
function find_firstlteq end


@inline function find_firstlteq(x, r::OneToUnion)
if (r.stop == 0) | (1 > x)
return nothing
Expand Down
8 changes: 8 additions & 0 deletions src/find_lasteq.jl → src/Find/find_lasteq.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

"""
find_lasteq(val, collection)
Return the last index of `collection` where the element is equal to `val`.
If no element of `collection` is equal to `val`, `nothing` is returned.
"""
function find_lasteq end

# should be the same for unique sorted vectors like ranges
find_lasteq(x, r::AbstractRange) = find_firsteq(x, r)

Expand Down
8 changes: 8 additions & 0 deletions src/find_lastgt.jl → src/Find/find_lastgt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

"""
find_lastgt(val, collection)
Return the last index of `collection` where the element is greater than `val`.
If no element of `collection` is greater than `val`, `nothing` is returned.
"""
function find_lastgt end

@inline function find_lastgt(x, r::AbstractUnitRange)
if isempty(r) | (last(r) <= x)
return nothing
Expand Down
9 changes: 9 additions & 0 deletions src/find_lastgteq.jl → src/Find/find_lastgteq.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

"""
find_lastgteq(val, collection)
Return the last index of `collection` where the element is greater than or equal
to `val`. If no element of `collection` is greater than or equal to `val`, `nothing`
is returned.
"""
function find_lastgteq end

@inline function find_lastgteq(x, r::AbstractUnitRange)
if last(r) < x
return nothing
Expand Down
9 changes: 9 additions & 0 deletions src/find_lastlt.jl → src/Find/find_lastlt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

"""
find_lastlt(val, collection)
Return the last index of `collection` where the element is less than `val`.
If no element of `collection` is less than `val`, `nothing` is returned.
"""
function find_lastlt end


@inline function find_lastlt(x, r::AbstractUnitRange)
idx = unsafe_findvalue(x, r)
if firstindex(r) > idx
Expand Down
10 changes: 10 additions & 0 deletions src/find_lastlteq.jl → src/Find/find_lastlteq.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

"""
find_lastlteq(val, collection)
Return the last index of `collection` where the element is less than or equal to
`val`. If no element of `collection` is less than or equal to`val`, `nothing` is
returned.
"""
function find_lastlteq end


function find_lastlteq(x, r::AbstractUnitRange)
if last(r) <= x
return lastindex(r)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 3 additions & 21 deletions src/StaticRanges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using Base.Broadcast: DefaultArrayStyle
using Dates

using StaticArrays
using StaticArrays: Dynamic

using ArrayInterface
using ArrayInterface: can_setindex
Expand Down Expand Up @@ -131,12 +130,10 @@ export
include("./GapRange/GapRange.jl")

include("chainedfix.jl")
using .ChainedFixes

include("continuity.jl")
include("order.jl")
include("findall.jl")
include("findlast.jl")
include("findfirst.jl")

include("onetorange.jl")
include("unitrange.jl")
include("abstractsteprange.jl")
Expand Down Expand Up @@ -259,30 +256,15 @@ mrange

include("merge.jl")
include("intersect.jl")
include("findin.jl")
include("broadcast.jl")
include("operators.jl")
include("getindex.jl")
include("findvalue.jl")
include("pop.jl")
include("push.jl")
include("show.jl")
include("vcat.jl")

include("find_firsteq.jl")
include("find_firstgt.jl")
include("find_firstlt.jl")
include("find_firstgteq.jl")
include("find_firstlteq.jl")

include("find_lasteq.jl")
include("find_lastgt.jl")
include("find_lastlt.jl")
include("find_lastgteq.jl")
include("find_lastlteq.jl")

include("resize.jl")

include("offset_range.jl")
include("./Find/Find.jl")

end
1 change: 1 addition & 0 deletions src/abstractsteprangelen.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

"""
gethi(x:: TwicePrecision{T}) -> T
Expand Down
20 changes: 20 additions & 0 deletions src/chainedfix.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@

module ChainedFixes

using Base: Fix2

export
ChainedFix,
BitAnd,
BitOr,
Fix2Lt,
Fix2Eq,
F2LtAndLtEq,
F2GtAndGtEq,
F2IsLess,
or,
,
and,

struct ChainedFix{L,F1,F2} <: Function
link::L
f1::F1
Expand Down Expand Up @@ -82,3 +101,4 @@ const F2LtAndLtEq{T} = Fix2{<:Union{typeof(<),typeof(<=)},T}
const F2GtAndGtEq{T} = Fix2{<:Union{typeof(>),typeof(>=)},T}
const F2IsLess{T} = Fix2{<:Union{typeof(isless),typeof(<)},T}

end
14 changes: 0 additions & 14 deletions src/find_firsteq.jl

This file was deleted.

16 changes: 16 additions & 0 deletions src/first.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@

struct First{F} end

Base.show(io::IO, ::First{F}) where {F} = print(io, "First(", F, ")")

Base.get(::First{F}) where {F} = F

First(::Type{OneToSRange{T,L}}) where {T,L} = First{one(T)}()
First(::Type{OneToMRange{T}}) where {T,L} = First{one(T)}()
First(::Type{OneTo{T}}) where {T,L} = First{one(T)}()
First(::Type{UnitSRange{T,F,L}}) where {T,F,L} = First{F}()
First(::Type{StepSRange{T,Ts,F,S,L}}) where {T,Ts,F,S,L} = First{F}()
First(::Type{LinSRange{T,F,E,L,D}}) where {T,F,E,L,D} = First{F}()
# TODO StepSRangeLen


### first(x)
Base.first(::OneToRange{T}) where {T} = one(T)

Expand Down Expand Up @@ -135,3 +150,4 @@ function set_offset!(r::StepMRangeLen, val::Int)
return r
end
set_offset!(r::StepMRangeLen, val) = set_offset!(r, Int(val))

14 changes: 14 additions & 0 deletions src/last.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@

struct Last{L} end

Base.show(io::IO, ::Last{L}) where {L} = print(io, "Last(", L, ")")

Base.get(::Last{L}) where {L} = L

Last(::Type{OneToSRange{T,L}}) where {T,L} = Last{L}()
Last(::Type{UnitSRange{T,F,L}}) where {T,F,L} = Last{L}()
Last(::Type{StepSRange{T,Ts,F,S,L}}) where {T,Ts,F,S,L} = Last{L}()
Last(::Type{LinSRange{T,F,E,L,D}}) where {T,F,E,L,D} = Last{L}()
# TODO StepSRangeLen

Last(::Type{T}) where {T} = Last{Dynamic()}()

Base.last(::OneToSRange{T,E}) where {T,E} = E

Base.last(r::OneToMRange) = getfield(r, :stop)
Expand Down
15 changes: 15 additions & 0 deletions src/length.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@

StaticArrays.Length(::Type{OneToSRange{T,L}}) where {T,L} = Length{Int(L)}()

StaticArrays.Length(::Type{LinSRange{T,B,E,L,D}}) where {T,B,E,L,D} = Length{L}()

function StaticArrays.Length(::Type{UnitSRange{T,F,L}}) where {T<:Union{UInt,UInt64,UInt128},F,L}
return Length{L < F ? 0 : Int(Base.Checked.checked_add(L - F, one(T)))}()
end

function StaticArrays.Length(::Type{UnitSRange{T,F,L}}) where {T<:Union{Int,Int64,Int128},F,L}
return Length{Int(Base.Checked.checked_add(Base.Checked.checked_sub(L, F), one(T)))}()
end



Base.length(r::OneToMRange) = Int(last(r))

Base.length(r::OneToSRange{T,L}) where {T,L} = Int(L)
Expand Down Expand Up @@ -172,3 +186,4 @@ function set_lendiv!(r::LinMRange, d::Int)
setfield!(r, :lendiv, d)
return r
end

1 change: 1 addition & 0 deletions src/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,4 @@ same_type(::Type{X}, ::Type{Y}) where {X<:LinSRange,Y<:LinSRange} = true
same_type(::Type{X}, ::Type{Y}) where {X<:StepSRangeLen,Y<:StepSRangeLen} = true
same_type(::Type{X}, ::Type{X}) where {X} = true
same_type(::Type{X}, ::Type{Y}) where {X,Y} = false

14 changes: 14 additions & 0 deletions src/step.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@

struct Step{S} end

Base.show(io::IO, ::Step{S}) where {S} = print(io, "First(", S, ")")

Base.get(::Step{S}) where {S} = S

Step(::Type{<:AbstractUnitRange{T}}) where {T} = Step{one(T)}()
Step(::Type{StepSRange{T,Ts,F,S,L}}) where {T,Ts,F,S,L} = Step{S}()
#Step(::Type{LinSRange{T,F,E,L,D}}) where {T,F,E,L,D} = First{F}()
# TODO StepSRangeLen


### OneToRange
Base.step(::OneToRange{T}) where {T} = one(T)

Expand Down Expand Up @@ -109,3 +122,4 @@ end
set_step(r::StepRangeLen, st) = StepRangeLen(r.ref, st, r.len, r.offset)
set_step(r::StepMRangeLen, st) = StepMRangeLen(r.ref, st, r.len, r.offset)
set_step(r::StepSRangeLen, st) = StepSRangeLen(r.ref, st, r.len, r.offset)

Loading

2 comments on commit 1805c36

@Tokazama
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/12922

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:

git tag -a v0.6.5 -m "<description of version>" 1805c36e60eb4c91a9623389816038a035804af5
git push origin v0.6.5

Please sign in to comment.