mirror of
https://github.com/mii443/merkle.rs.git
synced 2025-08-23 00:15:31 +00:00
Reverse Vec and use pop() instead of remove(0) for effiency.
This commit is contained in:
@ -93,16 +93,18 @@ impl <D, T> MerkleTree<D, T> where D: Digest, T: Hashable {
|
||||
cur.push(leaf);
|
||||
}
|
||||
|
||||
cur.reverse();
|
||||
|
||||
while cur.len() > 1 {
|
||||
let mut next = Vec::with_capacity(len);
|
||||
|
||||
while cur.len() > 0 {
|
||||
if cur.len() == 1 {
|
||||
next.push(cur.remove(0));
|
||||
next.push(cur.pop().unwrap());
|
||||
}
|
||||
else {
|
||||
let left = cur.remove(0);
|
||||
let right = cur.remove(0);
|
||||
let right = cur.pop().unwrap();
|
||||
let left = cur.pop().unwrap();
|
||||
|
||||
let combined_hash = combine_hashes::<D>(
|
||||
&mut digest,
|
||||
|
Reference in New Issue
Block a user