Package com.badlogic.gdx.utils
Class BinaryHeap<T extends BinaryHeap.Node>
- java.lang.Object
-
- com.badlogic.gdx.utils.BinaryHeap<T>
-
public class BinaryHeap<T extends BinaryHeap.Node> extends java.lang.ObjectA binary heap that stores nodes which each have a float value and are sorted either lowest first or highest first. TheBinaryHeap.Nodeclass can be extended to store additional information.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBinaryHeap.NodeA binary heap node.
-
Field Summary
Fields Modifier and Type Field Description intsize
-
Constructor Summary
Constructors Constructor Description BinaryHeap()BinaryHeap(int capacity, boolean isMaxHeap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tadd(T node)Adds the node to the heap using its current value.Tadd(T node, float value)Sets the node's value and adds it to the heap.voidclear()booleancontains(T node, boolean identity)Returns true if the heap contains the specified node.booleanequals(java.lang.Object obj)inthashCode()booleanisEmpty()Returns true if the heap is empty.booleannotEmpty()Returns true if the heap has one or more items.Tpeek()Returns the first item in the heap.Tpop()Removes the first item in the heap and returns it.Tremove(T node)voidsetValue(T node, float value)Changes the value of the node, which should already be in the heap.java.lang.StringtoString()
-
-
-
Method Detail
-
add
public T add(T node)
Adds the node to the heap using its current value. The node should not already be in the heap.- Returns:
- The specified node.
-
add
public T add(T node, float value)
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
public boolean contains(T node, boolean identity)
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
public T 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
public T 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).
-
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
public void setValue(T node, float value)
Changes the value of the node, which should already be in the heap.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-