mirror of
https://github.com/mii443/merkle.rs.git
synced 2025-08-22 16:05:30 +00:00
Fix height for singleton tree.
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user