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

CRDT datatype implementation #18046

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

vladimirmyshkovski
Copy link
Contributor

@vladimirmyshkovski vladimirmyshkovski commented Apr 24, 2023

g.increment_value(1)
}

// inc_val allows passing in an arbitrary delta to increment the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Merge combines the counter values across multiple replicas.
// merge combines the counter values across multiple replicas.

@@ -0,0 +1,16 @@
module crdt
Copy link
Member

@spytheman spytheman Apr 26, 2023

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +34 to +38
mut elements := []T{}
for _, element in g.main_set {
elements << element
}
return elements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mut elements := []T{}
for _, element in g.main_set {
elements << element
}
return elements
return g.main_set.keys()

Comment on lines +42 to +44
if value in o.add_map {
if value in o.rm_map {
for uid, _ in o.add_map {
Copy link
Member

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.

Comment on lines +62 to +64
for uid, _ in m {
add_map[uid]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Comment on lines +70 to +72
for uid, _ in m {
rm_map[uid]
}
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Merge combines both the PN-Counters and saves the result
// merge combines both the PN-Counters and saves the result

@medvednikov
Copy link
Member

@vladimirmyshkovski can you please fix these issues, so that we can merge the PR?

@ArtemkaKun ArtemkaKun added the Needs Rebase The code of the PR must be rebased over current master before it can be approved. label Jun 7, 2023
@spytheman spytheman added the Breaking Change This PR introduces changes that break backward compatibility. Requires manual review. label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change This PR introduces changes that break backward compatibility. Requires manual review. Needs Rebase The code of the PR must be rebased over current master before it can be approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants