import { CalcChain } from './scheduler/calc-chain.js';
import { DirtyFrontier } from './scheduler/dirty-frontier.js';
export class RecalcScheduler {
    dirtyFrontier = new DirtyFrontier();
    calcChain;
    constructor(counters) {
        this.calcChain = new CalcChain(counters);
    }
    rebuildChain(formulaCellIndices, cellStore) {
        this.calcChain.rebuild(formulaCellIndices, cellStore);
    }
    collectDirty(changedRoots, graph, cellStore, formulaCellIndices, formulaCount, hasFormula, rangeCount) {
        const dirty = this.dirtyFrontier.collectDirty(changedRoots, graph, hasFormula, cellStore.size, rangeCount);
        if (!this.calcChain.hasChainFor(formulaCount) || !this.calcChain.coversDirty(dirty.dirtyFormulaCellIndices, dirty.dirtyFormulaCount)) {
            this.calcChain.rebuild(formulaCellIndices, cellStore);
        }
        const ordered = this.calcChain.orderDirty(dirty.dirtyFormulaCellIndices, dirty.dirtyFormulaCount);
        return {
            orderedFormulaCellIndices: ordered.orderedFormulaCellIndices,
            orderedFormulaCount: ordered.orderedFormulaCount,
            rangeNodeVisits: dirty.rangeNodeVisits,
        };
    }
    collectAll(formulaCellIndices, formulaCount, cellStore) {
        const formulaIndexArray = formulaCellIndices instanceof Uint32Array ? formulaCellIndices : Uint32Array.from(formulaCellIndices);
        if (!this.calcChain.hasChainFor(formulaCount) || !this.calcChain.coversDirty(formulaIndexArray, formulaCount)) {
            this.calcChain.rebuild(formulaIndexArray, cellStore);
        }
        const ordered = this.calcChain.orderAll();
        return {
            orderedFormulaCellIndices: ordered.orderedFormulaCellIndices,
            orderedFormulaCount: ordered.orderedFormulaCount,
            rangeNodeVisits: 0,
        };
    }
}
//# sourceMappingURL=scheduler.js.map