ArduinoRingBuffer icon indicating copy to clipboard operation
ArduinoRingBuffer copied to clipboard

add() (or new push()) that overwrites oldest?

Open Humancell opened this issue 6 years ago • 5 comments

I'm curious if there is a way to add an option to add(), or a new call (push()?) that would always add to the queue by "pushing" the oldest item out of the queue?

In the current implementation it appears that if we are adding and the buffer fills, we are forced to lose the "new" items. This works in two of our cases, but we have one where we want the "oldest" data to be lost so that the queue contains the latest {x} records.

Does this make sense? Thoughts?

Humancell avatar Jul 12 '19 22:07 Humancell

This version currently does not have that behavior, but I would definitely see the use case for this. Maybe this will fit your needs? https://github.com/wizard97/Embedded_RingBuf_CPP/issues/12

wizard97 avatar Jul 13 '19 02:07 wizard97

Yes ... your new feature would do what I am looking for:

bool addForce(const Type &obj)

Is this now a part of your next release?

Humancell avatar Jul 13 '19 14:07 Humancell

I don't currently have plans to add it, but you are welcome to add it in and submit a pull request.

wizard97 avatar Jul 16 '19 06:07 wizard97

Ok ... but I'm confused about what I am looking at (not as well versed at Github as I'd like to be) ... who wrote this code that you linked to, and can't you pull that into your project?

Humancell avatar Jul 16 '19 16:07 Humancell

I made both of these projects, they both do the same thing. This one uses only C, the other one takes advantage of C++ features.

I think it will just be easier for you if you use my other project (https://github.com/wizard97/Embedded_RingBuf_CPP). The add method has the following signature

bool add(const Type &obj, bool overwrite=false)

If you call this method with overwrite set to true, then this will overwrite the oldest element when the buffer is full.

wizard97 avatar Jul 17 '19 04:07 wizard97