Open Grinion opened 1 year ago
Be careful with just setting the tail to 0
!
When popping items from the front, the head gets incremented and when pushing to the back, the tail incremented. This is done in a wrapping way, so if the tail ever passes u32::MAX
, it will start again at 0
.
Because of that, the invariant for an empty Deque
is not tail == 0
, it is head == tail
(if you never pop from / push to the front, those conditions are the same).
For that reason, I don't want to expose the setter functions (way too easy to mess up), but a clear
function seems like something we should have
Problem
We have a lot of records in ### Deque. We want to clear all records from Deque In our cases we don't need to clear the data on the blockchain, we can overwrite it
Solution
I suggest adding a method clear for soft delete that sets Tail to 0.
OR
Change visibility methods from private to public
Temporary Solution
Now, I need to do it manually through the code