diff --git a/src/main/java/baritone/bot/pathing/calc/openset/BinaryHeapOpenSet.java b/src/main/java/baritone/bot/pathing/calc/openset/BinaryHeapOpenSet.java index a44c6d7c..0afc227a 100644 --- a/src/main/java/baritone/bot/pathing/calc/openset/BinaryHeapOpenSet.java +++ b/src/main/java/baritone/bot/pathing/calc/openset/BinaryHeapOpenSet.java @@ -46,7 +46,6 @@ public class BinaryHeapOpenSet implements IOpenSet { upHeap(size); } - @Override public void update(PathNode node) { upHeap(node.heapPosition); } @@ -58,19 +57,17 @@ public class BinaryHeapOpenSet implements IOpenSet { @Override public PathNode removeLowest() { - int s = --size; - if (s < 0) { - size++; // undo invalid decrement + if (size == 0) { throw new IllegalStateException(); } - PathNode[] arr = array; - PathNode result = arr[1]; - PathNode val = arr[s + 1]; - arr[1] = val; + PathNode result = array[1]; + PathNode val = array[size]; + array[1] = val; val.heapPosition = 1; - arr[s + 1] = null; + array[size] = null; + size--; result.heapPosition = -1; - if (s < 2) { + if (size < 2) { return result; } int index = 1; @@ -78,30 +75,27 @@ public class BinaryHeapOpenSet implements IOpenSet { double cost = val.combinedCost; do { int right = smallerChild + 1; - PathNode smallerChildNode = arr[smallerChild]; - double smallerChildCost; - if (right <= s) { - PathNode rightChildNode = arr[right]; - smallerChildCost = smallerChildNode.combinedCost; + PathNode smallerChildNode = array[smallerChild]; + double smallerChildCost = smallerChildNode.combinedCost; + if (right <= size) { + PathNode rightChildNode = array[right]; double rightChildCost = rightChildNode.combinedCost; if (smallerChildCost > rightChildCost) { smallerChild = right; smallerChildCost = rightChildCost; smallerChildNode = rightChildNode; } - } else { - smallerChildCost = smallerChildNode.combinedCost; } if (cost <= smallerChildCost) { break; } - arr[index] = smallerChildNode; - arr[smallerChild] = val; + array[index] = smallerChildNode; + array[smallerChild] = val; val.heapPosition = smallerChild; smallerChildNode.heapPosition = index; index = smallerChild; smallerChild = index << 1; - } while (smallerChild <= s); + } while (smallerChild <= size); return result; }