Fix branchedResetPropagation #57

Merged
thepaperpilot merged 3 commits from nif/Profectus-Niffix:main into main 2024-02-14 17:39:07 +00:00

View file

@ -338,34 +338,21 @@ export const branchedResetPropagation = function (
tree: GenericTree, tree: GenericTree,
resettingNode: GenericTreeNode resettingNode: GenericTreeNode
): void { ): void {
const visitedNodes = [resettingNode]; const links = unref(tree.branches);
let currentNodes = [resettingNode]; if (links == null) return;
if (tree.branches != null) { const reset: GenericTreeNode[] = [];
const branches = unref(tree.branches); let current = [resettingNode];
while (currentNodes.length > 0) { while (current.length != 0) {
const nextNodes: GenericTreeNode[] = []; const next: GenericTreeNode[] = [];
currentNodes.forEach(node => { for (const node of current) {
branches for (const link of links.filter(link => link.startNode === node)) {
.filter(branch => branch.startNode === node || branch.endNode === node) if ([...reset, ...current].includes(link.endNode)) continue
.map(branch => { next.push(link.endNode);
if (branch.startNode === node) { link.endNode.reset?.reset();
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);
} }
};
reset.push(...current);
current = next;
} }
}; };