-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTopologicalDataRefresh.swift
More file actions
59 lines (45 loc) · 2.1 KB
/
TopologicalDataRefresh.swift
File metadata and controls
59 lines (45 loc) · 2.1 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
//
// TopologicalDataRefresh.swift
//
//
// Created by Elliot Boschwitz on 6/8/24.
//
import Foundation
extension GraphCalculatable {
@MainActor
public func updateTopologicalData() {
print("TopologicalData init")
// Save any IDs that we still need to calculate
let prevIdsToCalculate = self.topologicalData.nodesForNextGraphStep
// All nodes excludes group nodes
let allNodes = Array(self.nodes.values.filter { !$0.isGroupNode })
let connections = self.createConnections()
// Maps connections by node instead of by coordinate
let downstream = TopologicalData
.createShallowDownstreamNodes(allNodes: allNodes,
connections: connections)
// Skip if no nodes
guard !allNodes.isEmpty else {
return
}
// Saves edges by coordinate
self.setConnections(connections)
// Reset candidate root cycle node data, which gets updated lazily by graph computation
self.topologicalData.allCandidateRootCycleNodes = .init()
self.nodesForNextGraphStep = prevIdsToCalculate
// Gets a set of all node cycles
self.topologicalData.nodeCycles = TopologicalData
.findAllCycles(downstreamNodesMap: downstream)
self.topologicalData.shallowDownstreamNodes = downstream
self.topologicalData.cachedDownstreamIds = Self.TopologicalData.createCachedDownstreamNodes(connections: connections)
self.topologicalData.nodesToAlwaysRun = self.getNodesToAlwaysRun()
self.topologicalData.nodesScheduledToRun = self.getAnimationNodes()
self.topologicalData.keyboardNodes = self.topologicalData.keyboardNodes
self.topologicalData._allMustRunNodes = self.topologicalData.nodesToAlwaysRun
.union(self.topologicalData.nodesScheduledToRun)
.union(self.topologicalData.keyboardNodes)
let allNodeIds = Set(self.nodes.keys)
self.calculate(from: allNodeIds,
willResetCyclePreferences: true)
}
}