Last active
June 2, 2017 03:30
-
-
Save ssfrr/03c6dc2e41bc1e15c57dd86b0bf96382 to your computer and use it in GitHub Desktop.
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
julia> struct DupVector{T} <: AbstractVector{T} | |
A::Vector{T} | |
end | |
julia> Base.size(dv::DupVector) = size(dv.A) .* 2 | |
julia> @inline function Base.getindex(dv::DupVector, idx) | |
@boundscheck checkbounds(dv, idx) | |
dv.A[div(idx+1, 2)] | |
end | |
julia> testindex(v, i) = @inbounds return v[i] | |
testindex (generic function with 1 method) | |
julia> dv = DupVector([3, 7, 6, 1]) | |
8-element DupVector{Int64}: | |
3 | |
3 | |
7 | |
7 | |
6 | |
6 | |
1 | |
1 | |
julia> testindex(dv, 9) | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment