Giter Club home page Giter Club logo

Comments (6)

terasakisatoshi avatar terasakisatoshi commented on June 20, 2024 1

@juliohm Cc @Vexatos

Here is what I did:

Add the following methods in src/CircularArrays.jl.

Ref: https://github.com/JuliaArrays/OffsetArrays.jl/blob/6090bf49114ef86d122fc131a8bdb251d19aea3b/src/OffsetArrays.jl#L604-L608

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

from circulararrays.jl.

juliohm avatar juliohm commented on June 20, 2024

Thank you @terasakisatoshi!

@Vexatos is this a valid approach to be merged as a PR?

from circulararrays.jl.

Vexatos avatar Vexatos commented on June 20, 2024

Since I already have deleteat! and insert! as mutating methods, these should probably exist as well.

from circulararrays.jl.

juliohm avatar juliohm commented on June 20, 2024

@terasakisatoshi it would be nice to convert your comment to a PR 💯

from circulararrays.jl.

terasakisatoshi avatar terasakisatoshi commented on June 20, 2024

I found that when Base.resize!(A::CircularVector, nl::Integer) = (resize!(parent(A), nl); A) is defined, we can use push!.

from circulararrays.jl.

Vexatos avatar Vexatos commented on June 20, 2024

This is now available in Version 1.4.0.

from circulararrays.jl.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.