/// Creates a new node and `children_per_node` children if layers > 1,
/// also updates the internal hash to be the hash of its children.
Creates a new node and `children_per_node` children if layers > 1,
also updates the internal hash to be the hash of its children.
Creates a new node and ` children_per_node ` children if layers > 1 also updates the internal hash to be the hash of its children .
fn new(
        label: Label,
        children_per_node: u8,
        layers: u8,
        label_gen: &BitstringLabelGenerator,
    ) -> Result<Self, Error> {
        let mut node = Self { label: label, hash: None, children: Vec::new() };
        if layers == 0 {
            return Ok(node);
        }
        let mut hasher = Sha256::new();
        for child_index in 0..children_per_node {
            let child = Node::new(
                label_gen.child_label(&node.label, child_index)?,
                children_per_node,
                layers - 1,
                label_gen,
            )?;
            hasher.update(&child.hash.as_ref().unwrap_or(DEFAULT_EMPTY_HASH));
            node.children.push(child);
        }
        node.hash = Some(hasher.finalize().into());
        Ok(node)
    }
fn new ( label : Label , children_per_node : u8 , layers : u8 , label_gen : & BitstringLabelGenerator , ) -> Result < Self , Error > { let mut node = Self { label : label , hash : None , children : Vec :: new ( ) } ; if layers == 0 { return Ok ( node ) ; } let mut hasher = Sha256 :: new ( ) ; for child_index in 0 .. children_per_node { let child = Node :: new ( label_gen . child_label ( & node . label , child_index ) ? , children_per_node , layers - 1 , label_gen , ) ? ; hasher . update ( & child . hash . as_ref ( ) . unwrap_or ( DEFAULT_EMPTY_HASH ) ) ; node . children . push ( child ) ; } node . hash = Some ( hasher . finalize ( ) . into ( ) ) ; Ok ( node ) }
Creates a new node and `children_per_node` children if layers > 1,
also updates the internal hash to be the hash of its children.
Creates a new node and ` children_per_node ` children if layers > 1 also updates the internal hash to be the hash of its children .
label
Label
children_per_node
u8
layers
u8
label_gen
&BitstringLabelGenerator