E
- Type of elements in the priority queuepublic class BinaryHeapPriorityQueue<E> extends java.util.AbstractSet<E> implements PriorityQueue<E>, java.util.Iterator<E>
Constructor and Description |
---|
BinaryHeapPriorityQueue() |
BinaryHeapPriorityQueue(int initCapacity) |
BinaryHeapPriorityQueue(MapFactory<E,edu.stanford.nlp.util.BinaryHeapPriorityQueue.Entry<E>> mapFactory) |
BinaryHeapPriorityQueue(MapFactory<E,edu.stanford.nlp.util.BinaryHeapPriorityQueue.Entry<E>> mapFactory,
int initCapacity) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E key)
Adds an object to the queue with the minimum priority
(Double.NEGATIVE_INFINITY).
|
boolean |
add(E key,
double priority)
Convenience method for if you want to pretend relaxPriority doesn't exist,
or if you really want to use the return conditions of add().
|
boolean |
changePriority(E key,
double priority)
Changes a priority, either up or down, adding the key it if it wasn't there already.
|
void |
clear()
Clears the queue.
|
boolean |
contains(java.lang.Object key)
Returns whether the queue contains the given key.
|
boolean |
decreasePriority(E key,
double priority)
Demotes a key in the queue, adding it if it wasn't there already.
|
BinaryHeapPriorityQueue<E> |
deepCopy() |
BinaryHeapPriorityQueue<E> |
deepCopy(MapFactory<E,edu.stanford.nlp.util.BinaryHeapPriorityQueue.Entry<E>> mapFactory) |
E |
getFirst()
Finds the E with the highest priority and returns it, without
modifying the queue.
|
E |
getObject(E key)
Searches for the object in the queue and returns it.
|
double |
getPriority()
Gets the priority of the highest-priority element of the queue
(without modifying the queue).
|
double |
getPriority(E key)
Get the priority of a key.
|
boolean |
hasNext() |
boolean |
isEmpty()
Checks if the queue is empty.
|
java.util.Iterator<E> |
iterator() |
E |
next() |
boolean |
relaxPriority(E key,
double priority)
Promotes a key in the queue, adding it if it wasn't there already.
|
void |
remove() |
boolean |
remove(java.lang.Object key) |
E |
removeFirst()
Finds the E with the highest priority, removes it,
and returns it.
|
void |
removeLastEntry()
Remove the last element of the heap (last in the index array).
|
int |
size()
Get the number of elements in the queue.
|
java.util.List<E> |
toSortedList() |
java.lang.String |
toString() |
java.lang.String |
toString(int maxKeysToPrint)
Returns a representation of the queue in decreasing priority order,
displaying at most maxKeysToPrint elements.
|
java.lang.String |
toVerticalString() |
addAll, containsAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public BinaryHeapPriorityQueue()
public BinaryHeapPriorityQueue(int initCapacity)
public BinaryHeapPriorityQueue(MapFactory<E,edu.stanford.nlp.util.BinaryHeapPriorityQueue.Entry<E>> mapFactory)
public BinaryHeapPriorityQueue(MapFactory<E,edu.stanford.nlp.util.BinaryHeapPriorityQueue.Entry<E>> mapFactory, int initCapacity)
public boolean hasNext()
hasNext
in interface java.util.Iterator<E>
public void remove()
remove
in interface java.util.Iterator<E>
public void removeLastEntry()
public E removeFirst()
removeFirst
in interface PriorityQueue<E>
public E getFirst()
getFirst
in interface PriorityQueue<E>
public double getPriority()
getPriority
in interface PriorityQueue<E>
public E getObject(E key)
public double getPriority(E key)
getPriority
in interface PriorityQueue<E>
key
- The object to assesspublic boolean add(E key)
public boolean add(E key, double priority)
Warning: The semantics of this method currently varies between implementations. In some implementations, nothing will be changed if the key is already in the priority queue. In others, the element will be added a second time with the new priority. We maybe should at least change things so that the priority will be change to the priority given if the element is in the queue with a lower priority, but that wasn't the historical behavior, and it seemed like we'd need to do a lot of archeology before changing the behavior.
add
in interface PriorityQueue<E>
true
if this set did not already contain the specified
element.public boolean remove(java.lang.Object key)
public boolean relaxPriority(E key, double priority)
relaxPriority
in interface PriorityQueue<E>
key
- an Object
valuepublic boolean decreasePriority(E key, double priority)
key
- an Object
valuepublic boolean changePriority(E key, double priority)
changePriority
in interface PriorityQueue<E>
key
- an Object
valuepublic boolean isEmpty()
public int size()
public boolean contains(java.lang.Object key)
public java.util.List<E> toSortedList()
toSortedList
in interface PriorityQueue<E>
public BinaryHeapPriorityQueue<E> deepCopy(MapFactory<E,edu.stanford.nlp.util.BinaryHeapPriorityQueue.Entry<E>> mapFactory)
public BinaryHeapPriorityQueue<E> deepCopy()
public java.util.Iterator<E> iterator()
public void clear()
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public java.lang.String toString(int maxKeysToPrint)
toString
in interface PriorityQueue<E>
maxKeysToPrint
- The maximum number of keys to print. Less are
printed if there are less than this number of items in the
PriorityQueue. If this number is non-positive, then all elements in
the PriorityQueue are printed.public java.lang.String toVerticalString()