Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/circular_buffer.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
CircularBuffer{T}(v,n::Int)
CircularBuffer{T}(v, n::Int)

The CircularBuffer type implements a circular buffer of fixed capacity
where new items are pushed to the back of the list, overwriting values
Expand All @@ -14,29 +14,29 @@ mutable struct CircularBuffer{T} <: AbstractVector{T}
length::Int
buffer::Vector{T}

function CircularBuffer{T}(f,len,buf) where {T}
function CircularBuffer{T}(f::Int, len::Int, buf) where {T}
f <= length(buf) || throw(ArgumentError("Value of 'first' must be inbounds of buffer"))
len <= length(buf) || throw(ArgumentError("Value of 'length' must be <= length of buffer"))
return new{T}(length(buf), f, len, buf)
end

# Convert any `Integer` to whatever `Int` is on the relevant machine
CircularBuffer{T}(f::Integer, len::Integer, buf::Integer) where {T} = CircularBuffer{T}(Int(f), Int(len), Int(buf))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor could be removed entirely, as it was just never called in the previous version. However it seems that #893 decided to keep it

CircularBuffer{T}(f::Integer, len::Integer, buf) where {T} = CircularBuffer{T}(Int(f), Int(len), buf)
end

function CircularBuffer{T}(iter, capacity::Integer) where {T}
vec = copyto!(Vector{T}(undef,capacity), iter)
CircularBuffer{T}(1, length(iter),vec)
vec = copyto!(Vector{T}(undef, capacity), iter)
CircularBuffer{T}(1, length(iter), vec)
end

CircularBuffer(capacity::Integer) = CircularBuffer{Any}(capacity)

CircularBuffer{T}(capacity::Integer) where {T} = CircularBuffer{T}(T[],capacity)
CircularBuffer{T}(capacity::Integer) where {T} = CircularBuffer{T}(T[], capacity)

CircularBuffer(iter,capacity::Integer) = CircularBuffer{eltype(iter)}(iter,capacity)
CircularBuffer(iter, capacity::Integer) = CircularBuffer{eltype(iter)}(iter, capacity)

function CircularBuffer{T}(iter) where {T}
vec = reshape(collect(T,iter),:)
vec = reshape(collect(T, iter), :)
CircularBuffer{T}(1, length(vec), vec)
end
Comment on lines 27 to 41
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just formatting fixes


Expand Down
Loading