-
Notifications
You must be signed in to change notification settings - Fork 480
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
SkipMap::compare_insert is not a CAS operation if the key is not present. #1167
Comments
Could you elaborate on the behavior you are hoping for? If the key does not exist, what do you want it to be compared to? |
If the key is not exist, is it possible to skip the insert? If there is nothing to compare, it shouldn't do the swap. |
Add more details about the use case I am about to implement with the compare_insert. We use skipmap as the underlying in memory data structure to store some data. And we are trying to achieve the similar CAS operation as in tikv. https://docs.rs/tikv-client/latest/tikv_client/struct.RawClient.html#method.compare_and_swap pseudo code for the behavior i am hoping for:
|
I'm not sure how take Option<&V> solves this. Adding a variable is feasible, but I'm not sure if it's better to not insert if the key doesn't exist. Traditional CAS doesn't deal with missing keys. Maybe it would be better to return an Err in this case? |
I was thinking a closure that takes
However, that might be an idea that would complicate the API. |
From the documentation, it appears that SkipMap::compare_insert directly inserts the value without invoking the closure function if the key is absent. This behavior does not align with a true CAS (Compare-And-Swap) operation, as it bypasses the condition check against the old value, even when the key is not present.
Is it possible to do a CAS operation with the closure function called that includes cases where the key is absent?
The text was updated successfully, but these errors were encountered: