crucial performance optimization

This commit is contained in:
Leijurv 2018-08-29 16:13:14 -07:00
parent 95cda79ef1
commit be303f2e57
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -108,14 +108,13 @@ public final class BinaryHeapOpenSet implements IOpenSet {
int smallerChild = 2; int smallerChild = 2;
double cost = val.combinedCost; double cost = val.combinedCost;
do { do {
int right = smallerChild + 1;
PathNode smallerChildNode = array[smallerChild]; PathNode smallerChildNode = array[smallerChild];
double smallerChildCost = smallerChildNode.combinedCost; double smallerChildCost = smallerChildNode.combinedCost;
if (right <= size) { if (smallerChild < size) {
PathNode rightChildNode = array[right]; PathNode rightChildNode = array[smallerChild + 1];
double rightChildCost = rightChildNode.combinedCost; double rightChildCost = rightChildNode.combinedCost;
if (smallerChildCost > rightChildCost) { if (smallerChildCost > rightChildCost) {
smallerChild = right; smallerChild++;
smallerChildCost = rightChildCost; smallerChildCost = rightChildCost;
smallerChildNode = rightChildNode; smallerChildNode = rightChildNode;
} }
@ -128,8 +127,7 @@ public final class BinaryHeapOpenSet implements IOpenSet {
val.heapPosition = smallerChild; val.heapPosition = smallerChild;
smallerChildNode.heapPosition = index; smallerChildNode.heapPosition = index;
index = smallerChild; index = smallerChild;
smallerChild = index << 1; } while ((smallerChild <<= 1) <= size);
} while (smallerChild <= size);
return result; return result;
} }
} }