topology work in progress
This commit is contained in:
parent
9a536d2a38
commit
2d59898b4f
|
@ -0,0 +1,16 @@
|
||||||
|
@@warning("-44")
|
||||||
|
module Topology = ReducerProject_Topology
|
||||||
|
|
||||||
|
open Jest
|
||||||
|
open Expect
|
||||||
|
open Expect.Operators
|
||||||
|
|
||||||
|
describe("Topology", () => {
|
||||||
|
Only.test("when equal 1x", () => {
|
||||||
|
Topology.runOrderDiff(["a"], ["a"])->expect == []
|
||||||
|
})
|
||||||
|
|
||||||
|
test("when equal 3x", () => {
|
||||||
|
Topology.runOrderDiff(["a", "b", "c"], ["a", "b", "c"])->expect == []
|
||||||
|
})
|
||||||
|
})
|
|
@ -70,3 +70,28 @@ let getDependents = (this: t, sourceId: string): array<string> => {
|
||||||
let (_, dependents) = getTopologicalSortFor(this, sourceId)
|
let (_, dependents) = getTopologicalSortFor(this, sourceId)
|
||||||
dependents
|
dependents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let runOrderDiff = (current: array<string>, previous0: array<string>): array<string> => {
|
||||||
|
let extraLength =
|
||||||
|
Belt.Array.length(current) > Belt.Array.length(previous0)
|
||||||
|
? Belt.Array.length(current) - Belt.Array.length(previous0)
|
||||||
|
: 0
|
||||||
|
let previous = Belt.Array.copy(previous0)
|
||||||
|
let filler = Belt.Array.make(extraLength, "")
|
||||||
|
Belt.Array.forEach(filler, _ => {
|
||||||
|
let _ = Js.Array2.push(previous, "")
|
||||||
|
})
|
||||||
|
let zipped = Belt.Array.zip(current, previous)
|
||||||
|
let (_, affected) = Belt.Array.reduce(zipped, (true, []), ((wasEqual, acc), (curr, prev)) => {
|
||||||
|
switch wasEqual {
|
||||||
|
| true =>
|
||||||
|
if curr == prev {
|
||||||
|
(true, Belt.Array.concat(acc, [curr]))
|
||||||
|
} else {
|
||||||
|
(false, acc)
|
||||||
|
}
|
||||||
|
| false => (false, acc)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
affected
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user