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

Adding parents and children helper APIs to MerkleReg #116

Merged

Conversation

bochaco
Copy link
Contributor

@bochaco bochaco commented Mar 16, 2021

No description provided.

Copy link
Member

@davidrusu davidrusu left a comment

Choose a reason for hiding this comment

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

Looks good, comments are mostly nits

use quickcheck::{Arbitrary, Gen};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
Copy link
Member

Choose a reason for hiding this comment

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

please keep the std/core imports up in the first group of imports, third party imports in the second group and local crate imports in the third group

@@ -11,7 +11,7 @@ use crate::traits::{CmRDT, CvRDT};
pub type Hash = [u8; 32];

/// A node in the Merkle DAG
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, PartialOrd, Deserialize)]
Copy link
Member

Choose a reason for hiding this comment

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

If you're going to derive PartialOrd, might as well get Ord as well. Also keep the serde(or any third party) derives together at the end.

Suggested change
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, PartialOrd, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]

@@ -57,7 +57,7 @@ impl<'a, T> Content<'a, T> {

/// Iterate over the Merkle DAG nodes holding the content values.
pub fn nodes(&self) -> impl Iterator<Item = &Node<T>> {
self.nodes.values().map(|n| *n)
self.nodes.values().copied()
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -74,7 +74,7 @@ impl<'a, T> Content<'a, T> {
/// The MerkleReg is a Register CRDT that uses the Merkle DAG
/// structure to track the current value(s) held by this register.
/// The leaves of the Merkle DAG are the current values.
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd)]
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
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]

node.parents
.iter()
.copied()
.filter_map(|leaf| self.dag.get(&leaf).map(|node| (leaf, node)))
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
.filter_map(|leaf| self.dag.get(&leaf).map(|node| (leaf, node)))
.filter_map(|parent_hash| self.dag.get(&parent_hash).map(|node| (parent_hash, node)))

Copy link
Member

@davidrusu davidrusu left a comment

Choose a reason for hiding this comment

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

🚂

@davidrusu davidrusu merged commit 91bf3e6 into rust-crdt:master Mar 17, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants