queue
to store the stream values.window_sum
to store the sum of the last size
elements.next(val)
method, append val
to queue
.val
to window_sum
.queue
exceeds size
, subtract the oldest value from window_sum
and remove it from queue
.window_sum
by the minimum of the window size or the length of queue
.