fn build<A: Algorithm<E>, U: Unsigned>(
        &mut self,
        leafs: usize,
        row_count: usize,
        config: Option<StoreConfig>,
    ) -> Result<E> {
        let branches = U::to_usize();
        ensure!(
            next_pow2(branches) == branches,
            "branches MUST be a power of 2"
        );
        ensure!(Store::len(self) == leafs, "Inconsistent data");
        ensure!(leafs % 2 == 0, "Leafs must be a power of two");
        ensure!(
            config.is_some(),
            "LevelCacheStore build requires a valid config"
        );

        // Process one `level` at a time of `width` nodes. Each level has half the nodes
        // as the previous one; the first level, completely stored in `data`, has `leafs`
        // nodes. We guarantee an even number of nodes per `level`, duplicating the last
        // node if necessary.
        let mut level: usize = 0;
        let mut width = leafs;
        let mut level_node_index = 0;

        let config = config.unwrap();
        let shift = log2_pow2(branches);

        // Both in terms of elements, not bytes.
        let cache_size = get_merkle_tree_cache_size(leafs, branches, config.rows_to_discard)?;
        let cache_index_start = (get_merkle_tree_len(leafs, branches)?) - cache_size;

        while width > 1 {
            // Start reading at the beginning of the current level, and writing the next
            // level immediate after.  `level_node_index` keeps track of the current read
            // starts, and width is updated accordingly at each level so that we know where
            // to start writing.
            let (read_start, write_start) = if level == 0 {
                // Note that we previously asserted that data.len() == leafs.
                (0, Store::len(self))
            } else if level_node_index < cache_index_start {
                (0, width)
            } else {
                (
                    level_node_index - cache_index_start,
                    (level_node_index + width) - cache_index_start,
                )
            };

            self.process_layer::<A, U>(width, level, read_start, write_start)?;

            if level_node_index < cache_index_start {
                self.front_truncate(&config, width)?;
            }

            level_node_index += width;
            level += 1;
            width >>= shift; // width /= branches;

            // When the layer is complete, update the store length
            // since we know the backing file was updated outside of
            // the store interface.
            self.set_len(level_node_index);
        }

        // Account for the root element.
        self.set_len(Store::len(self) + 1);
        // Ensure every element is accounted for.
        ensure!(
            Store::len(self) == get_merkle_tree_len(leafs, branches)?,
            "Invalid merkle tree length"
        );

        ensure!(row_count == level + 1, "Invalid tree row_count");
        // The root isn't part of the previous loop so `row_count` is
        // missing one level.

        // Return the root.  Note that the offset is adjusted because
        // we've just built a store that says that it has the full
        // length of elements, when in fact only the cached portion is
        // on disk.
        self.read_at_internal(self.len() - cache_index_start - 1)
    }
