|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection
harpoon.Util.BinHeapPriorityQueue
public class BinHeapPriorityQueue
BinHeapPriorityQueue is an implementation of the
PriorityQueue interface. It supports O(1) time
peekMax and O(lg n) time insert and
removeMax operations, assuming that
ArrayList is implemented in a reasonable manner. The
remove operation is probably slow however.
Look into implementing a FibinocciHeap-based representation if
speed becomes an issue.
| Constructor Summary | |
|---|---|
BinHeapPriorityQueue()
|
|
BinHeapPriorityQueue(int size)
|
|
| Method Summary | |
|---|---|
void |
changePriority(Object item,
int delta)
Change the priority of this element by the specified delta. |
void |
clear()
|
boolean |
contains(Object item)
|
Object |
deleteMax()
Returns and removes the Object in
this with the highest priority. |
int |
getPriority(Object item)
Returns the priority currently associated with this item. |
boolean |
insert(Object item,
int priority)
Inserts item into this, assigning it priority
priority. |
Iterator |
iterator()
|
Object |
peekMax()
Returns the Object in this with the
highest priority. |
boolean |
remove(Object item)
|
int |
setPriority(Object item,
int priority)
Changes the priority of this Object
to the new, specified value, and returns the old value |
int |
size()
|
String |
toString()
|
| Methods inherited from class java.util.AbstractCollection |
|---|
add, addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
add, addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public BinHeapPriorityQueue()
public BinHeapPriorityQueue(int size)
| Method Detail |
|---|
public boolean insert(Object item,
int priority)
MaxPriorityQueueitem into this, assigning it priority
priority.
insert in interface MaxPriorityQueueitem - Object being insertedpriority - Priority of itempublic int getPriority(Object item)
MaxPriorityQueue
getPriority in interface MaxPriorityQueue
public int setPriority(Object item,
int priority)
MaxPriorityQueueObject
to the new, specified value, and returns the old value
setPriority in interface MaxPriorityQueue
public void changePriority(Object item,
int delta)
MaxPriorityQueuesetPriority(item, getPriority(item)+delta).
It might save time in some implementations.
- Specified by:
changePriority in interface MaxPriorityQueue
public Object peekMax()
MaxPriorityQueueObject in this with the
highest priority.
peekMax in interface MaxPriorityQueuepublic Object deleteMax()
MaxPriorityQueueObject in
this with the highest priority.
deleteMax in interface MaxPriorityQueuepublic boolean remove(Object item)
remove in interface Collectionremove in class AbstractCollectionpublic boolean contains(Object item)
contains in interface Collectioncontains in class AbstractCollectionpublic Iterator iterator()
iterator in interface Iterableiterator in interface Collectioniterator in class AbstractCollectionpublic void clear()
clear in interface Collectionclear in class AbstractCollectionpublic int size()
size in interface Collectionsize in class AbstractCollectionpublic String toString()
toString in class AbstractCollection
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||