Package com.badlogic.gdx.utils
Class BinaryHeap<T extends BinaryHeap.Node>
java.lang.Object
com.badlogic.gdx.utils.BinaryHeap<T>
A binary heap that stores nodes which each have a float value and are sorted either lowest first or highest first. The
BinaryHeap.Node
class can be extended to store additional information.-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds the node to the heap using its current value.Sets the node's value and adds it to the heap.void
clear()
boolean
Returns true if the heap contains the specified node.boolean
int
hashCode()
boolean
isEmpty()
Returns true if the heap is empty.boolean
notEmpty()
Returns true if the heap has one or more items.peek()
Returns the first item in the heap.pop()
Removes the first item in the heap and returns it.void
Changes the value of the node, which should already be in the heap.toString()
-
Field Details
-
size
public int size
-
-
Constructor Details
-
BinaryHeap
public BinaryHeap() -
BinaryHeap
public BinaryHeap(int capacity, boolean isMaxHeap)
-
-
Method Details
-
add
Adds the node to the heap using its current value. The node should not already be in the heap.- Returns:
- The specified node.
-
add
Sets the node's value and adds it to the heap. The node should not already be in the heap.- Returns:
- The specified node.
-
contains
Returns true if the heap contains the specified node.- Parameters:
identity
- If true, == comparison will be used. If false, .equals() comparison will be used.
-
peek
Returns the first item in the heap. This is the item with the lowest value (or highest value if this heap is configured as a max heap). -
pop
Removes the first item in the heap and returns it. This is the item with the lowest value (or highest value if this heap is configured as a max heap). -
remove
- Returns:
- The specified node.
-
notEmpty
public boolean notEmpty()Returns true if the heap has one or more items. -
isEmpty
public boolean isEmpty()Returns true if the heap is empty. -
clear
public void clear() -
setValue
Changes the value of the node, which should already be in the heap. -
equals
-
hashCode
public int hashCode() -
toString
-