Ensuring the value of a register monotonically increases or decreases #145
DaveLanday
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
In this case you are not getting anything by wrapping a LWWReg, it's best to write your own CRDT here. struct MaxReg<T: Ord>(T); // where merge is equivalent to std::cmp::max(...)
struct MinReg<T: Ord>(T); // where merge is equivalent to std::cmp::min(...) It would make a good addition to the library as it's one of the simplest CRDT's. If you'd like to add this, please send a PR and I can help on the review side. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to keep track of a value that should always increase, decrease, or remain the same when an update is applied or a merge takes place. It represents a best bound on some computation improving or tending toward an optimal value. Instead of re-writing or customizing the way a register CRDT changes its value, I was wondering: can I simply wrap an operation (or an entire register in the case of a CvRDT) in a
match
expression that handles updating the value of the register only if the value we want to change it to is greater than or equal to (or less than or equal to) the current value in the register?For example:
This works, but does it still have the guarantees provided by by the LWWReg CRDT?
Beta Was this translation helpful? Give feedback.
All reactions