moving away from linked list, so remove nextOpen from PathNode

This commit is contained in:
Leijurv 2018-08-03 12:50:09 -04:00
parent cd2b5d001e
commit d382de2b52
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 22 additions and 18 deletions

View File

@ -54,7 +54,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
PathNode currentNode = openSet.removeLowest();
mostRecentConsidered = currentNode;
currentNode.isOpen = false;
currentNode.nextOpen = null;
BlockPos currentNodePos = currentNode.pos;
numNodes++;
if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second

View File

@ -5,13 +5,15 @@ package baritone.bot.pathing.calc;
* It has incredbly fast insert performance, at the cost of O(n) removeLowest.
*/
public class LinkedListOpenSet implements IOpenSet {
private PathNode first = null;
private Node first = null;
public boolean isEmpty() {
return first == null;
}
public void insert(PathNode node) {
public void insert(PathNode pathNode) {
Node node = new Node();
node.val = pathNode;
node.nextOpen = first;
first = node;
}
@ -20,18 +22,18 @@ public class LinkedListOpenSet implements IOpenSet {
if (first == null) {
return null;
}
PathNode current = first.nextOpen;
Node current = first.nextOpen;
if (current == null) {
PathNode n = first;
Node n = first;
first = null;
return n;
return n.val;
}
PathNode previous = first;
double bestValue = first.combinedCost;
PathNode bestNode = first;
PathNode beforeBest = null;
Node previous = first;
double bestValue = first.val.combinedCost;
Node bestNode = first;
Node beforeBest = null;
while (current != null) {
double comp = current.combinedCost;
double comp = current.val.combinedCost;
if (comp < bestValue) {
bestValue = comp;
bestNode = current;
@ -42,9 +44,16 @@ public class LinkedListOpenSet implements IOpenSet {
}
if (beforeBest == null) {
first = first.nextOpen;
return bestNode;
bestNode.nextOpen = null;
return bestNode.val;
}
beforeBest.nextOpen = bestNode.nextOpen;
return bestNode;
bestNode.nextOpen = null;
return bestNode.val;
}
public static class Node { //wrapper with next
Node nextOpen;
PathNode val;
}
}

View File

@ -30,14 +30,10 @@ class PathNode {
/**
* Is this a member of the open set in A*? (only used during pathfinding)
* Instead of doing a costly member check in the open set, cache membership in each node individually too.
*/
boolean isOpen;
/**
* In the linked list of open nodes, which one is next? (only used during pathfinding)
*/
PathNode nextOpen;
public PathNode(BlockPos pos, Goal goal) {
this.pos = pos;
this.previous = null;