Address Eirik's review comments

This commit is contained in:
Jack Grigg 2019-06-03 11:14:01 +01:00
parent 79006ecbdf
commit 07dbfbef59
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
2 changed files with 5 additions and 4 deletions

View File

@ -90,10 +90,10 @@ impl<Node: Hashable> CommitmentTree<Node> {
/// Returns the number of notes in the tree. /// Returns the number of notes in the tree.
pub fn size(&self) -> usize { pub fn size(&self) -> usize {
self.parents.iter().enumerate().fold( self.parents.iter().enumerate().fold(
match (self.left.is_some(), self.right.is_some()) { match (self.left, self.right) {
(false, false) => 0, (None, None) => 0,
(true, false) | (false, true) => 1, (Some(_), None) | (None, Some(_)) => 1,
(true, true) => 2, (Some(_), Some(_)) => 2,
}, },
|acc, (i, p)| { |acc, (i, p)| {
// Treat occupation of parents array as a binary number // Treat occupation of parents array as a binary number

View File

@ -221,6 +221,7 @@ mod tests {
eval_u8!(Some(1), [1, 1]); eval_u8!(Some(1), [1, 1]);
eval_u8!(Some(5), [1, 5]); eval_u8!(Some(5), [1, 5]);
eval_vec!(None as Option<Vec<_>>, [0]);
eval_vec!(Some(vec![]), [1, 0]); eval_vec!(Some(vec![]), [1, 0]);
eval_vec!(Some(vec![0]), [1, 1, 0]); eval_vec!(Some(vec![0]), [1, 1, 0]);
eval_vec!(Some(vec![1]), [1, 1, 1]); eval_vec!(Some(vec![1]), [1, 1, 1]);