SMFSW / Queue

Queue handling library (designed on Arduino)
BSD 3-Clause "New" or "Revised" License
97 stars 20 forks source link

get the minimal value in a queue #15

Closed aliceesiee closed 2 years ago

aliceesiee commented 2 years ago

Hello,

I would like to get the minimal value of a queue, because I am trying to modify this code https://github.com/Seeed-Studio/Seeed_Arduino_Linechart/blob/master/examples/basic/basic.ino I thought about writing a for loop with an if loop inside to compare each element but I don't manage to get the value inside the queue. I have tried like the vectors data[i] where data is a std::queue type and i the index.

Does anyone could give me some help?

Best regards,

Alice

SMFSW commented 2 years ago

Hello,

Well, you can probably make a loop (limited to q.nbRecs) as you said using q.peekIdx method to get every values to check. But... a queue is not a list of elements, it is designed to be used as FIFO or LIFO, thus you can peek records to see if new record has to be stored in the queue, but you can't remove a record at any desired index. Some kind of workaround for you would be flushing the whole queue (with q.flush), or if in need of a circular buffer, using FIFO implementation with overwrite=true might work too (without the need to pull items from queue).

Please keep in mind an issue tracker is not a place to ask for implementation help (there are lots of forums for that (eg. stack exchange)) but to raise bugs/issues or ask for improvements / new functionalities.

Regards, SMFSW

aliceesiee commented 2 years ago

Thanks for the answer and sorry for the misusing of the issue tracker !

SMFSW commented 2 years ago

Glad if I was able to help!

If needed, my libraries includes a contact email in README.md.

Closing the issue for now,

Regards, SMFSW