Fix branchedResetPropagation
Some checks failed
Run Tests / test (pull_request) Has been cancelled

BREAKING CHANGE - Forces branches to be directed

Signed-off-by: nif <nif@incremental.social>
This commit is contained in:
Nif 2024-02-12 19:46:31 +00:00
parent 4f807aaf96
commit 5e32fa4985

View file

@ -338,34 +338,21 @@ export const branchedResetPropagation = function (
tree: GenericTree,
resettingNode: GenericTreeNode
): void {
const visitedNodes = [resettingNode];
let currentNodes = [resettingNode];
if (tree.branches != null) {
const branches = unref(tree.branches);
while (currentNodes.length > 0) {
const nextNodes: GenericTreeNode[] = [];
currentNodes.forEach(node => {
branches
.filter(branch => branch.startNode === node || branch.endNode === node)
.map(branch => {
if (branch.startNode === node) {
return branch.endNode;
}
return branch.startNode;
})
.filter(node => !visitedNodes.includes(node))
.forEach(node => {
// Check here instead of in the filter because this check's results may
// change as we go through each node
if (!nextNodes.includes(node)) {
nextNodes.push(node);
node.reset?.reset();
}
});
});
currentNodes = nextNodes;
visitedNodes.push(...currentNodes);
}
const links = unref(tree.branches);
if (links === undefined) return;
let reset: GenericTreeNode[] = [];
let current = [resettingNode];
while (current.length != 0) {
let next: GenericTreeNode[] = [];
for (let node of current) {
for (let link of links.filter(link => link.startNode === node)) {
if ([...reset, ...current].includes(link.endNode)) continue
next.push(link.endNode);
link.endNode.reset?.reset();
}
};
reset = reset.concat(current);
current = next;
}
};