SparseSource

Struct SparseSource 

Source
pub struct SparseSource { /* private fields */ }
Expand description

The sparse arena, its index and the reference-walk state.

Implementations§

Source§

impl SparseSource

Source

pub fn new(preamble: Vec<u8>) -> Self

Start from a preamble: the file’s HEADER followed by the records every worker needs (see build_sparse_preamble).

Source

pub fn with_reserve(preamble: Vec<u8>, reserve_bytes: usize) -> Self

Self::new, reserving reserve_bytes of arena up front.

Without a reservation the arena grows by doubling, and each growth holds the old and the new block at once: measured on a single worker, the wasm heap high-water was 2 to 5 times the arena. Reserved once, the arena never moves until it outgrows the reservation, and a reset keeps the block. Pages that are never written cost address space only.

Source

pub fn set_inverse_edges(&mut self, targets: &[u32], referrers: &[u32])

Declare inverse edges: referrers[i] references targets[i] and must be installed whenever the target is walked. Order is preserved per target, so file-order precedence among referrers survives.

Source

pub fn bytes(&self) -> Arc<Vec<u8>>

Source

pub fn index(&self) -> Arc<SparseIndex>

Source

pub fn stats(&self) -> SparseStats

Source

pub fn contains(&self, id: u32) -> bool

Source

pub fn expand(&mut self, ids: &[u32], max_depth: u32, missing: &mut Vec<u32>)

Walk references from ids through the installed records and append every id that is needed and not installed to missing (deduplicated, ascending). After installing them, walk again from those ids.

A full walk (max_depth == u32::MAX) expands each record once per arena lifetime, so later calls only pay for what was installed since. A depth-limited walk follows at most max_depth reference hops and keeps no state, so it never hides a record from a later full walk.

Source

pub fn install(&mut self, spans: &[(u32, usize, usize)], chunk: &[u8])

Append records. spans holds (id, offset, length) into chunk; each record is copied with a trailing newline. An id already installed is skipped (the first copy stays authoritative).

Source

pub fn mark_absent(&mut self, ids: &[u32])

Ids the file does not hold (dangling references): never reported again.

Source

pub fn take_misses(&self) -> Vec<u32>

Lookups that missed since the last call, without the ids already known to be absent from the file.

Source

pub fn reset(&mut self)

Drop everything but the preamble. Spans change, so the caller must not hold a decoder or a span across this call.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.