UNPKG

1.14 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getMemoizedDepTree = exports.memoize = void 0;
4function memoize(nodeId, memoizationMap, depTree, partitionedCycles) {
5 const { cyclesStartWithThisNode, cyclesWithThisNode } = partitionedCycles;
6 if (cyclesStartWithThisNode.length > 0) {
7 const cycleNodeIds = new Set(...cyclesStartWithThisNode);
8 memoizationMap.set(nodeId, { depTree, cycleNodeIds });
9 }
10 else if (cyclesWithThisNode.length === 0) {
11 memoizationMap.set(nodeId, { depTree });
12 }
13 // Don't memoize nodes in cycles (cyclesWithThisNode.length > 0)
14}
15exports.memoize = memoize;
16function getMemoizedDepTree(nodeId, ancestors, memoizationMap) {
17 if (!memoizationMap.has(nodeId))
18 return null;
19 const { depTree, cycleNodeIds } = memoizationMap.get(nodeId);
20 if (!cycleNodeIds)
21 return depTree;
22 const ancestorsArePartOfTheCycle = ancestors.some((nodeId) => cycleNodeIds.has(nodeId));
23 return ancestorsArePartOfTheCycle ? null : depTree;
24}
25exports.getMemoizedDepTree = getMemoizedDepTree;
26//# sourceMappingURL=memiozation.js.map
\No newline at end of file