vimsheet.formula.dependency

Dependency DAG for formula recalculation.

exception vimsheet.formula.dependency.CycleError[source]

Bases: ValueError

Raised when a cycle is detected in the dependency graph.

class vimsheet.formula.dependency.DependencyGraph[source]

Bases: object

Directed acyclic graph tracking formula cell dependencies.

Nodes are (row, col) tuples. An edge (A B) means cell A’s formula references cell B (i.e. A depends on B).

__init__()[source]
Return type:

None

set_dependencies(cell, deps)[source]

Replace all dependencies of cell with deps.

Parameters:
Return type:

None

remove_cell(cell)[source]

Remove cell from the graph entirely.

Parameters:

cell (tuple[int, int])

Return type:

None

dependents_of(cell)[source]

Return all cells that directly depend on cell.

Parameters:

cell (tuple[int, int])

Return type:

set[tuple[int, int]]

dependencies_of(cell)[source]

Return all cells that cell directly references.

Parameters:

cell (tuple[int, int])

Return type:

set[tuple[int, int]]

evaluation_order(dirty)[source]

Return cells in evaluation order for the subgraph reachable from dirty.

Raises CycleError if a cycle is detected.

Parameters:

dirty (set[tuple[int, int]])

Return type:

list[tuple[int, int]]

iter_edges()[source]

Yield (dependent, dependency) pairs.

Return type:

Iterator[tuple[tuple[int, int], tuple[int, int]]]