E
- Type of elements in the priority queuepublic class BinaryHeapPriorityQueue<E> extends AbstractSet<E> implements PriorityQueue<E>, 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(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.
|
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(Object key) |
E |
removeFirst()
Finds the E with the highest priority, removes it,
and returns it.
|
int |
size()
Get the number of elements in the queue.
|
List<E> |
toSortedList() |
String |
toString() |
String |
toString(int maxKeysToPrint)
Returns a representation of the queue in decreasing priority order,
displaying at most maxKeysToPrint elements.
|
String |
toVerticalString() |
equals, hashCode, removeAll
addAll, containsAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
forEachRemaining
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 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)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollection<E>
key
- an E
valuepublic 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>
public boolean remove(Object key)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollection<E>
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()
isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
boolean
valuepublic int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public boolean contains(Object key)
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
public 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 void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public String toString()
toString
in class AbstractCollection<E>
public 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 String toVerticalString()