circular-queue icon indicating copy to clipboard operation
circular-queue copied to clipboard

Add in `reserve_exact` and `truncate`

Open CosmicHorrorDev opened this issue 3 years ago • 2 comments

Adding in reserve_exact and truncate would allow the circular queue to be resized. This behavior was brought up in cjbassi/ytop#96 where circular-queue would be a good choice: however, resizing would be required and the most ergonimic way I can find to do this would be to create a new circular queue and copying over all the old elements.

Would you be open to reserve_exact and truncate being added?

CosmicHorrorDev avatar Aug 02 '20 19:08 CosmicHorrorDev

So, the way CircularQueue works does indeed mean that the simplest (the only safe?) method of resizing in the general case is creating a new vector and moving the elements over. I would be open to introducing those methods into CircularQueue.

Should it be reserve or reserve_exact or maybe some other name? On a Vec, both of them say the resulting capacity will actually be >= the requested capacity...

YaLTeR avatar Aug 03 '20 12:08 YaLTeR

I thought the difference between reserve and reserve_exact was that reserve_exact would only reserve enough for the additional amount, but I see that that is not the case. I think that reserve should be just fine instead of reserve_exact and makes it easy for people to find coming from Vec or other collections to understand the purpose.

CosmicHorrorDev avatar Aug 03 '20 15:08 CosmicHorrorDev