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

Signature of KeyValue::Atomic::Increment #31

Open
karthik2804 opened this issue Dec 7, 2023 · 1 comment
Open

Signature of KeyValue::Atomic::Increment #31

karthik2804 opened this issue Dec 7, 2023 · 1 comment

Comments

@karthik2804
Copy link

Currently, the signature of the atomic increment is

increment: func(bucket: bucket, key: key, delta: u64) -> result<u64, error>;

I would like to understand the reasoning behind the delta argument and the return u64 types. This would not support cases where atomic decrement is desired. Would it be better for the types to be i64 to allow for flexibility?

@Mossaka
Copy link
Collaborator

Mossaka commented Dec 19, 2023

That's a good quetsion. Changing the delta and return value type to i64 indeeds give more flexibility and allows the increment operation to also behave as a decrement if the delta is a negative integer.

The reason behind choosing an u64 is that common usage scenarios like counters, timestamps are all positive and this ensures that the operation will not accidentally decreases the value.

Do you have an use case for decrementing?

Do you think adding a decrement function would be sufficient for your use case?

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