Comparing head/tail indexes cannot distinguish between empty/full cases, so we end up wasting one item in the circular buffer. This also limits the smallest and efficient size choice to be 4. If the circular buffer is large, there's no issue, however for the motion planner the block size is significant, and I was planning to use exactly a ring buffer of two: one busy block, plus one planned. Modify the indexer to store the internal "index" (aka cursor) pointer to be one extra bit deeper than the final index. Comparing the underlying cursor allow to distinguish the empty/full case due to the extra bit, while producing the final index requires simple masking. This is just as efficient if the size is a power of two with 2-complement wrap-around logic, which is the optimized case. However the implementation also works for non-power-of-two sizes. Add tests for more failure cases in the CircularBuffer which is built on top. (tecnique described in the Art of Computer Programming by Knuth) |
||
|---|---|---|
| .. | ||
| circular_buffer | ||
| progmem | ||
| CMakeLists.txt | ||