/** * Dependency Graph for Formula Calculation * * Builds a dependency graph from compiled formulas' static dependencies, * then produces a topological evaluation order with circular reference * detection. * * Key exports: * - `buildDependencyGraphFromDeps()` — build graph from CompiledFormula static deps * - `topologicalSort()` — produce evaluation order, detecting circular refs */ /** * The dependency graph structure. * * - `dependsOn`: formula cell key → set of cell keys it reads from * - `dependedBy`: cell key → set of formula cell keys that read from it * - `formulaKeys`: ordered list of all formula cell keys * - `circularKeys`: set of formula cell keys involved in circular references */ export interface DependencyGraph { /** Forward edges: formula → cells it depends on */ readonly dependsOn: ReadonlyMap>; /** Reverse edges: cell → formulas that depend on it */ readonly dependedBy: ReadonlyMap>; /** All formula cell keys in insertion order */ readonly formulaKeys: readonly string[]; /** Formula cell keys that are part of a circular reference cycle */ readonly circularKeys: ReadonlySet; } /** * Build a dependency graph from compiled formulas' static dependencies. * * Operates on the already-resolved `StaticDependencySet` from each compiled * formula. Since names and structured references are already resolved by * the binder, the dependency edges are complete. * * @param compiled - Map from formula cell key to compiled formula with static deps * @param producerMap - Optional map from cell key → formula key that produces * that cell's value (via CSE distribution or dynamic-array spill). Allows * dependency edges to be added to the producer even when the target cell * isn't itself a formula. * @returns The complete dependency graph */ export declare function buildDependencyGraphFromDeps(compiled: ReadonlyMap, producerMap?: ReadonlyMap): DependencyGraph; /** * Merge runtime-discovered dynamic dependencies into a dependency graph. * * After evaluating formulas that contain INDIRECT/OFFSET, the runtime * dependency recorder has collected the actual cell accesses. This function * incorporates those dynamic edges into the graph and re-detects cycles. * * Returns a new graph if edges were added, or the original graph if no * dynamic deps were recorded. */ export declare function mergeDynamicDeps(graph: DependencyGraph, dynamicDeps: ReadonlyMap>): { graph: DependencyGraph; changed: boolean; }; /** * Produce a topological evaluation order for formula cells using Kahn's algorithm. * Cells with no dependencies are evaluated first. Circular references are * appended at the end in their original order. */ export declare function topologicalSort(graph: DependencyGraph): string[];