1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00
ReCo.jl/src/PreVectors.jl
2022-03-19 23:11:03 +01:00

35 lines
632 B
Julia

module PreVectors
export PreVector, push!, reset!, iterate
import Base: push!, iterate
mutable struct PreVector{T}
last_ind::UInt64
v::Vector{T}
PreVector{T}(n_particles) where {T} = new{T}(UInt64(0), Vector{T}(undef, n_particles))
end
function push!(pv::PreVector{T}, x::T) where {T}
pv.last_ind += 1
pv.v[pv.last_ind] = x
return nothing
end
function reset!(pv::PreVector)
pv.last_ind = 0
return nothing
end
function iterate(pv::PreVector, state::UInt64=UInt64(1))
if state > pv.last_ind
return nothing
else
return (pv.v[state], state + 1)
end
end
end # module