Skip to main content

DependencyGraph

Struct DependencyGraph 

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

The dependency graph of one worksheet’s formulas.

A cell is a formula cell iff it appears in the forward map; constant cells appear only on the reverse side (as things formulas read). The graph is single-sheet: coordinates are (row, col) within the modeled worksheet (see crate::refs for the sheet-qualifier policy).

Implementations§

Source§

impl DependencyGraph

Source

pub const fn new() -> Self

An empty graph.

Source

pub fn extract(formula: &str) -> Result<Self, GraphError>

Extracts the references of formula into a standalone graph anchored at the origin cell (0, 0) — i.e. exactly Self::new() + add_formula((0, 0), formula).

Useful for one-shot parsing (precedents((0, 0)) returns the sorted, de-duplicated references) and as the typed entry point when the anchor cell is irrelevant. Note the modeling consequence: a formula at the origin that reads A1 produces a self-edge and will be reported by has_circular — correct for the anchor, so prefer add_formula with the real address when one exists.

§Errors

GraphError — see extract_refs.

Source

pub fn add_formula( &mut self, cell: (u32, u32), formula: &str, ) -> Result<(), GraphError>

Registers cell as holding formula, replacing any formula previously registered there. The graph is mutated only when the formula parses — a rejected formula leaves it untouched.

§Errors

GraphError — see extract_refs.

Source

pub fn remove_formula(&mut self, cell: (u32, u32))

Unregisters the formula at cell (no-op when there is none). The cell’s own outgoing edges go; incoming edges of other formulas that read it stay — removing a formula does not blank its value for readers, it just stops the cell from being recomputed.

Source

pub fn precedents(&self, cell: (u32, u32)) -> Vec<(u32, u32)>

Cells read by the formula at cell, sorted ascending. Empty when cell holds no formula.

Source

pub fn dependents(&self, cell: (u32, u32)) -> Vec<(u32, u32)>

Formula cells whose formulas read cell, sorted ascending.

Source

pub fn contains_formula(&self, cell: (u32, u32)) -> bool

true when cell holds a registered formula.

Source

pub fn formula_count(&self) -> usize

Number of registered formulas.

Source

pub fn formula_cells(&self) -> Vec<(u32, u32)>

All registered formula cells, sorted ascending.

Source

pub fn topological_order(&self) -> Vec<(u32, u32)>

The evaluation order: every formula cell, ordered so that each formula comes after every formula it (transitively) reads. Ties break by ascending (row, col), so the result is a total, stable order. Formula cells inside a circular reference have no valid position — and neither does anything that reads them — so both are omitted; pair with has_circular to detect that case.

Source

pub fn dirty_subgraph(&self, edited: &[(u32, u32)]) -> Vec<(u32, u32)>

The minimal recompute set for an edit of edited, in evaluation order — ready to drive an incremental recalc directly.

Formulas among the edited cells are included (an edited formula must re-evaluate); constants only propagate. Cycle members that the propagation reaches are included but cannot be ordered, so they are appended after the orderable prefix (see has_circular).

Source

pub fn has_circular(&self) -> Vec<Vec<(u32, u32)>>

The circular references, as explicit cycles. Each cycle is sorted ascending and the cycles themselves are sorted by first member, so the output is deterministic. Self-references (A1 = A1+1) report as single-member cycles. Empty when the graph is acyclic.

Trait Implementations§

Source§

impl Clone for DependencyGraph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DependencyGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DependencyGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DependencyGraph

Source§

impl PartialEq for DependencyGraph

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DependencyGraph

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.