/// Write a new tree root, return the root page id.
///
/// This is used to implement insertion as well as initialization of a
/// non-empty tree. The node should contain all datoms that need to be
/// inserted into a higher level than the current root. In the case of
/// initialization, there is no current root, and the node will become
/// the root (it might be split, if required). If the node has no datoms,
/// then it should point to a single child node which is the new root. In
/// that case nothing is written.
Write a new tree root, return the root page id.
This is used to implement insertion as well as initialization of a
non-empty tree. The node should contain all datoms that need to be
inserted into a higher level than the current root. In the case of
initialization, there is no current root, and the node will become
the root (it might be split, if required). If the node has no datoms,
then it should point to a single child node which is the new root. In
that case nothing is written.
Write a new tree root return the root page id . This is used to implement insertion as well as initialization of a non - empty tree . The node should contain all datoms that need to be inserted into a higher level than the current root . In the case of initialization there is no current root and the node will become the root ( it might be split if required ) . If the node has no datoms then it should point to a single child node which is the new root . In that case nothing is written .
fn write_root(&mut self, mut node: VecNode) -> io::Result<PageId> where Store: store::StoreMut {
        // The node contains all datoms that need to be inserted into a new
        // higher level in the tree. There might be so many of those, that one
        // page is not enough. Then we need to split, and create yet a higher
        // level, until there are few enough midpoints to fit in one page.
        while node.datoms.len() > Store::Size::CAPACITY {
            node = self.split(&node.as_node())?;
        }
        // If we get only one new page id, then that is the new root. If there
        // is more, then the tree grows in height, and we write the entire new
        // node as the new root.
        let root_page = match node.children.len() {
            0 => panic!("Result of insert_into must contain at least one child page."),
            1 => node.children[0],
            _ => self.store.write_page(&node.as_node().write::<Store::Size>())?,
        };
        Ok(root_page)
    }
fn write_root ( & mut self , mut node : VecNode ) -> io :: Result < PageId > where Store : store :: StoreMut { // The node contains all datoms that need to be inserted into a new // higher level in the tree. There might be so many of those, that one // page is not enough. Then we need to split, and create yet a higher // level, until there are few enough midpoints to fit in one page. while node . datoms . len ( ) > Store :: Size :: CAPACITY { node = self . split ( & node . as_node ( ) ) ? ; } // If we get only one new page id, then that is the new root. If there // is more, then the tree grows in height, and we write the entire new // node as the new root. let root_page = match node . children . len ( ) { 0 => panic ! ( " " ) , 1 => node . children [ 0 ] , _ => self . store . write_page ( & node . as_node ( ) . write :: < Store :: Size > ( ) ) ? , } ; Ok ( root_page ) }
Write a new tree root, return the root page id.
Write a new tree root return the root page id .
&mut self
node
VecNode