Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juliareinforcementlearning/circulararraybuffers.jl
https://github.com/juliareinforcementlearning/circulararraybuffers.jl
circular-arrays circular-buffer data-structures julia
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/juliareinforcementlearning/circulararraybuffers.jl
- Owner: JuliaReinforcementLearning
- License: mit
- Created: 2020-11-24T14:32:56.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-29T08:36:16.000Z (9 months ago)
- Last Synced: 2024-04-13T21:20:22.554Z (9 months ago)
- Topics: circular-arrays, circular-buffer, data-structures, julia
- Language: Julia
- Homepage:
- Size: 44.9 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CircularArrayBuffers
[![Build Status](https://github.com/JuliaReinforcementLearning/CircularArrayBuffers.jl/workflows/CI/badge.svg)](https://github.com/JuliaReinforcementLearning/CircularArrayBuffers.jl/actions)
`CircularArrayBuffers.jl` is a small package to wrap an `AbstractArray` as a buffer along the last dimension. The main benefit compared to [`CircularBuffer`](https://juliacollections.github.io/DataStructures.jl/latest/circ_buffer/) in [`DataStructures.jl`](https://github.com/JuliaCollections/DataStructures.jl) is that the view of consecutive elements is a `SubArray`.
## Usage
```julia
julia> using CircularArrayBuffersjulia> names(CircularArrayBuffers)
5-element Array{Symbol,1}:
:CircularArrayBuffer
:CircularArrayBuffers
:CircularVectorBuffer
:capacity
:isfulljulia> a = CircularArrayBuffer(rand(2,3))
2×3 CircularArrayBuffer{Float64,2}:
0.0510714 0.0260738 0.0245707
0.856257 0.571643 0.0189365julia> b = CircularArrayBuffer{Float64}(2,3)
2×0 CircularArrayBuffer{Float64,2}julia> push!(b, rand(2))
2×1 CircularArrayBuffer{Float64,2}:
0.4215856115651755
0.5485806794787502julia> push!(b, rand(2))
2×2 CircularArrayBuffer{Float64,2}:
0.421586 0.640501
0.548581 0.774729julia> push!(b, rand(2))
2×3 CircularArrayBuffer{Float64,2}:
0.421586 0.640501 0.653054
0.548581 0.774729 0.902611julia> push!(b, rand(2))
2×3 CircularArrayBuffer{Float64,2}:
0.640501 0.653054 0.640373
0.774729 0.902611 0.227435julia> pop!(b)
2-element view(::CircularArrayBuffer{Float64,2}, :, 3) with eltype Float64:
0.6403725468830439
0.22743495787074597julia> b
2×2 CircularArrayBuffer{Float64,2}:
0.640501 0.653054
0.774729 0.902611julia> size(b)
(2, 2)julia> capacity(b)
3julia> isfull(b)
falsejulia> push!(b, rand(2))
2×3 CircularArrayBuffer{Float64,2}:
0.640501 0.653054 0.885887
0.774729 0.902611 0.0332439julia> isfull(b)
truejulia> eltype(b)
Float64
```