Skip to content

Instantly share code, notes, and snippets.

@ssfrr
Last active June 2, 2017 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssfrr/03c6dc2e41bc1e15c57dd86b0bf96382 to your computer and use it in GitHub Desktop.
Save ssfrr/03c6dc2e41bc1e15c57dd86b0bf96382 to your computer and use it in GitHub Desktop.
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