Address Eirik's review comments
This commit is contained in:
parent
79006ecbdf
commit
07dbfbef59
|
@ -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
|
||||||
|
|
|
@ -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]);
|
||||||
|
|
Loading…
Reference in New Issue