// LevelCacheStore specific merkle-tree build.
LevelCacheStore specific merkle-tree build.
LevelCacheStore specific merkle - tree build .
fn build<A: Algorithm<E>, U: Unsigned>(
        &mut self,
        leafs: usize,
        row_count: usize,
        config: Option<StoreConfig>,
    ) -> Result<E> {
        let branches = U::to_usize();
        ensure!(
            next_pow2(branches) == branches,
            "branches MUST be a power of 2"
        );
        ensure!(Store::len(self) == leafs, "Inconsistent data");
        ensure!(leafs % 2 == 0, "Leafs must be a power of two");
        ensure!(
            config.is_some(),
            "LevelCacheStore build requires a valid config"
        );
        // Process one `level` at a time of `width` nodes. Each level has half the nodes
        // as the previous one; the first level, completely stored in `data`, has `leafs`
        // nodes. We guarantee an even number of nodes per `level`, duplicating the last
        // node if necessary.
        let mut level: usize = 0;
        let mut width = leafs;
        let mut level_node_index = 0;
        let config = config.unwrap();
        let shift = log2_pow2(branches);
        // Both in terms of elements, not bytes.
        let cache_size = get_merkle_tree_cache_size(leafs, branches, config.rows_to_discard)?;
        let cache_index_start = (get_merkle_tree_len(leafs, branches)?) - cache_size;
        while width > 1 {
            // Start reading at the beginning of the current level, and writing the next
            // level immediate after.  `level_node_index` keeps track of the current read
            // starts, and width is updated accordingly at each level so that we know where
            // to start writing.
            let (read_start, write_start) = if level == 0 {
                // Note that we previously asserted that data.len() == leafs.
                (0, Store::len(self))
            } else if level_node_index < cache_index_start {
                (0, width)
            } else {
                (
                    level_node_index - cache_index_start,
                    (level_node_index + width) - cache_index_start,
                )
            };
            self.process_layer::<A, U>(width, level, read_start, write_start)?;
            if level_node_index < cache_index_start {
                self.front_truncate(&config, width)?;
            }
            level_node_index += width;
            level += 1;
            width >>= shift; // width /= branches;
            // When the layer is complete, update the store length
            // since we know the backing file was updated outside of
            // the store interface.
            self.set_len(level_node_index);
        }
        // Account for the root element.
        self.set_len(Store::len(self) + 1);
        // Ensure every element is accounted for.
        ensure!(
            Store::len(self) == get_merkle_tree_len(leafs, branches)?,
            "Invalid merkle tree length"
        );
        ensure!(row_count == level + 1, "Invalid tree row_count");
        // The root isn't part of the previous loop so `row_count` is
        // missing one level.
        // Return the root.  Note that the offset is adjusted because
        // we've just built a store that says that it has the full
        // length of elements, when in fact only the cached portion is
        // on disk.
        self.read_at_internal(self.len() - cache_index_start - 1)
    }
fn build < A : Algorithm < E > , U : Unsigned > ( & mut self , leafs : usize , row_count : usize , config : Option < StoreConfig > , ) -> Result < E > { let branches = U :: to_usize ( ) ; ensure ! ( next_pow2 ( branches ) branches " " ) ; ensure ! ( Store len ( self ) leafs " " ) ; ensure ! ( leafs 2 0 " " ) ; ensure ! ( config is_some ( ) " " ) ; // Process one `level` at a time of `width` nodes. Each level has half the nodes // as the previous one; the first level, completely stored in `data`, has `leafs` // nodes. We guarantee an even number of nodes per `level`, duplicating the last // node if necessary. let mut level : usize = 0 ; let mut width = leafs ; let mut level_node_index = 0 ; let config = config . unwrap ( ) ; let shift = log2_pow2 ( branches ) ; // Both in terms of elements, not bytes. let cache_size = get_merkle_tree_cache_size ( leafs , branches , config . rows_to_discard ) ? ; let cache_index_start = ( get_merkle_tree_len ( leafs , branches ) ? ) - cache_size ; while width > 1 { // Start reading at the beginning of the current level, and writing the next // level immediate after.  `level_node_index` keeps track of the current read // starts, and width is updated accordingly at each level so that we know where // to start writing. let ( read_start , write_start ) = if level == 0 { // Note that we previously asserted that data.len() == leafs. ( 0 , Store :: len ( self ) ) } else if level_node_index < cache_index_start { ( 0 , width ) } else { ( level_node_index - cache_index_start , ( level_node_index + width ) - cache_index_start , ) } ; self . process_layer :: < A , U > ( width , level , read_start , write_start ) ? ; if level_node_index < cache_index_start { self . front_truncate ( & config , width ) ? ; } level_node_index += width ; level += 1 ; width >>= shift ; // width /= branches; // When the layer is complete, update the store length // since we know the backing file was updated outside of // the store interface. self . set_len ( level_node_index ) ; } // Account for the root element. self . set_len ( Store :: len ( self ) + 1 ) ; // Ensure every element is accounted for. ensure ! ( Store len ( self ) get_merkle_tree_len ( leafs branches ) " " ) ; ensure ! ( row_count level 1 " " ) ; // The root isn't part of the previous loop so `row_count` is // missing one level. // Return the root.  Note that the offset is adjusted because // we've just built a store that says that it has the full // length of elements, when in fact only the cached portion is // on disk. self . read_at_internal ( self . len ( ) - cache_index_start - 1 ) }
LevelCacheStore specific merkle-tree build.
LevelCacheStore specific merkle - tree build .
&mut self
leafs
usize
row_count
usize
config
Option<StoreConfig>