pub struct Tree<T> { /* private fields */ }Expand description
A tree that allows one-time iteration over all nodes and their children, consuming it in the process, while being shareable among threads without a lock. It does this by making the guarantee that iteration only happens once.
Implementations§
Source§impl<T> Tree<T>where
T: Send,
impl<T> Tree<T>where
T: Send,
Sourcepub fn traverse<F, MBFN, E, R>(
self,
resolve: F,
resolve_data: &R,
pack_entries_end: u64,
inspect_object: MBFN,
_: Options<'_, '_>,
) -> Result<Outcome<T>, Error>
pub fn traverse<F, MBFN, E, R>( self, resolve: F, resolve_data: &R, pack_entries_end: u64, inspect_object: MBFN, _: Options<'_, '_>, ) -> Result<Outcome<T>, Error>
Traverse this tree of delta objects with a function inspect_object to process each object at will.
should_run_in_parallel() -> boolreturns true if the underlying pack is big enough to warrant parallel traversal at all.resolve(EntrySlice, &mut Vec<u8>) -> Option<()>resolves the bytes in the pack for the givenEntrySliceand stores them in the output vector. It returnsSome(())if the object existed in the pack, orNoneto indicate a resolution error, which would abort the operation as well.pack_entries_endmarks one-past-the-last byte of the last entry in the pack, as the last entries size would otherwise be unknown as it’s not part of the index file.inspect_object(node_data: &mut T, progress: Progress, context: Context<ThreadLocal State>) -> Result<(), CustomError>is a function running for each thread receiving fully decoded objects along with contextual information, which either succeeds withOk(())or returns aCustomError. Note thatnode_datacan be modified to allow storing maintaining computation results on a per-object basis. It should contain its own mutable per-thread data as required.
This method returns a vector of all tree items, along with their potentially modified custom node data.
Note that this method consumed the Tree to assure safe parallel traversal with mutation support.
Source§impl<T> Tree<T>
Generate tree from certain input
impl<T> Tree<T>
Generate tree from certain input
Sourcepub fn from_offsets_in_pack(
pack_path: &Path,
data_sorted_by_offsets: impl Iterator<Item = T>,
get_pack_offset: &dyn Fn(&T) -> Offset,
resolve_in_pack_id: &dyn Fn(&oid) -> Option<Offset>,
progress: &mut dyn Progress,
should_interrupt: &AtomicBool,
object_hash: Kind,
) -> Result<Self, Error>
pub fn from_offsets_in_pack( pack_path: &Path, data_sorted_by_offsets: impl Iterator<Item = T>, get_pack_offset: &dyn Fn(&T) -> Offset, resolve_in_pack_id: &dyn Fn(&oid) -> Option<Offset>, progress: &mut dyn Progress, should_interrupt: &AtomicBool, object_hash: Kind, ) -> Result<Self, Error>
Create a new Tree from any data sorted by offset, ascending as returned by the data_sorted_by_offsets iterator.
get_pack_offset(item: &T) -> data::Offsetis a function returning the pack offset of the given item, which can be used for obtaining the objects entry within the pack.pack_pathis the path to the pack file itself and from which to read the entry data, which is a pack file matching the offsets returned byget_pack_offset(…).progressis used to track progress when creating the tree.resolve_in_pack_id(gix_hash::oid) -> Option<data::Offset>takes an object ID and tries to resolve it to an object within this pack if possible. Failing to do so aborts the operation, and this function is not expected to be called in usual packs. It’s a theoretical possibility though as old packs might have referred to their objects using the 20 bytes hash, instead of their encoded offset from the base.
Note that the sort order is ascending. The given pack file path must match the provided offsets.