diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt index 8e61e22ce..c6f435c08 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt @@ -8,15 +8,16 @@ import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.RelativeSide import ru.dbotthepony.mc.otm.graph.GraphNodeList +import java.util.PriorityQueue import kotlin.math.ln class EnergyCableGraph : GraphNodeList() { - val livelyNodes = ObjectOpenHashSet() + val livelyNodes = HashSet() - private val pathCache = Object2ObjectOpenHashMap, Decimal?>() + private val pathCache = HashMap, Decimal?>() private class SearchNode(val node: EnergyCableBlockEntity.Node, target: EnergyCableBlockEntity.Node, var parent: SearchNode? = null) : Comparable { - var heuristics: Double = node.position.distSqr(target.position) * 0.0001 - ln(node.energyThroughput.coerceAtMost(Decimal.LONG_MAX_VALUE).toDouble()) + val heuristics: Double = node.position.distSqr(target.position) * 0.0001 - ln(node.energyThroughput.coerceAtMost(Decimal.LONG_MAX_VALUE).toDouble()) override fun compareTo(other: SearchNode): Int { return heuristics.compareTo(other.heuristics) @@ -39,13 +40,13 @@ class EnergyCableGraph : GraphNodeList() - val seenNodes = ObjectOpenHashSet() + val openNodes = PriorityQueue() + val seenNodes = HashSet() openNodes.add(SearchNode(a, b)) while (openNodes.isNotEmpty()) { - val first = openNodes.min() + val first = openNodes.remove() openNodes.remove(first) if (first.node === b) {