pub struct Tree<'a, R> { /* private fields */ }Expand description
A handle on one tree of a volume, for searching or iterating it.
Borrowed from the Volume rather than owning anything, so a caller moves between trees
without reopening the filesystem — and so that every block either reads goes through the
one chunk map and the one checksum check.
Implementations§
Source§impl<'a, R: Read + Seek> Tree<'a, R>
impl<'a, R: Read + Seek> Tree<'a, R>
Sourcepub fn for_each_item<F>(&mut self, visit: F) -> Result<(), ReadError>
pub fn for_each_item<F>(&mut self, visit: F) -> Result<(), ReadError>
Visit every item, in key order.
The closure answers whether to keep going, so a caller looking for one thing stops where it finds it rather than reading the rest of the tree.
§Errors
Whatever reading a block does, and the tree-shape refusals this module’s documentation lists.
Sourcepub fn for_each_item_from<F>(
&mut self,
from: DiskKey,
visit: F,
) -> Result<(), ReadError>
pub fn for_each_item_from<F>( &mut self, from: DiskKey, visit: F, ) -> Result<(), ReadError>
Visit every item at or after from, in key order.
The descent goes straight to the first item at or after the key rather than walking the tree from its start, which is what makes “the entries of this directory” one descent instead of a scan.
§Errors
As for_each_item.
Sourcepub fn for_each_block<F>(&mut self, visit: F) -> Result<(), ReadError>
pub fn for_each_block<F>(&mut self, visit: F) -> Result<(), ReadError>
Visit every block of the tree, in the order a depth-first descent meets them.
Every block is fetched through the chunk map and its checksum verified before the closure sees it, so a walk that completes is a statement that every block of the tree verified. The items are bounds-checked on the way past whether or not the closure looks at them, which is what makes this a verification pass rather than a header read.
§Errors
As for_each_item.
Sourcepub fn find_at_or_before(
&mut self,
key: DiskKey,
) -> Result<Option<Located>, ReadError>
pub fn find_at_or_before( &mut self, key: DiskKey, ) -> Result<Option<Located>, ReadError>
The last item at or before key, or None where every item in the tree is above it.
The search a range needs, where find_first is the one a point
needs. A record keyed by where a run begins covers everything up to the next one, so the
record covering a position is the last one at or before it — and asking for the first at
or after would find the record covering the next position and skip the one wanted.
That is how a file’s extents are keyed, and reading from an offset in the middle of one
is the case that makes the difference visible.
One descent, so it costs the height of the tree rather than a scan.
§Errors
As for_each_item.
Sourcepub fn count_items(&mut self) -> Result<u64, ReadError>
pub fn count_items(&mut self) -> Result<u64, ReadError>
How many items the tree holds, having read and verified every block on the way.
§Errors
As for_each_item.