Circular buffer package?

I am working on some code that processes vectors of data of length 6000 elements. When I detect specific criteria, I want to reprocess the last 100 vectors to extract finer details. Thus I want to store the data in a form of a FIFO “cache”, replacing the oldest data as I go.

I am thinking of using a circular buffer, but I’m not seeing a package that directly support it.

I see there is Ringbuffers.jl which wraps a C library. I don’t specifically want to use it as a FIFO with variable amount of data and thus the reading will not be simple pop in sequence (for example might need to fetch some of the data twice if 2 events are detected within 100 vectors of each other, thus I’m not sure if the read interfacing supported with Ringbuffers.jl will be limiting for my use case.

I also see FFTViews.jl which seems to implement a periodic indexing but come with a number of warnings about using it away from FFT.

My guess is either of them can be made to work, or creating a custom implementation might also not be too difficult.

Any thoughts or suggestions?
Thanks

https://juliacollections.github.io/DataStructures.jl/latest/circ_buffer/

3 Likes

Thanks

I believe my use case will benefit from being able to use negative indexing, similar to https://github.com/JuliaCollections/DataStructures.jl/pull/451

I see the CircularBuffer is a vector.

I was inspired by the idea in https://github.com/JuliaCollections/DataStructures.jl/pull/445/files where CircularVectorBuffer is defined to create a 2d-Array and I decided to utilize a custom N+1-dimensional array with limited functionality, although I suspect a CircularBuffer{Any} with elements Array{T,N} would have worked just as well for my use case.

what about CircularArrays.jl