package com.badlogic.gdx.utils;\r
\r
/** @author Nathan Sweet */\r
-public class BinaryHeap<T> {\r
+public class BinaryHeap<T extends BinaryHeap.Node> {\r
public int size = 0;\r
\r
- private Node<T>[] nodes;\r
+ private Node[] nodes;\r
private final boolean isMaxHeap;\r
\r
public BinaryHeap () {\r
nodes = new Node[capacity];\r
}\r
\r
- public Node add (Node node) {\r
+ public T add (T node) {\r
// Expand if necessary.\r
if (size == nodes.length) {\r
Node[] newNodes = new Node[size << 1];\r
return node;\r
}\r
\r
- public Node pop () {\r
+ public T pop () {\r
Node[] nodes = this.nodes;\r
Node popped = nodes[0];\r
nodes[0] = nodes[--size];\r
nodes[size] = null;\r
if (size > 0) down(0);\r
- return popped;\r
+ return (T)popped;\r
}\r
\r
- public void setValue (Node node, float value) {\r
+ public void setValue (T node, float value) {\r
float oldValue = node.value;\r
node.value = value;\r
if (value < oldValue ^ isMaxHeap)\r
}\r
\r
/** @author Nathan Sweet */\r
- static public class Node<T> {\r
+ static public class Node {\r
float value;\r
int index;\r
\r
public Node (float value) {\r
this.value = value;\r
}\r
+\r
+ public float getValue () {\r
+ return value;\r
+ }\r
}\r
}\r