Closed juliohm closed 6 months ago
@juliohm Cc @Vexatos
Here is what I did:
Add the following methods in src/CircularArrays.jl
.
Base.resize!(A::CircularVector, nl::Integer) = (resize!(parent(A), nl); A)
Base.push!(a::CircularVector, x...) = (push!(parent(a), x...); a)
Base.pop!(a::CircularVector) = pop!(parent(a))
Base.append!(a::CircularVector, items) = (append!(parent(a), items); a)
Base.empty!(a::CircularVector) = (empty!(parent(a)); a)
Now we have
julia> using CircularArrays
julia> c = CircularVector([1,2,3])
3-element CircularVector(::Vector{Int64}):
1
2
3
julia> push!(c, 4)
4-element CircularVector(::Vector{Int64}):
1
2
3
4
julia> c
4-element CircularVector(::Vector{Int64}):
1
2
3
4
julia> push!(c, 6,7,8)
7-element CircularVector(::Vector{Int64}):
1
2
3
4
6
7
8
Thank you @terasakisatoshi!
@Vexatos is this a valid approach to be merged as a PR?
Since I already have deleteat!
and insert!
as mutating methods, these should probably exist as well.
@terasakisatoshi it would be nice to convert your comment to a PR 💯
I found that when Base.resize!(A::CircularVector, nl::Integer) = (resize!(parent(A), nl); A)
is defined, we can use push!
.
This is now available in Version 1.4.0.