🔁Circular 💾Buffer

by Ricardo “Rudxain” Fernández Serrata

Version 1 (September 26, 2023)

Download (76 downloads)

This may improve performance when using an array as a FIFO queue buffer. Instead of using Add(x, -1) and Remove(x, 0), it keeps the array at a fixed length and replaces values cyclically, kinda like a "sawtooth waveform".

The 2nd loop shouldn't be necessary, but I used it because it was easier and I tried MULTIPLE different ways of avoiding that loop.

The `length` var is necessary if you want to resize the buffer. But I haven't coded a proper resizing mechanism. If you increase the size, more "room" will be made for new values instead of old values. If you decrease the size, original new values will be ignored instead of old values. The proper way of resizing requires the internal buffer to use reversed indexing.

I could have used `? :` instead of `%` operator, because values are never added in bulk. But conditional reset is more prone to bugs and executes branch operations which could be slower than `%` op.

ℹ en.wikipedia.org/wiki/Circular_buffer

Rudxain profile: llamalab.com/automate/community/flows/42921

LICENSE: https://unlicense.org

4.7 average rating from 3 reviews

5 stars
2
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.