/** * The directed dependency graph: which formula cells depend on which cells, so a * change recomputes only the affected subgraph rather than the whole grid. * * ### Two kinds of precedent, one reverse lookup * - **Single-cell precedents** (`=A1+B1`) are indexed by an exact reverse map * `precedent → dependents`, giving O(1) dependent lookup. * - **Range precedents** (`=SUM(A1:A9)`, `=SUM(A:A)`) are stored as rectangular * regions, *not* expanded per cell — so a whole-column dependency costs O(1) * memory instead of O(rowCount). A changed cell tests region containment. * * This keeps the graph scalable to hundreds of thousands of formulas and * whole-column ranges without materializing millions of edges. * * @packageDocumentation */ import type { CellId } from '../types/formula.types'; /** * A rectangular precedent region for a range reference. `colEnd`/`rowEnd` are * `Number.POSITIVE_INFINITY` for open-ended whole-row/whole-column ranges. */ export interface RangeDependency { /** The formula cell that depends on this region. */ readonly dependent: CellId; /** Inclusive positional column bounds. */ readonly colStart: number; readonly colEnd: number; /** Inclusive positional row bounds. */ readonly rowStart: number; readonly rowEnd: number; } export declare class DependencyGraph { /** dependent → its precedents (for cleanup on re-set/removal). */ private readonly forward; /** precedent cell → set of dependents (single-cell reverse index). */ private readonly cellReverse; /** All range-precedent regions, scanned on change (bucketing is a Phase 6 optimization). */ private rangeDeps; /** * Replaces the dependencies of `dependent`, updating both reverse indexes. * * @param dependent - The formula cell whose precedents are being (re)declared. * @param cells - Its discrete single-cell precedents. * @param ranges - Its rectangular range precedents. */ setDependencies(dependent: CellId, cells: readonly CellId[], ranges: readonly RangeDependency[]): void; /** * Removes every dependency edge owned by `dependent`. * * @param dependent - The formula cell to detach. */ clearDependencies(dependent: CellId): void; /** * Adds every formula cell that directly depends on the changed cell into * `out`. * * @param changedCellId - Stable id of the cell that changed. * @param colIndex - Positional column index of the changed cell. * @param rowIndex - Positional row index of the changed cell. * @param out - Destination set (dependents are added, not replaced). */ collectDependents(changedCellId: CellId, colIndex: number, rowIndex: number, out: Set): void; /** @returns `true` when any formula cell is tracked. */ get hasDependencies(): boolean; /** @returns The number of formula cells with tracked dependencies. */ get size(): number; /** Removes every edge in the graph. */ clear(): void; } //# sourceMappingURL=dependency-graph.d.ts.map