DAG: expose deterministic recompute levels

This commit is contained in:
2026-08-02 17:42:10 -04:00
parent a4b9d04ff4
commit ed5b1f3b67
4 changed files with 15 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ export type DependencyEdge = {
export type RecomputePlan = {
affected: string[]
order: string[]
levels: string[][]
cycles: string[][]
}
@@ -85,7 +86,14 @@ export class DependencyGraph {
if (!cyclic.has(nodeId)) order.push(nodeId)
}
for (const nodeId of affected) visitDependencies(nodeId)
return { affected: [...affected], order, cycles }
const levelByNode = new Map<string, number>()
for (const nodeId of order) {
const level = Math.max(0, ...this.dependenciesOf(nodeId).filter((dependency) => affected.has(dependency)).map((dependency) => (levelByNode.get(dependency) ?? 0) + 1))
levelByNode.set(nodeId, level)
}
const levels: string[][] = []
for (const nodeId of order) { const level = levelByNode.get(nodeId) ?? 0; (levels[level] ??= []).push(nodeId) }
return { affected: [...affected], order, levels, cycles }
}
findCycles(scope: Set<string> = this.nodes): string[][] {