Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed Feb 28, 2024
1 parent 32805dd commit 374491d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/disktree/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,43 @@ impl<'a> Iter<'a> {
node_stack,
})
}

pub(crate) fn empty(disktree_buf: &'a [u8]) -> Iter<'a> {
let disktree_csr = Cursor::new(disktree_buf);
let cell_stack = CellStack::new();
let node_stack = Vec::new();
let recycle_bin = Vec::new();
let curr_node = None;
Self {
cell_stack,
curr_node,
disktree_buf,
disktree_csr,
recycle_bin,
node_stack,
}
}

// pub(crate) fn subtree(disktree: &'a DiskTreeMap, cell: Cell) -> Result<Iter<'a>> {
// let mut disktree_csr = Cursor::new(disktree_buf);
// let mut cell_stack = CellStack::new();
// let mut node_stack = Vec::new();
// let recycle_bin = Vec::new();
// let mut base_nodes = Self::read_base_nodes(&mut disktree_csr)?;
// let curr_node = base_nodes.pop();
// node_stack.push(base_nodes);
// if let Some((digit, _)) = curr_node {
// cell_stack.push(digit);
// }
// Ok(Self {
// cell_stack,
// curr_node,
// disktree_buf,
// disktree_csr,
// recycle_bin,
// node_stack,
// })
// }
}

impl<'a> Iterator for Iter<'a> {
Expand Down
20 changes: 18 additions & 2 deletions src/disktree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,24 @@ impl DiskTreeMap {
}

/// Returns an iterator visiting the specified `cell` or its descendants.
pub fn subtree_iter(&self, _cell: Cell) -> Result<impl Iterator<Item = Result<(Cell, &[u8])>>> {
Ok(None.into_iter())
pub fn subtree_iter(&self, cell: Cell) -> Result<impl Iterator<Item = Result<(Cell, &[u8])>>> {
let iter = match self.get_raw(cell)? {
None => {
let iter = crate::disktree::iter::Iter::empty((*self.0).as_ref());
None.into_iter().chain(iter)
}
Some((cell, Node::Leaf(range))) => {
let iter = crate::disktree::iter::Iter::empty((*self.0).as_ref());
let val_bytes = &(*self.0).as_ref()[range];
Some(Ok((cell, val_bytes))).into_iter().chain(iter)
}
Some((cell, Node::Parent(children))) => {
let iter = crate::disktree::iter::Iter::empty((*self.0).as_ref());
let val_bytes = &(*self.0).as_ref()[range];

Check failure on line 132 in src/disktree/tree.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `range` in this scope

error[E0425]: cannot find value `range` in this scope --> src/disktree/tree.rs:132:53 | 132 | let val_bytes = &(*self.0).as_ref()[range]; | ^^^^^ not found in this scope | help: consider importing one of these items | 1 + use core::slice::range; | 1 + use std::slice::range; |
Some(Ok((cell, val_bytes))).into_iter().chain(iter)
}
};
Ok(iter)
}

/// Returns the DPtr to a base (res0) cell dptr.
Expand Down

0 comments on commit 374491d

Please sign in to comment.