Skip to main content

Tree

Struct Tree 

Source
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,

Source

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>
where F: for<'r> Fn(EntryRange, &'r R) -> Option<&'r [u8]> + Send + Clone, R: Send + Sync, MBFN: FnMut(&mut T, &dyn Progress, Context<'_>) -> Result<(), E> + Send + Clone, E: Error + Send + Sync + 'static,

Traverse this tree of delta objects with a function inspect_object to process each object at will.

  • should_run_in_parallel() -> bool returns 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 given EntrySlice and stores them in the output vector. It returns Some(()) if the object existed in the pack, or None to indicate a resolution error, which would abort the operation as well.
  • pack_entries_end marks 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 with Ok(()) or returns a CustomError. Note that node_data can 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

Source

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::Offset is a function returning the pack offset of the given item, which can be used for obtaining the objects entry within the pack.
  • pack_path is the path to the pack file itself and from which to read the entry data, which is a pack file matching the offsets returned by get_pack_offset(…).
  • progress is 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.

Auto Trait Implementations§

§

impl<T> Freeze for Tree<T>
where Vec<Item<T>>: Freeze,

§

impl<T> RefUnwindSafe for Tree<T>
where Vec<Item<T>>: RefUnwindSafe,

§

impl<T> Send for Tree<T>
where Vec<Item<T>>: Send,

§

impl<T> Sync for Tree<T>
where Vec<Item<T>>: Sync,

§

impl<T> Unpin for Tree<T>
where Vec<Item<T>>: Unpin,

§

impl<T> UnsafeUnpin for Tree<T>
where Vec<Item<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Tree<T>
where Vec<Item<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.