getRunOrderFor runs topological sort from current id

This commit is contained in:
Vyacheslav Matyukhin 2022-09-01 17:57:04 +04:00
parent ec93a82110
commit dd3a8ab736
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C

View File

@ -44,31 +44,23 @@ let getTopologicalSort = (this: t): array<string> => {
Belt.List.reverse(stack)->Belt.List.toArray Belt.List.reverse(stack)->Belt.List.toArray
} }
let getTopologicalSortFor = (this: t, sourceId) => {
let runOrder = getTopologicalSort(this)
let index = runOrder->Js.Array2.indexOf(sourceId)
let after = Belt.Array.sliceToEnd(runOrder, index + 1)
let before = Js.Array2.slice(runOrder, ~start=0, ~end_=index + 1)
(before, after)
}
let getRunOrder = getTopologicalSort let getRunOrder = getTopologicalSort
let getRunOrderFor = (this: t, sourceId: string) => { let getRunOrderFor = (this: t, sourceId) => {
let (runOrder, _) = getTopologicalSortFor(this, sourceId) let (_visited, stack) = topologicalSortUtil(this, sourceId, (Belt.Map.String.empty, list{}))
runOrder Belt.List.reverse(stack)->Belt.List.toArray
} }
let getDependencies = (this: t, sourceId: string): array<string> => { let getDependencies = (this: t, sourceId: string): array<string> => {
let runOrder = getRunOrderFor(this, sourceId) let runOrder = getTopologicalSort(this)
let index = runOrder->Js.Array2.indexOf(sourceId)
let _ = Js.Array2.pop(runOrder) Js.Array2.slice(runOrder, ~start=0, ~end_=index)
runOrder
} }
let getDependents = (this: t, sourceId: string): array<string> => { let getDependents = (this: t, sourceId: string): array<string> => {
let (_, dependents) = getTopologicalSortFor(this, sourceId) let runOrder = getTopologicalSort(this)
dependents let index = runOrder->Js.Array2.indexOf(sourceId)
Belt.Array.sliceToEnd(runOrder, index + 1)
} }
let runOrderDiff = (current: array<string>, previous0: array<string>): array<string> => { let runOrderDiff = (current: array<string>, previous0: array<string>): array<string> => {