2018-08-05 03:19:32 +00:00
|
|
|
package baritone.bot.pathing.calc.openset;
|
2018-08-03 20:31:33 +00:00
|
|
|
|
|
|
|
import baritone.bot.pathing.calc.PathNode;
|
2018-08-03 13:55:17 +00:00
|
|
|
|
|
|
|
/**
|
2018-08-03 15:45:11 +00:00
|
|
|
* A linked list implementation of an open set. This is the original implementation from MineBot.
|
2018-08-06 01:17:04 +00:00
|
|
|
* It has incredibly fast insert performance, at the cost of O(n) removeLowest.
|
|
|
|
*
|
|
|
|
* @author leijurv
|
2018-08-03 13:55:17 +00:00
|
|
|
*/
|
|
|
|
public class LinkedListOpenSet implements IOpenSet {
|
2018-08-03 16:50:09 +00:00
|
|
|
private Node first = null;
|
2018-08-03 13:55:17 +00:00
|
|
|
|
2018-08-05 15:30:50 +00:00
|
|
|
@Override
|
2018-08-03 13:55:17 +00:00
|
|
|
public boolean isEmpty() {
|
|
|
|
return first == null;
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:30:50 +00:00
|
|
|
@Override
|
2018-08-03 16:50:09 +00:00
|
|
|
public void insert(PathNode pathNode) {
|
|
|
|
Node node = new Node();
|
|
|
|
node.val = pathNode;
|
2018-08-03 13:55:17 +00:00
|
|
|
node.nextOpen = first;
|
|
|
|
first = node;
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:30:50 +00:00
|
|
|
@Override
|
|
|
|
public void update(PathNode node) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-03 13:55:17 +00:00
|
|
|
public PathNode removeLowest() {
|
|
|
|
if (first == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-03 16:50:09 +00:00
|
|
|
Node current = first.nextOpen;
|
2018-08-03 13:55:17 +00:00
|
|
|
if (current == null) {
|
2018-08-03 16:50:09 +00:00
|
|
|
Node n = first;
|
2018-08-03 13:55:17 +00:00
|
|
|
first = null;
|
2018-08-03 16:50:09 +00:00
|
|
|
return n.val;
|
2018-08-03 13:55:17 +00:00
|
|
|
}
|
2018-08-03 16:50:09 +00:00
|
|
|
Node previous = first;
|
|
|
|
double bestValue = first.val.combinedCost;
|
|
|
|
Node bestNode = first;
|
|
|
|
Node beforeBest = null;
|
2018-08-03 13:55:17 +00:00
|
|
|
while (current != null) {
|
2018-08-03 16:50:09 +00:00
|
|
|
double comp = current.val.combinedCost;
|
2018-08-03 13:55:17 +00:00
|
|
|
if (comp < bestValue) {
|
|
|
|
bestValue = comp;
|
|
|
|
bestNode = current;
|
|
|
|
beforeBest = previous;
|
|
|
|
}
|
|
|
|
previous = current;
|
|
|
|
current = current.nextOpen;
|
|
|
|
}
|
|
|
|
if (beforeBest == null) {
|
|
|
|
first = first.nextOpen;
|
2018-08-03 16:50:09 +00:00
|
|
|
bestNode.nextOpen = null;
|
|
|
|
return bestNode.val;
|
2018-08-03 13:55:17 +00:00
|
|
|
}
|
|
|
|
beforeBest.nextOpen = bestNode.nextOpen;
|
2018-08-03 16:50:09 +00:00
|
|
|
bestNode.nextOpen = null;
|
|
|
|
return bestNode.val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Node { //wrapper with next
|
|
|
|
Node nextOpen;
|
|
|
|
PathNode val;
|
2018-08-03 13:55:17 +00:00
|
|
|
}
|
|
|
|
}
|