@@ -79,6 +79,42 @@ function Base.push!(cb::CircularArrayBuffer{T, N}, data) where {T,N}
7979 cb
8080end
8181
82+ function Base. append! (cb:: CircularArrayBuffer{T, N} , data) where {T,N}
83+ d, r = divrem (length (data) , cb. step_size)
84+ @assert r == 0
85+ if length (data) >= length (cb. buffer)
86+ cb. nframes = capacity (cb)
87+ cb. first = 1
88+ cb. buffer[:] .= @view data[end - length (cb. buffer)+ 1 : end ]
89+ else
90+ start_idx = (cb. first- 1 ) * cb. step_size + length (cb) + 1
91+ end_idx = start_idx + length (data) - 1
92+ if start_idx > length (cb. buffer)
93+ start_idx -= length (cb. buffer)
94+ end_idx -= length (cb. buffer)
95+ end
96+ if end_idx > length (cb. buffer)
97+ n_first_part = length (cb. buffer)- start_idx+ 1
98+ n_second_part = length (data) - n_first_part
99+ cb. buffer[end - n_first_part+ 1 : end ] .= @view data[1 : n_first_part]
100+ cb. buffer[1 : n_second_part] .= @view data[end - n_second_part+ 1 : end ]
101+ else
102+ cb. buffer[start_idx: end_idx] .= data
103+ end
104+
105+ if cb. nframes + d > capacity (cb)
106+ cb. first += cb. nframes + d - capacity (cb)
107+ if cb. first > capacity (cb)
108+ cb. first -= capacity (cb)
109+ end
110+ cb. nframes = capacity (cb)
111+ else
112+ cb. nframes += d
113+ end
114+ end
115+ cb
116+ end
117+
82118function Base. pop! (cb:: CircularArrayBuffer{T, N} ) where {T,N}
83119 if cb. nframes <= 0
84120 throw (ArgumentError (" buffer must be non-empty" ))
0 commit comments