fn compute_hashes_for_all_positions(leaves: &[HashValue]) -> HashMap<NodeIndex, HashValue> {
    if leaves.is_empty() {
        return HashMap::new();
    }

    let mut current_leaves = leaves.to_vec();
    current_leaves.resize(
        leaves.len().next_power_of_two(),
        *ACCUMULATOR_PLACEHOLDER_HASH,
    );
    let mut position_to_hash = HashMap::new();
    let mut current_level = 0;

    while current_leaves.len() > 1 {
        assert!(current_leaves.len().is_power_of_two());

        let mut parent_leaves = vec![];
        for (index, _hash) in current_leaves.iter().enumerate().step_by(2) {
            let left_hash = current_leaves[index];
            let right_hash = current_leaves[index + 1];
            let parent_hash = compute_parent_hash(left_hash, right_hash);
            parent_leaves.push(parent_hash);

            let left_pos = NodeIndex::from_level_and_pos(current_level, index as u64);
            let right_pos = NodeIndex::from_level_and_pos(current_level, index as u64 + 1);
            assert_eq!(position_to_hash.insert(left_pos, left_hash), None);
            assert_eq!(position_to_hash.insert(right_pos, right_hash), None);
        }

        assert_eq!(current_leaves.len(), parent_leaves.len() << 1);
        current_leaves = parent_leaves;
        current_level += 1;
    }

    assert_eq!(
        position_to_hash.insert(
            NodeIndex::from_level_and_pos(current_level, 0),
            current_leaves[0],
        ),
        None,
    );
    position_to_hash
}
/// Given a list of leaves, constructs the smallest accumulator that has all the leaves and
/// computes the hash of every node in the tree.
Given a list of leaves, constructs the smallest accumulator that has all the leaves and
computes the hash of every node in the tree.
Given a list of leaves constructs the smallest accumulator that has all the leaves and computes the hash of every node in the tree .
fn compute_hashes_for_all_positions(leaves: &[HashValue]) -> HashMap<NodeIndex, HashValue> {
    if leaves.is_empty() {
        return HashMap::new();
    }
    let mut current_leaves = leaves.to_vec();
    current_leaves.resize(
        leaves.len().next_power_of_two(),
        *ACCUMULATOR_PLACEHOLDER_HASH,
    );
    let mut position_to_hash = HashMap::new();
    let mut current_level = 0;
    while current_leaves.len() > 1 {
        assert!(current_leaves.len().is_power_of_two());
        let mut parent_leaves = vec![];
        for (index, _hash) in current_leaves.iter().enumerate().step_by(2) {
            let left_hash = current_leaves[index];
            let right_hash = current_leaves[index + 1];
            let parent_hash = compute_parent_hash(left_hash, right_hash);
            parent_leaves.push(parent_hash);
            let left_pos = NodeIndex::from_level_and_pos(current_level, index as u64);
            let right_pos = NodeIndex::from_level_and_pos(current_level, index as u64 + 1);
            assert_eq!(position_to_hash.insert(left_pos, left_hash), None);
            assert_eq!(position_to_hash.insert(right_pos, right_hash), None);
        }
        assert_eq!(current_leaves.len(), parent_leaves.len() << 1);
        current_leaves = parent_leaves;
        current_level += 1;
    }
    assert_eq!(
        position_to_hash.insert(
            NodeIndex::from_level_and_pos(current_level, 0),
            current_leaves[0],
        ),
        None,
    );
    position_to_hash
}
fn compute_hashes_for_all_positions ( leaves : & [ HashValue ] ) -> HashMap < NodeIndex , HashValue > { if leaves . is_empty ( ) { return HashMap :: new ( ) ; } let mut current_leaves = leaves . to_vec ( ) ; current_leaves . resize ( leaves . len ( ) . next_power_of_two ( ) , * ACCUMULATOR_PLACEHOLDER_HASH , ) ; let mut position_to_hash = HashMap :: new ( ) ; let mut current_level = 0 ; while current_leaves . len ( ) > 1 { assert ! ( current_leaves len ( ) is_power_of_two ( ) ) ; let mut parent_leaves = vec ! [ ] ; for ( index , _hash ) in current_leaves . iter ( ) . enumerate ( ) . step_by ( 2 ) { let left_hash = current_leaves [ index ] ; let right_hash = current_leaves [ index + 1 ] ; let parent_hash = compute_parent_hash ( left_hash , right_hash ) ; parent_leaves . push ( parent_hash ) ; let left_pos = NodeIndex :: from_level_and_pos ( current_level , index as u64 ) ; let right_pos = NodeIndex :: from_level_and_pos ( current_level , index as u64 + 1 ) ; assert_eq ! ( position_to_hash insert ( left_pos left_hash ) None ) ; assert_eq ! ( position_to_hash insert ( right_pos right_hash ) None ) ; } assert_eq ! ( current_leaves len ( ) parent_leaves len ( ) 1 ) ; current_leaves = parent_leaves ; current_level += 1 ; } assert_eq ! ( position_to_hash insert ( NodeIndex from_level_and_pos ( current_level 0 ) current_leaves [ 0 ] ) None ) ; position_to_hash }
Given a list of leaves, constructs the smallest accumulator that has all the leaves and
computes the hash of every node in the tree.
Given a list of leaves constructs the smallest accumulator that has all the leaves and computes the hash of every node in the tree .
leaves
&[HashValue]
leaves
&[HashValue]