## edu.stanford.nlp.util
Class FixedPrioritiesPriorityQueue<E>

    java.lang.Object
      java.util.AbstractCollection<E>
          java.util.AbstractSet<E>
              edu.stanford.nlp.util.FixedPrioritiesPriorityQueue<E>

All Implemented Interfaces:
  PriorityQueue<E>, Serializable, Cloneable, Iterable<E>, Collection<E>, Iterator<E>, Set<E>

    public class FixedPrioritiesPriorityQueue<E>

extends AbstractSet<E>
implements PriorityQueue<E>, Iterator<E>, Serializable, Cloneable

A priority queue based on a binary heap. This implementation trades flexibility for speed: while it is up to 2x faster than `BinaryHeapPriorityQueue` and nearly as fast as `PriorityQueue`, it does not support removing or changing the priority of an element. Also, while `getPriority(Object key)` is supported, performance will be linear, not constant.

Author:
  Dan Klein, Bill MacCartney
See Also:
  Serialized Form

Constructor Summary
`FixedPrioritiesPriorityQueue()`
`FixedPrioritiesPriorityQueue(int capacity)`

Method Summary
`boolean` `add(E key, double priority)` Adds a key to the queue with the given priority.
`boolean` `changePriority(E key, double priority)` Not supported in this implementation.
`void` `clear()`
`FixedPrioritiesPriorityQueue<E>` `clone()` Returns a clone of this priority queue.
`E` `getFirst()` Returns the highest-priority element without removing it from the queue.
`double` `getPriority()` Gets the priority of the highest-priority element of the queue.
`double` `getPriority(Object key)` Note that this method will be linear (not constant) time in this implementation! Better not to use it.
`boolean` `hasNext()` Returns true if the priority queue is non-empty
`Iterator<E>` `iterator()`
`static void` `main(String[] args)`
`E` `next()` Returns the element in the queue with highest priority, and pops it from the queue.
`boolean` `relaxPriority(E key, double priority)` Not supported in this implementation.
`void` `remove()` Not supported -- next() already removes the head of the queue.
`E` `removeFirst()` Returns the highest-priority element and removes it from the queue.
`int` `size()` Number of elements in the queue.
`List<E>` `toSortedList()`
`String` `toString()` Returns a representation of the queue in decreasing priority order.
`String` `toString(int maxKeysToPrint)` Returns a representation of the queue in decreasing priority order, displaying at most maxKeysToPring elements.

Methods inherited from class java.util.AbstractSet
`equals, hashCode, removeAll`

Methods inherited from class java.util.AbstractCollection
`add, addAll, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.util.Set
`add, addAll, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray`

Constructor Detail

### FixedPrioritiesPriorityQueue

    public FixedPrioritiesPriorityQueue()

### FixedPrioritiesPriorityQueue

    public FixedPrioritiesPriorityQueue(int capacity)

Method Detail

### hasNext

    public boolean hasNext()

  Returns true if the priority queue is non-empty

  Specified by:
    `hasNext` in interface `Iterator<E>`

### next

    public E next()

  Returns the element in the queue with highest priority, and pops it from the queue.

  Specified by:
    `next` in interface `Iterator<E>`

### remove

    public void remove()

  Not supported -- next() already removes the head of the queue.

  Specified by:
    `remove` in interface `Iterator<E>`

### add

    public boolean add(E key,
                       double priority)

  Adds a key to the queue with the given priority. If the key is already in the queue, it will be added an additional time, NOT promoted/demoted.

  Specified by:
    `add` in interface `PriorityQueue<E>`
  Returns:
    `true` if this set did not already contain the specified element.

### changePriority

    public boolean changePriority(E key,
                                  double priority)

  Not supported in this implementation.

  Specified by:
    `changePriority` in interface `PriorityQueue<E>`
  Parameters:
    `key` - an `E` value
  Returns:
    whether the priority actually changed.

### getFirst

    public E getFirst()

  Returns the highest-priority element without removing it from the queue.

  Specified by:
    `getFirst` in interface `PriorityQueue<E>`
  Returns:
    the object with minimum key

### getPriority

    public double getPriority(Object key)

  Note that this method will be linear (not constant) time in this implementation! Better not to use it.

  Specified by:
    `getPriority` in interface `PriorityQueue<E>`
  Parameters:
    `key` - The object to assess
  Returns:
    A key's priority. If the key is not in the queue, Double.NEGATIVE_INFINITY is returned.

### getPriority

    public double getPriority()

  Gets the priority of the highest-priority element of the queue.

  Specified by:
    `getPriority` in interface `PriorityQueue<E>`
  Returns:
    The priority of the highest-priority element of the queue.

### relaxPriority

    public boolean relaxPriority(E key,
                                 double priority)

  Not supported in this implementation.

  Specified by:
    `relaxPriority` in interface `PriorityQueue<E>`

### removeFirst

    public E removeFirst()

  Returns the highest-priority element and removes it from the queue.

  Specified by:
    `removeFirst` in interface `PriorityQueue<E>`
  Returns:
    the object with highest priority

### toSortedList

    public List<E> toSortedList()

  Specified by:
    `toSortedList` in interface `PriorityQueue<E>`

### size

    public int size()

  Number of elements in the queue.

  Specified by:
    `size` in interface `Collection<E>`
  Specified by:
    `size` in interface `Set<E>`
  Specified by:
    `size` in class `AbstractCollection<E>`

### clear

    public void clear()

  Specified by:
    `clear` in interface `Collection<E>`
  Specified by:
    `clear` in interface `Set<E>`
  Overrides:
    `clear` in class `AbstractCollection<E>`

### iterator

    public Iterator<E> iterator()

  Specified by:
    `iterator` in interface `Iterable<E>`
  Specified by:
    `iterator` in interface `Collection<E>`
  Specified by:
    `iterator` in interface `Set<E>`
  Specified by:
    `iterator` in class `AbstractCollection<E>`

### toString

    public String toString()

  Returns a representation of the queue in decreasing priority order.

  Overrides:
    `toString` in class `AbstractCollection<E>`

### toString

    public String toString(int maxKeysToPrint)

  Returns a representation of the queue in decreasing priority order, displaying at most maxKeysToPring elements.

  Specified by:
    `toString` in interface `PriorityQueue<E>`
  Parameters:
    `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.
  Returns:
    A String representation of the high priority items in the queue.

### clone

    public FixedPrioritiesPriorityQueue<E> clone()

  Returns a clone of this priority queue. Modifications to one will not affect modifications to the other.

  Overrides:
    `clone` in class `Object`

### main

    public static void main(String[] args)

Stanford NLP Group