SMFSW / Queue

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

Add method to peek last item in queue #12

Closed morcibacsi closed 4 years ago

morcibacsi commented 4 years ago

Hi,

I am using your (slightly modified) library on a project where I am using a FIFO queue. However before adding a new item I need to check if the last item in the queue has the same properties which I am trying to add. If yes I just don't add a new item. I was wondering if a peek_last() method is worth to be added to the main library (considering that with a LIFO queue it might not make much sense to have it)

Best regards

SMFSW commented 4 years ago

Hello,

thanks for your interest about Queue library.

I did not have to deal with such behavior since the creation of the library, but it happened in the past. I would even extend this enhancement to the whole queue by creating a method like peek_rec to peek any record in the queue (as you may also have to search in the whole queue for a duplicate record and making more sense for a LIFO implementation).

I think I could add a peek_previous() method as inline to do exactly what you want (for FIFO implementation).

I could also implement a method to drop any item in the queue, just because more peeking options would exist, but as I would like to keep the library straightforward and fluent as possible, I wouldn't plan to add these drop methods, only peeking on all records would be possible.

What do you think about it?

Thanks for giving thoughts about improving this library!

Regards, SMFSW

SMFSW commented 4 years ago

Changes made and exemples added...

Thanks for your thoughts/needs about enhancing this library, I (on behalf) of open source community thank you for it!

Just one thing before closing the issue, I would be really enjoying that you would test the changes and see if it fits your needs (using peekPrevious method) before tagging this new version...

Thanks a lot for the idea to improve this tiny library, making it more flexible to ones needs! Really appreciated, kind regards, SMFSW

morcibacsi commented 4 years ago

Thank you for the fast reply, and the generic implementation. I am going to test it and report back ASAP. Just please give me a few days. Thanks again for your work.

morcibacsi commented 4 years ago

Tested, and seems fine, closing the issue. Thanks for your patience.

SMFSW commented 4 years ago

@morcibacsi Thanks a lot for enhancement proposal and tests! New version is now tagged and should be available through Arduino library manager soon now.