topology work in progress

This commit is contained in:
Umur Ozkul 2022-08-25 21:59:15 +02:00
parent 9a536d2a38
commit 2d59898b4f
2 changed files with 41 additions and 0 deletions

View File

@ -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 == []
})
})

View File

@ -70,3 +70,28 @@ let getDependents = (this: t, sourceId: string): array<string> => {
let (_, dependents) = getTopologicalSortFor(this, sourceId)
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
}