1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-07-07 04:14:26 +00:00
CC-Tweaked/projects/common
Jonathan Coates 84b6edab82
More efficient removal of wired nodes from networks
When we remove a wired node from a network, we need to find connected
components in the rest of the graph. Typically, this requires a
traversal of the whole graph, taking O(|V| + |E|) time.

If we remove a lot of nodes at once (such as when unloading chunks),
this ends up being quadratic in the number of nodes. In some test
networks, this can take anywhere from a few seconds, to hanging the game
indefinitely.

This attempts to reduce the cases where this can happen, with a couple
of optimisations:

 - Instead of constructing a new hash set of reachable nodes (requiring
   multiple allocations and hash lookups), we store reachability as a
   temporary field on the WiredNode.

 - We abort our traversal of the graph if we can prove the graph remains
   connected after removing the node.

There's definitely future work to be done here in optimising large wired
networks, but this is a good first step.
2024-02-24 15:02:34 +00:00
..
src More efficient removal of wired nodes from networks 2024-02-24 15:02:34 +00:00
build.gradle.kts Clean up the wired network tests 2024-02-24 14:52:44 +00:00