|
|||||||||
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)
MaxPriorityQueue
item
into this, assigning it priority
priority
.
insert
in interface MaxPriorityQueue
item
- Object
being insertedpriority
- Priority of item
public int getPriority(Object item)
MaxPriorityQueue
getPriority
in interface MaxPriorityQueue
public int setPriority(Object item, int priority)
MaxPriorityQueue
Object
to the new, specified value, and returns the old value
setPriority
in interface MaxPriorityQueue
public void changePriority(Object item, int delta)
MaxPriorityQueue
setPriority(item, getPriority(item)+delta).
It might save time in some implementations.
- Specified by:
changePriority
in interface MaxPriorityQueue
public Object peekMax()
MaxPriorityQueue
Object
in this
with the
highest priority.
peekMax
in interface MaxPriorityQueue
public Object deleteMax()
MaxPriorityQueue
Object
in
this
with the highest priority.
deleteMax
in interface MaxPriorityQueue
public boolean remove(Object item)
remove
in interface Collection
remove
in class AbstractCollection
public boolean contains(Object item)
contains
in interface Collection
contains
in class AbstractCollection
public Iterator iterator()
iterator
in interface Iterable
iterator
in interface Collection
iterator
in class AbstractCollection
public void clear()
clear
in interface Collection
clear
in class AbstractCollection
public int size()
size
in interface Collection
size
in class AbstractCollection
public String toString()
toString
in class AbstractCollection
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |