|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectbcds.tools.PQWithNumericKey<E>
public class PQWithNumericKey<E>
A priority queue where the key is a value of type double.
It is a wrapper on java.util.PriorityQueue, with
the operation decreaseKey added.
Notes:
PQItemWithNumericKey. Such
items are internal and are never exposed.
| Constructor Summary | |
|---|---|
PQWithNumericKey()
Default constructor. |
|
| Method Summary | ||
|---|---|---|
void |
add(E elem,
double key)
Adds a new item consisting of elem and key. |
|
void |
addOrUpdate(E elem,
double key)
Adds a new item consisting of elem and key, or updates
it if it already exists (by calling decreaseKey(elem, key)). |
|
void |
clear()
Removes all the items. |
|
boolean |
contains(E e)
Returns true if this priority queue contains the element e, or null if the queue is empty. |
|
void |
decreaseKey(E elem,
double new_key)
Decreases the key of the item corresponding to elem,
setting its key to new_key. |
|
double |
getKey(E e)
Returns the key of the element e. |
|
boolean |
isEmpty()
Returns true if this priority queue is empty. |
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements, in no particular order. |
|
static
|
make()
Convenience "factory" method. |
|
E |
peekData()
Returns a reference to the data element of the item with the smallest key, or null if the queue is empty. |
|
double |
peekKey()
Returns the smallest key in the queue. |
|
E |
removeMin()
Removes the item with the smallest key and returns its data element. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PQWithNumericKey()
| Method Detail |
|---|
public static <E> PQWithNumericKey<E> make()
public void add(E elem,
double key)
elem and key.
java.lang.IllegalArgumentException - if the element already exists.
public void addOrUpdate(E elem,
double key)
elem and key, or updates
it if it already exists (by calling decreaseKey(elem, key)).
In its current implementation, this method "updates" the item by temporary removal and reinsertion with the new key.
java.lang.IllegalArgumentException - if the new key is larger than the
current one.public void clear()
public boolean isEmpty()
public E removeMin()
java.util.NoSuchElementException - if the queue is empty.
public void decreaseKey(E elem,
double new_key)
elem,
setting its key to new_key.
java.lang.IllegalArgumentException - if the element does not exist or
if the new key is larger than the current one.public E peekData()
public double peekKey()
java.util.NoSuchElementException - if the queue is empty.public boolean contains(E e)
e, or null if the queue is empty.
public double getKey(E e)
e.
java.util.NoSuchElementException - if e does not exist.public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||