1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-09-19 19:01:17 +00:00
ReCo.jl/src/PreVector.jl

30 lines
567 B
Julia
Raw Normal View History

2021-12-02 23:37:43 +00:00
import Base: push!, iterate
2021-11-10 14:41:04 +00:00
mutable struct PreVector{T}
last_ind::UInt64
v::Vector{T}
2021-12-10 02:16:18 +00:00
PreVector{T}(n_particles) where {T} = new{T}(UInt64(0), Vector{T}(undef, n_particles))
2021-11-10 14:41:04 +00:00
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{T}) where {T}
pv.last_ind = 0
return nothing
end
2021-11-16 21:26:08 +00:00
function iterate(pv::PreVector{T}, state=1) where {T}
if state > pv.last_ind
return nothing
else
return (pv.v[state], state + 1)
end
2021-11-17 18:47:05 +00:00
end