Fix height for singleton tree.

This commit is contained in:
Romain Ruetschi
2016-11-11 16:38:36 +01:00
parent 93a2839ad1
commit 90531513fe
2 changed files with 5 additions and 6 deletions

View File

@ -21,11 +21,8 @@ impl <D, T> MerkleTree<D, T> where D: Digest, T: Hashable {
panic!("Cannot build a Merkle tree from an empty vector.");
}
let count = values.len();
let count = values.len();
let mut height = 0;
if count == 1 {
height = 1;
}
let mut cur = Vec::with_capacity(count);
@ -60,7 +57,9 @@ impl <D, T> MerkleTree<D, T> where D: Digest, T: Hashable {
next.push(node);
}
}
height = height + 1;
height += 1;
cur = next;
}

View File

@ -89,7 +89,7 @@ fn test_from_vec1() {
let root_hash = &d.hash_bytes(&"hello, world".to_string().to_bytes());
assert_eq!(tree.count, 1);
assert_eq!(tree.height, 1);
assert_eq!(tree.height, 0);
assert_eq!(tree.root_hash().as_slice(), root_hash.as_slice());
}