Improve cable path search performance when there are a lot of paths existing already
This commit is contained in:
parent
590f420c07
commit
89ca0fbce8
@ -426,6 +426,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
|
||||
openNodes.add(SearchNode(a, b, null, seenTop))
|
||||
|
||||
val existingNodes = HashSet<EnergyCableBlockEntity.Node>()
|
||||
existing.forEach { existingNodes.addAll(it.nodes) }
|
||||
|
||||
while (openNodes.isNotEmpty()) {
|
||||
val first = openNodes.remove()
|
||||
openNodes.remove(first)
|
||||
@ -466,7 +469,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
} else {
|
||||
for (neighbour in first.node.neighboursView.values) {
|
||||
if (!seenNodes.add(neighbour) || !neighbour.canTraverse) continue
|
||||
val seen = existing.any { neighbour in it }
|
||||
val seen = neighbour in existingNodes
|
||||
if (seen && neighbour.energyThroughput <= threshold) continue
|
||||
openNodes.add(SearchNode(neighbour, b, first, seen))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user