|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsalvo.jesus.util.Heap
public class Heap
The Heap class implements a heap data structure, also called a priority queue.
Field Summary | |
---|---|
(package private) java.util.Vector |
binarytree
To hold the actual storage of the Heap class. |
(package private) HeapNodeComparator |
comparator
HeapNodeComparator to compare two heap nodes in the heap. |
Constructor Summary | |
---|---|
Heap()
Creates an instance of a Heap. |
|
Heap(HeapNodeComparator comparator)
Creates an instance of a Heap, with a specified HeapNodeComparator. |
Method Summary | |
---|---|
void |
clear()
Clears the heap, removing all nodes in the heap. |
HeapNode |
contains(java.lang.Object object,
java.util.Comparator heapnodeobjectcomparator)
Determines if the given object is encapsulated by one of the nodes in the heap. |
private int |
downHeap(int index)
Move the node, specified by the index, down in the heap until the heap condition is satisfied. |
void |
insert(HeapNode node)
Add a new item into the heap |
boolean |
isEmpty()
Checks if the heap is empty |
HeapNode |
remove()
Remove the item with the highest priority from the heap. |
void |
setPriority(HeapNode node,
double priority)
Sets the priority of a specific node in the heap, thereby also forcing to fixup the heap to satisfy the heap condition. |
java.lang.String |
toString()
Returns a String representation of the Heap. |
private int |
upHeap(int index)
Move the node, specified by the index, up in the heap until heap condition is satisfied. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
java.util.Vector binarytree
HeapNodeComparator comparator
Constructor Detail |
---|
public Heap()
public Heap(HeapNodeComparator comparator)
comapartor
- The HeapNodeComparator object to be used in comparing
the priorities of the nodes of the heap.Method Detail |
---|
public void insert(HeapNode node)
public HeapNode remove()
public void setPriority(HeapNode node, double priority)
node
- The HeapNode object whose priority is to be changedpriority
- The new priority that will be assigned to the heapnode.public void clear()
public boolean isEmpty()
public HeapNode contains(java.lang.Object object, java.util.Comparator heapnodeobjectcomparator)
private int upHeap(int index)
index
- 0-based index of the node we want to move up the heap.
private int downHeap(int index)
index
- 0-based index of the node we want to move down the heap.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |