Merge pull request #1051 from quantified-uncertainty/topsort-improvement
Topological sort improvement
This commit is contained in:
commit
f21f635bf0
|
@ -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> => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user