|
datastructures | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.datastructures.HeapPriorityQueue
Realization of a priority queue by means of a heap. The heap is built upon a vector-based complete binary tree.
| Nested Class Summary | |
protected static class |
HeapPriorityQueue.DefaultComparator
Inner class for a comparator that uses the natural ordering of keys. |
protected static class |
HeapPriorityQueue.MyEntry
Inner class for heap entries. |
| Field Summary | |
protected Comparator |
comp
|
protected CompleteBinaryTree |
T
|
| Constructor Summary | |
HeapPriorityQueue()
Creates an empty heap with the default comparator. |
|
HeapPriorityQueue(Comparator c)
Creates an empty heap with the given comparator. |
|
| Method Summary | |
protected void |
checkKey(Object key)
Determines whether a given key is valid. |
protected void |
downHeap(Position r)
Performs down-heap bubbling. |
protected Entry |
entry(Position p)
Returns the entry stored at a heap node. |
Entry |
insert(Object k,
Object x)
Inserts a key-value pair and return the entry created. |
boolean |
isEmpty()
Returns whether the heap is empty. |
protected Object |
key(Position p)
Returns the key stored at a heap node. |
Entry |
min()
Returns but does not remove an entry with minimum key. |
Entry |
removeMin()
Removes and returns an entry with minimum key. |
void |
setComparator(Comparator c)
Sets the comparator used for comparing items in the heap. |
int |
size()
Returns the size of the heap. |
protected void |
swapElements(Position x,
Position y)
Swaps the elements of the two positions. |
String |
toString()
Text visualization for debugging purposes |
protected void |
upHeap(Position v)
Performs up-heap bubbling. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected CompleteBinaryTree T
protected Comparator comp
| Constructor Detail |
public HeapPriorityQueue()
public HeapPriorityQueue(Comparator c)
| Method Detail |
public void setComparator(Comparator c)
throws IllegalStateException
IllegalStateException - if priority queue is not emptypublic int size()
size in interface PriorityQueuepublic boolean isEmpty()
isEmpty in interface PriorityQueue
public Entry min()
throws EmptyPriorityQueueException
min in interface PriorityQueueEmptyPriorityQueueException
public Entry insert(Object k,
Object x)
throws InvalidKeyException
insert in interface PriorityQueueInvalidKeyException
public Entry removeMin()
throws EmptyPriorityQueueException
removeMin in interface PriorityQueueEmptyPriorityQueueExceptionprotected Entry entry(Position p)
protected Object key(Position p)
protected void checkKey(Object key)
throws InvalidKeyException
InvalidKeyExceptionprotected void upHeap(Position v)
protected void downHeap(Position r)
protected void swapElements(Position x,
Position y)
public String toString()
|
datastructures | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||