2021-12-15 20:50:18 +01:00
|
|
|
module PreVectors
|
|
|
|
|
|
|
|
export PreVector, push!, reset!, iterate
|
|
|
|
|
2021-12-03 00:37:43 +01:00
|
|
|
import Base: push!, iterate
|
|
|
|
|
2021-11-10 15:41:04 +01:00
|
|
|
mutable struct PreVector{T}
|
|
|
|
last_ind::UInt64
|
|
|
|
v::Vector{T}
|
|
|
|
|
2021-12-10 03:16:18 +01:00
|
|
|
PreVector{T}(n_particles) where {T} = new{T}(UInt64(0), Vector{T}(undef, n_particles))
|
2021-11-10 15:41:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function push!(pv::PreVector{T}, x::T) where {T}
|
|
|
|
pv.last_ind += 1
|
|
|
|
pv.v[pv.last_ind] = x
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
2022-01-18 02:17:52 +01:00
|
|
|
function reset!(pv::PreVector)
|
2021-11-10 15:41:04 +01:00
|
|
|
pv.last_ind = 0
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
2021-11-16 22:26:08 +01:00
|
|
|
|
2022-01-18 02:17:52 +01:00
|
|
|
function iterate(pv::PreVector, state::UInt64=UInt64(1))
|
2021-11-16 22:26:08 +01:00
|
|
|
if state > pv.last_ind
|
|
|
|
return nothing
|
|
|
|
else
|
|
|
|
return (pv.v[state], state + 1)
|
|
|
|
end
|
2021-11-17 19:47:05 +01:00
|
|
|
end
|
2021-12-15 20:50:18 +01:00
|
|
|
|
2022-03-19 23:11:03 +01:00
|
|
|
end # module
|