[btree_builder] Rename Builder to BTreeBuilder for clarity
This commit is contained in:
		@@ -125,7 +125,7 @@ impl<V: Unpack + Pack + Clone + Default> ArrayBuilder<V> {
 | 
			
		||||
 | 
			
		||||
    pub fn complete(self, w: &mut WriteBatcher) -> Result<u64> {
 | 
			
		||||
        let blocks = self.block_builder.complete(w)?;
 | 
			
		||||
        let mut index_builder = Builder::<u64>::new(Box::new(NoopRC {}));
 | 
			
		||||
        let mut index_builder = BTreeBuilder::<u64>::new(Box::new(NoopRC {}));
 | 
			
		||||
 | 
			
		||||
        for (i, b) in blocks.iter().enumerate() {
 | 
			
		||||
            index_builder.push_value(w, i as u64, *b)?;
 | 
			
		||||
 
 | 
			
		||||
@@ -453,13 +453,13 @@ impl<'a, V: Pack + Unpack + Clone> NodeBuilder<V> {
 | 
			
		||||
 | 
			
		||||
//------------------------------------------
 | 
			
		||||
 | 
			
		||||
pub struct Builder<V: Unpack + Pack> {
 | 
			
		||||
pub struct BTreeBuilder<V: Unpack + Pack> {
 | 
			
		||||
    leaf_builder: NodeBuilder<V>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<V: Unpack + Pack + Clone> Builder<V> {
 | 
			
		||||
    pub fn new(value_rc: Box<dyn RefCounter<V>>) -> Builder<V> {
 | 
			
		||||
        Builder {
 | 
			
		||||
impl<V: Unpack + Pack + Clone> BTreeBuilder<V> {
 | 
			
		||||
    pub fn new(value_rc: Box<dyn RefCounter<V>>) -> BTreeBuilder<V> {
 | 
			
		||||
        BTreeBuilder {
 | 
			
		||||
            leaf_builder: NodeBuilder::new(Box::new(LeafIO {}), value_rc),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -473,33 +473,40 @@ impl<V: Unpack + Pack + Clone> Builder<V> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn complete(self, w: &mut WriteBatcher) -> Result<u64> {
 | 
			
		||||
        let mut nodes = self.leaf_builder.complete(w)?;
 | 
			
		||||
 | 
			
		||||
        // Now we iterate, adding layers of internal nodes until we end
 | 
			
		||||
        // up with a single root.
 | 
			
		||||
        while nodes.len() > 1 {
 | 
			
		||||
            let mut builder = NodeBuilder::new(
 | 
			
		||||
                Box::new(InternalIO {}),
 | 
			
		||||
                Box::new(SMRefCounter::new(w.sm.clone())),
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            for n in nodes {
 | 
			
		||||
                builder.push_value(w, n.key, n.block)?;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            nodes = builder.complete(w)?;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        assert!(nodes.len() == 1);
 | 
			
		||||
 | 
			
		||||
        // The root is expected to be referenced by only one parent,
 | 
			
		||||
        // hence the ref count is increased before the availability
 | 
			
		||||
        // of it's parent.
 | 
			
		||||
        let root = nodes[0].block;
 | 
			
		||||
        w.sm.lock().unwrap().inc(root, 1)?;
 | 
			
		||||
 | 
			
		||||
        Ok(root)
 | 
			
		||||
        let nodes = self.leaf_builder.complete(w)?;
 | 
			
		||||
        build_btree(w, nodes)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//------------------------------------------
 | 
			
		||||
 | 
			
		||||
// Build a btree from a list of pre-built leaves
 | 
			
		||||
pub fn build_btree(w: &mut WriteBatcher, leaves: Vec<NodeSummary>) -> Result<u64> {
 | 
			
		||||
    // Now we iterate, adding layers of internal nodes until we end
 | 
			
		||||
    // up with a single root.
 | 
			
		||||
    let mut nodes = leaves;
 | 
			
		||||
    while nodes.len() > 1 {
 | 
			
		||||
        let mut builder = NodeBuilder::new(
 | 
			
		||||
            Box::new(InternalIO {}),
 | 
			
		||||
            Box::new(SMRefCounter::new(w.sm.clone())),
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        for n in nodes {
 | 
			
		||||
            builder.push_value(w, n.key, n.block)?;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        nodes = builder.complete(w)?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    assert!(nodes.len() == 1);
 | 
			
		||||
 | 
			
		||||
    // The root is expected to be referenced by only one parent,
 | 
			
		||||
    // hence the ref count is increased before the availability
 | 
			
		||||
    // of it's parent.
 | 
			
		||||
    let root = nodes[0].block;
 | 
			
		||||
    w.sm.lock().unwrap().inc(root, 1)?;
 | 
			
		||||
 | 
			
		||||
    Ok(root)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//------------------------------------------
 | 
			
		||||
 
 | 
			
		||||
@@ -200,7 +200,7 @@ pub fn write_common(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<(Vec<Inde
 | 
			
		||||
    use BitmapEntry::*;
 | 
			
		||||
 | 
			
		||||
    let mut index_entries = Vec::new();
 | 
			
		||||
    let mut overflow_builder: Builder<u32> = Builder::new(Box::new(NoopRC {}));
 | 
			
		||||
    let mut overflow_builder: BTreeBuilder<u32> = BTreeBuilder::new(Box::new(NoopRC {}));
 | 
			
		||||
 | 
			
		||||
    // how many bitmaps do we need?
 | 
			
		||||
    for bm in 0..div_up(sm.get_nr_blocks()? as usize, ENTRIES_PER_BITMAP) {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ use crate::write_batcher::*;
 | 
			
		||||
pub fn write_disk_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<SMRoot> {
 | 
			
		||||
    let (index_entries, ref_count_root) = write_common(w, sm)?;
 | 
			
		||||
 | 
			
		||||
    let mut index_builder: Builder<IndexEntry> = Builder::new(Box::new(NoopRC {}));
 | 
			
		||||
    let mut index_builder: BTreeBuilder<IndexEntry> = BTreeBuilder::new(Box::new(NoopRC {}));
 | 
			
		||||
    for (i, ie) in index_entries.iter().enumerate() {
 | 
			
		||||
        index_builder.push_value(w, i as u64, *ie)?;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -303,7 +303,7 @@ pub fn restore(opts: ThinRestoreOptions) -> Result<()> {
 | 
			
		||||
    let pass = pass.get_result()?;
 | 
			
		||||
 | 
			
		||||
    // Build the device details tree.
 | 
			
		||||
    let mut details_builder: Builder<DeviceDetail> = Builder::new(Box::new(NoopRC {}));
 | 
			
		||||
    let mut details_builder: BTreeBuilder<DeviceDetail> = BTreeBuilder::new(Box::new(NoopRC {}));
 | 
			
		||||
    for (thin_id, (detail, _)) in &pass.devices {
 | 
			
		||||
        details_builder.push_value(&mut w, *thin_id as u64, *detail)?;
 | 
			
		||||
    }
 | 
			
		||||
@@ -314,14 +314,14 @@ pub fn restore(opts: ThinRestoreOptions) -> Result<()> {
 | 
			
		||||
    for (thin_id, (_, nodes)) in &pass.devices {
 | 
			
		||||
        ctx.report
 | 
			
		||||
            .info(&format!("building btree for device {}", thin_id));
 | 
			
		||||
        let mut builder: Builder<BlockTime> = Builder::new(Box::new(NoopRC {}));
 | 
			
		||||
        let mut builder: BTreeBuilder<BlockTime> = BTreeBuilder::new(Box::new(NoopRC {}));
 | 
			
		||||
        builder.push_leaves(&mut w, nodes)?;
 | 
			
		||||
        let root = builder.complete(&mut w)?;
 | 
			
		||||
        devs.insert(*thin_id, root);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Build the top level mapping tree
 | 
			
		||||
    let mut builder: Builder<u64> = Builder::new(Box::new(NoopRC {}));
 | 
			
		||||
    let mut builder: BTreeBuilder<u64> = BTreeBuilder::new(Box::new(NoopRC {}));
 | 
			
		||||
    for (thin_id, root) in devs {
 | 
			
		||||
        builder.push_value(&mut w, thin_id as u64, root)?;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user