Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add soft delete to Deque #57

Open
Grinion opened this issue Sep 23, 2023 · 1 comment
Open

Add soft delete to Deque #57

Grinion opened this issue Sep 23, 2023 · 1 comment

Comments

@Grinion
Copy link

Grinion commented Sep 23, 2023

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

tail
head
set_tail
set_head

Temporary Solution

Now, I need to do it manually through the code

let full_key = namespaces_with_key(&["players".as_bytes()], b"t");
ctx.deps.storage.set(&full_key, &(0 as u32).to_be_bytes());
@chipshort
Copy link
Collaborator

chipshort commented Sep 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants