Skip to content

Commit

Permalink
Add @findmyway's feedback from previous PR
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiahpslewis committed Mar 27, 2024
1 parent 7f5965f commit b882431
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/CircularArrayBuffers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Base.isempty(cb::CircularArrayBuffer) = cb.nframes == 0
"""
_buffer_index(cb::CircularArrayBuffer, i::Int)
Return the index of the `i`-th element in the buffer.
Return the index of the `i`-th element in the buffer. Note the `i` is assumed to be the linear indexing of `cb`.
"""
@inline function _buffer_index(cb::CircularArrayBuffer, i::Int)
idx = (cb.first - 1) * cb.step_size + i
Expand All @@ -90,23 +90,23 @@ end
"""
wrap_index(idx, n)
Return the index of the `idx`-th element in the buffer, if index is one past the size, return 1, else error.
Return the index of the `idx`-th element in the buffer, if index is one past the size, return 1, else error.
"""
function wrap_index(idx, n)
if idx <= n
return idx
elseif idx <= 2n
return idx - n
else
@info "oops! idx $(idx) > 2n $(2n)"
@warn "oops! idx $(idx) > 2n $(2n)"
return idx - n
end
end

"""
_buffer_frame(cb::CircularArrayBuffer, i::Int)
Return the index of the `i`-th frame in the buffer.
Here `i` is assumed to be the last dimension of `cb`. Each `frame` means a slice of the last dimension. Since we use *circular frames* (the `data` buffer) underlying, this function transforms the logical `i`-th frame to the real frame of the internal buffer.
"""
@inline function _buffer_frame(cb::CircularArrayBuffer, i::Int)
n = capacity(cb)
Expand Down

0 comments on commit b882431

Please sign in to comment.