-
Notifications
You must be signed in to change notification settings - Fork 56
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
Why does merge() take ownership of the other side? #135
Comments
Hi @exi, We take ownership because E.g. say you have two sets:
But I'm curious, do you have a need to hold onto the other state after merging? I assumed most cases will be throwing away the other state after they merge it into their state. |
I actually have multiple such situations. For For |
I see, for the merge case, would it not make more sense to broadcast the merged state rather than the "other" state? This should speed up convergence a little. You would need a signal to tell you if the other state had any new information, and then only broadcasting your state when you see new information. Perhaps that's a change worth making to the merge api? // Merge the other state into our state, return true if our state was modified, false otherwise
fn merge(&mut self, other: Self) -> bool; This way you can decide to broadcast based on the result of the merge? |
These are good suggestions. Returning |
Interesting idea. Returning a But computing this delta would be a useful API that we could implement: fn delta(&self, other: Self) -> Vec<Op> Thinking through this. You could collapse that // The return value is the minimal state that when merged would bring you in sync with other.
fn delta(&self, other: Self) -> Self The delta state should be more space efficient than a vec of independent ops. So your flow would be: // on receive `other` state
let delta = self.state.delta(other);
// delta will be empty if `other` had no new information.
if self.state.merge(delta.clone()) {
// broadcast delta
} Impl thoughts:
What do you think of something like that? |
Better than hashes would be to send the vector clocks: Use
Hashes would only tell you that you are out of sync and would result in more messages. |
With the current merge() API, I'm forced to clone the other side I'm merging from every time, because merge takes ownership.
Why is this necessary and can't there be a variant of merge with
merge(&mut self, other: &Self)
?The text was updated successfully, but these errors were encountered: