This commit is contained in:
Leijurv 2018-08-06 11:48:30 -07:00
parent 25663c54e7
commit 3eef5e2972
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -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;
}