-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTopologicalData.swift
More file actions
88 lines (70 loc) · 2.78 KB
/
TopologicalData.swift
File metadata and controls
88 lines (70 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// TopologicalData.swift
//
//
// Created by Elliot Boschwitz on 6/4/24.
//
import Foundation
// TODO: topological data should be recalculated only when the node schema count and/or connections dict changes
// TODO: move wirelessBroadcastChoices outside of topological data
public struct GraphTopologicalData<Node: NodeCalculatable> {
public typealias InputRowId = Node.InputRow.RowID
public typealias OutputRowId = Node.OutputRow.RowID
public typealias ShallowDownstreamNodesDict = [Node.ID: Set<Node.ID>]
typealias CachedDownstreamNodes = [OutputRowId: Set<Node.ID>]
typealias UpstreamNodesCache = [Node.ID: Set<Node.ID>]
public typealias Connections = [OutputRowId: Set<InputRowId>]
typealias NodeCycles = Set<Set<Node.ID>>
typealias GraphDependencies = [Node.ID: [Node.ID]]
typealias NodeId = Node.ID
typealias NodeIdSet = Set<NodeId>
public init() { }
var nodesForNextGraphStep = Set<Node.ID>()
// Maps NodeID to set of connected input coordinates
var shallowDownstreamNodes = ShallowDownstreamNodesDict()
// Maps output coordinate to set of connected input coordinates
var cachedDownstreamIds = CachedDownstreamNodes()
// Tracks which nodes are in cycles
var nodeCycles = NodeCycles()
// Tracks preferred node starting points, which persist with documents
var preferredRootCycleNodes = NodeIdSet()
// Tracks all posible candidates for root cycles, resets whenever
// topological data is updated
var allCandidateRootCycleNodes = NodeIdSet()
var upstreamNodesCache = UpstreamNodesCache()
var connections = Connections()
var _allMustRunNodes = Set<Node.ID>()
// Memoizes a sorted list of nodes to eval given some set of node IDs
var memoizedQueues = [Set<Node.ID>: Node.ID]()
// Nodes that scheduled themselves via their node eval,
// e.g. Classic Animation node
var nodesScheduledToRun = Set<Node.ID>() {
didSet {
self._allMustRunNodes = self.getMustRunNodes()
}
}
// Nodes that need to run every graph step,
// e.g. Time node
// memoized: changes when patch node count changes.
var nodesToAlwaysRun = Set<Node.ID>() {
didSet {
self._allMustRunNodes = self.getMustRunNodes()
}
}
var keyboardNodes = Set<Node.ID>() {
didSet {
self._allMustRunNodes = self.getMustRunNodes()
}
}
}
extension GraphTopologicalData {
// fka `allMustRunNodes`
var nodesToRunOnGraphStep: Set<Node.ID> {
self._allMustRunNodes.union(self.nodesForNextGraphStep)
}
func getMustRunNodes() -> Set<Node.ID> {
self.nodesToAlwaysRun
.union(self.nodesScheduledToRun)
.union(self.keyboardNodes)
}
}