-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
CRDT datatype implementation #18046
base: master
Are you sure you want to change the base?
CRDT datatype implementation #18046
Conversation
g.increment_value(1) | ||
} | ||
|
||
// inc_val allows passing in an arbitrary delta to increment the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// inc_val allows passing in an arbitrary delta to increment the | |
// increment_value allows passing in an arbitrary delta to increment the |
g.counter[g.identity] += value | ||
} | ||
|
||
// count returns the total count of this counter across all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// count returns the total count of this counter across all the | |
// value returns the total count of this counter across all the |
return total | ||
} | ||
|
||
// Merge combines the counter values across multiple replicas. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Merge combines the counter values across multiple replicas. | |
// merge combines the counter values across multiple replicas. |
@@ -0,0 +1,16 @@ | |||
module crdt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you want to test private functions, it is a little better, to not use module crdt
for the test (i.e. just make a test that uses import datatypes.crdt
, like a normal user program will have to) - the reason is that in this way, the test will also serve as an example, that is directly copy/paste-able.
// Gset is a grow-only set. | ||
struct GSet[T] { | ||
mut: | ||
main_set map[T]T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main_set map[T]T | |
main_set map[T]bool |
For most types, like strings or pointers etc, sizeof(bool) < sizeof(T), and the map here is only used for its keys afaik.
mut elements := []T{} | ||
for _, element in g.main_set { | ||
elements << element | ||
} | ||
return elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mut elements := []T{} | |
for _, element in g.main_set { | |
elements << element | |
} | |
return elements | |
return g.main_set.keys() |
if value in o.add_map { | ||
if value in o.rm_map { | ||
for uid, _ in o.add_map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given if value in o.add_map {
passed, then for uid, _ in o.add_map {
is not needed - uid
will be value
.
It may be helpful to use some variation of key
for the name of the parameter, instead of value
, then the code below will be clearer.
for uid, _ in m { | ||
add_map[uid] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this do?
for uid, _ in m { | ||
rm_map[uid] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not seem to have side effects too, what is the intent for it?
return pn.p_counter.value() - pn.n_counter.value() | ||
} | ||
|
||
// Merge combines both the PN-Counters and saves the result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Merge combines both the PN-Counters and saves the result | |
// merge combines both the PN-Counters and saves the result |
@vladimirmyshkovski can you please fix these issues, so that we can merge the PR? |
From Wikipedia (good to update the doc)
|
Conflict-free replicated data type implementation