|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--gov.nist.antd.merlin.algorithm.route.util.BinaryHeap
This class implements a binary heap.
This class was developed at the National Institute of Standards and Technology by employees of the Federal Government in the course of their official duties. Pursuant to title 17 Section 105 of the United States Code this software is not subject to copyright protection and is in the public domain. NIST assumes no responsibility whatsoever for its use by other parties, and makes no guarantees, expressed or implied, about its quality, reliability, or any other characteristic.
We would appreciate acknowledgement if the software is used.
NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
| Nested Class Summary |
| Nested classes inherited from class gov.nist.antd.merlin.algorithm.route.util.PriorityQueue |
PriorityQueue.Position |
| Field Summary | |
private java.lang.Comparable[] |
array
The heap array |
private int |
currentSize
Number of elements in heap |
private static int |
DEFAULT_CAPACITY
Default capacity of this binary heap |
| Constructor Summary | |
BinaryHeap()
Default constructor |
|
BinaryHeap(java.lang.Comparable[] items)
Construct the binary heap from an array. |
|
| Method Summary | |
private void |
buildHeap()
Establish heap order property from an arbitrary arrangement of items. |
void |
decreaseKey(PriorityQueue.Position p,
java.lang.Comparable newVal)
Decrease the Key. |
java.lang.Comparable |
deleteMin()
Remove the smallest item from the priority queue. |
private void |
doubleArray()
Internal method to extend array. |
java.lang.Comparable |
findMin()
Find the smallest item in the priority queue. |
PriorityQueue.Position |
insert(java.lang.Comparable x)
Insert into the priority queue. |
boolean |
isEmpty()
Test if the priority queue is logically empty. |
void |
makeEmpty()
Make the priority queue logically empty. |
private void |
percolateDown(int hole)
Internal method to percolate down in the heap. |
int |
size()
Returns size. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static final int DEFAULT_CAPACITY
private int currentSize
private java.lang.Comparable[] array
| Constructor Detail |
public BinaryHeap()
public BinaryHeap(java.lang.Comparable[] items)
items - the inital items in the binary heap.| Method Detail |
public PriorityQueue.Position insert(java.lang.Comparable x)
insert in interface PriorityQueuex - the item to insert.
public void decreaseKey(PriorityQueue.Position p,
java.lang.Comparable newVal)
decreaseKey in interface PriorityQueuep - The Position of the key.newVal - The new value.public java.lang.Comparable findMin()
findMin in interface PriorityQueueUnderflowException - if empty.public java.lang.Comparable deleteMin()
deleteMin in interface PriorityQueueUnderflowException - if empty.private void buildHeap()
public boolean isEmpty()
isEmpty in interface PriorityQueuepublic int size()
size in interface PriorityQueuepublic void makeEmpty()
makeEmpty in interface PriorityQueueprivate void percolateDown(int hole)
hole - the index at which the percolate begins.private void doubleArray()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||