Interface PriorityQueueDouble<E>

Type Parameters:
E - The type of object contained in the PriorityQueueDouble.
All Superinterfaces:
Collection<PriorityQueueNode.Double<E>>, Iterable<PriorityQueueNode.Double<E>>, Queue<PriorityQueueNode.Double<E>>
All Known Subinterfaces:
MergeablePriorityQueueDouble<E,T>
All Known Implementing Classes:
BinaryHeapDouble, FibonacciHeapDouble

public interface PriorityQueueDouble<E> extends Queue<PriorityQueueNode.Double<E>>

Interface common to the classes that provide implementations of a priority queue with double valued priorities. All PriorityQueueDouble implementations enforce distinct elements, and use the Object.hashCode() and Object.equals(java.lang.Object) methods to to enforce distinctness, so be sure that the class of the elements properly implements these methods, or else behavior is not guaranteed.

  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    add(E element, double priority)
    Adds an (element, priority) pair to the PriorityQueueDouble with a specified priority, provided the element is not already in the PriorityQueueDouble.
    default boolean
    Adds an (element, priority) pair to the PriorityQueueDouble, provided the element is not already in the PriorityQueueDouble.
    default boolean
    Adds all (element, priority) pairs from a Collection to the PriorityQueueDouble, provided the elements are not already in the PriorityQueueDouble.
    boolean
    change(E element, double priority)
    Changes the priority of an element if the element is present in the PriorityQueueDouble, and otherwise adds the (element, priority) pair to the PriorityQueueDouble.
    void
    Clears the PriorityQueueDouble, removing all elements.
    boolean
    Checks if this PriorityQueueDouble contains a given element or an (element, priority) pair with a given element.
    default boolean
    Checks if this PriorityQueueDouble contains all elements or (element, priority) pairs from a given Collection.
    boolean
    demote(E element, double priority)
    Demotes an element relative to priority order if the element is present in the PriorityQueueDouble.
    Gets the next (element, priority) pair in priority order from this PriorityQueueDouble, without removing it.
    boolean
    Checks if the PriorityQueueDouble is empty.
    Returns an iterator over the (element, priority) pairs in a mostly arbitrary order (i.e., you must not assume any particular order).
    boolean
    offer(E element, double priority)
    Adds an (element, priority) pair to the PriorityQueueDouble with a specified priority, provided the element is not already in the PriorityQueueDouble.
    boolean
    Adds an (element, priority) pair to the PriorityQueueDouble, provided the element is not already in the PriorityQueueDouble.
    Gets the next (element, priority) pair in priority order from this PriorityQueueDouble, without removing it.
    Gets the next element in priority order from this PriorityQueueDouble, without removing it.
    double
    Gets the priority of the next element in priority order in the PriorityQueueDouble.
    double
    peekPriority(E element)
    Gets the priority of a specified element if it is present in the PriorityQueueDouble.
    Removes and returns the next (element, priority) pair in priority order from this PriorityQueueDouble.
    Removes and returns the next element in priority order from this PriorityQueueDouble.
    boolean
    promote(E element, double priority)
    Promotes an element relative to priority order if the element is present in the PriorityQueueDouble.
    Removes and returns the next (element, priority) pair in priority order from this PriorityQueueDouble.
    boolean
    Removes from this PriorityQueueDouble the (element, priority) pair, if present, for a specified element or element from a specified (element, priority) pair.
    boolean
    Removes from this PriorityQueueDouble all (element, priority) pairs such that a given Collection c either contains the element or contains an (element, priority) pair with the same element.
    default E
    Removes and returns the next element in priority order from this PriorityQueueDouble.
    boolean
    Removes from this PriorityQueueDouble all (element, priority) pairs except for the elements or (element, priority) pairs contained in a given Collection c.
    int
    Gets the current size of the PriorityQueueDouble, which is the number of (element, value) pairs that it contains.
    Returns an array containing all of the (element, priority) pairs contained in the PriorityQueueDouble.
    <T> T[]
    toArray(T[] array)
    Returns an array containing all of the (element, priority) pairs contained in the PriorityQueueDouble.

    Methods inherited from interface java.util.Collection

    equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach
  • Method Details

    • add

      default boolean add(E element, double priority)
      Adds an (element, priority) pair to the PriorityQueueDouble with a specified priority, provided the element is not already in the PriorityQueueDouble. This method differs from offer(Object, double) in that it throws an exception if the PriorityQueueDouble contains the element, while the offer method instead returns false.
      Parameters:
      element - The element.
      priority - The priority of the element.
      Returns:
      true if the (element, priority) pair was added.
      Throws:
      IllegalArgumentException - if the priority queue already contains the element.
    • add

      default boolean add(PriorityQueueNode.Double<E> pair)
      Adds an (element, priority) pair to the PriorityQueueDouble, provided the element is not already in the PriorityQueueDouble. This method differs from offer(PriorityQueueNode.Double) in that it throws an exception if the PriorityQueueDouble contains the element, while the offer method instead returns false.
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Queue<E>
      Parameters:
      pair - The (element, priority) pair to add.
      Returns:
      true if the (element, priority) pair was added.
      Throws:
      IllegalArgumentException - if the priority queue already contains the element.
    • addAll

      default boolean addAll(Collection<? extends PriorityQueueNode.Double<E>> c)
      Adds all (element, priority) pairs from a Collection to the PriorityQueueDouble, provided the elements are not already in the PriorityQueueDouble. The default implementation calls the add(PriorityQueueNode.Double) for each pair in the Collection.
      Specified by:
      addAll in interface Collection<E>
      Parameters:
      c - the Collection of (element, priority) pairs to add.
      Returns:
      true if the (element, priority) pairs were added.
      Throws:
      IllegalArgumentException - if the PriorityQueueDouble already contains any of the (element, priority) pairs.
    • change

      boolean change(E element, double priority)
      Changes the priority of an element if the element is present in the PriorityQueueDouble, and otherwise adds the (element, priority) pair to the PriorityQueueDouble.
      Parameters:
      element - The element whose priority is to change.
      priority - Its new priority.
      Returns:
      true if and only if the PriorityQueueDouble changed as a consequence of this method call.
    • clear

      void clear()
      Clears the PriorityQueueDouble, removing all elements.
      Specified by:
      clear in interface Collection<E>
    • contains

      boolean contains(Object o)
      Checks if this PriorityQueueDouble contains a given element or an (element, priority) pair with a given element.
      Specified by:
      contains in interface Collection<E>
      Parameters:
      o - An element or (element, priority) pair to check for containment of the element.
      Returns:
      true if and only if this PriorityQueueDouble contains the element.
    • containsAll

      default boolean containsAll(Collection<?> c)
      Checks if this PriorityQueueDouble contains all elements or (element, priority) pairs from a given Collection.
      Specified by:
      containsAll in interface Collection<E>
      Parameters:
      c - A Collection of elements or (element, priority) pairs to check for containment.
      Returns:
      true if and only if this PriorityQueueDouble contains all of the elements or (element, priority) pairs in c.
    • demote

      boolean demote(E element, double priority)
      Demotes an element relative to priority order if the element is present in the PriorityQueueDouble. For a min-heap, demotion means increasing the element's priority, while for a max-heap, demotion means decreasing its priority. If the element is not in the PriorityQueueDouble, or if its new priority is not a demotion, then this method does nothing.
      Parameters:
      element - The element whose priority is to change.
      priority - Its new priority.
      Returns:
      true if and only if the PriorityQueueDouble changed as a consequence of this method call.
    • element

      default PriorityQueueNode.Double<E> element()

      Gets the next (element, priority) pair in priority order from this PriorityQueueDouble, without removing it.

      This method differs from peek() in that if the PriorityQueueDouble is empty, this method throws an exception, while peek() returns null.

      This method serves a different purpose than peekElement(). The peekElement() methods returns only the element of the (element, priority) pair, while this method returns the (element, priority) pair. This element() method is included only for full implementation of the superinterface Queue.

      Specified by:
      element in interface Queue<E>
      Returns:
      the next (element, priority) pair in priority order.
      Throws:
      NoSuchElementException - if the PriorityQueueDouble is empty
    • isEmpty

      boolean isEmpty()
      Checks if the PriorityQueueDouble is empty.
      Specified by:
      isEmpty in interface Collection<E>
      Returns:
      true if and only if it is empty
    • iterator

      Returns an iterator over the (element, priority) pairs in a mostly arbitrary order (i.e., you must not assume any particular order).
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Returns:
      an iterator over the (element, priority) pairs
    • offer

      boolean offer(E element, double priority)
      Adds an (element, priority) pair to the PriorityQueueDouble with a specified priority, provided the element is not already in the PriorityQueueDouble.
      Parameters:
      element - The element.
      priority - The priority of the element.
      Returns:
      true if the (element, priority) pair was added, and false if the PriorityQueueDouble already contained the element.
    • offer

      boolean offer(PriorityQueueNode.Double<E> pair)
      Adds an (element, priority) pair to the PriorityQueueDouble, provided the element is not already in the PriorityQueueDouble.
      Specified by:
      offer in interface Queue<E>
      Parameters:
      pair - The (element, priority) pair to add.
      Returns:
      true if the (element, priority) pair was added, and false if the PriorityQueueDouble already contained the element.
    • peek

      Gets the next (element, priority) pair in priority order from this PriorityQueueDouble, without removing it.
      Specified by:
      peek in interface Queue<E>
      Returns:
      the next (element, priority) pair in priority order, or null if empty.
    • peekPriority

      double peekPriority()
      Gets the priority of the next element in priority order in the PriorityQueueDouble.
      Returns:
      the priority of the next element in priority order.
    • peekPriority

      double peekPriority(E element)
      Gets the priority of a specified element if it is present in the PriorityQueueDouble. This interface does not define the behavior when the element is not present. Implementations may define the behavior when the element is not present.
      Parameters:
      element - The element whose priority is returned.
      Returns:
      the priority of a specified element.
    • peekElement

      E peekElement()
      Gets the next element in priority order from this PriorityQueueDouble, without removing it.
      Returns:
      the next element in priority order, or null if empty.
    • poll

      Removes and returns the next (element, priority) pair in priority order from this PriorityQueueDouble.
      Specified by:
      poll in interface Queue<E>
      Returns:
      the next (element, priority) pair in priority order, or null if empty.
    • pollElement

      E pollElement()
      Removes and returns the next element in priority order from this PriorityQueueDouble.
      Returns:
      the next element in priority order, or null if empty.
    • promote

      boolean promote(E element, double priority)
      Promotes an element relative to priority order if the element is present in the PriorityQueueDouble. For a min-heap, promotion means decreasing the element's priority, while for a max-heap, promotion means increasing its priority. If the element is not in the PriorityQueueDouble, or if its new priority is not a promotion, then this method does nothing.
      Parameters:
      element - The element whose priority is to change.
      priority - Its new priority.
      Returns:
      true if and only if the PriorityQueueDouble changed as a consequence of this method call.
    • remove

      default PriorityQueueNode.Double<E> remove()
      Removes and returns the next (element, priority) pair in priority order from this PriorityQueueDouble. This method differs from poll() in that if the PriorityQueueDouble is empty, this method throws an exception, while poll() returns null.
      Specified by:
      remove in interface Queue<E>
      Returns:
      the next (element, priority) pair in priority order.
      Throws:
      NoSuchElementException - if the PriorityQueueDouble is empty
    • remove

      boolean remove(Object o)
      Removes from this PriorityQueueDouble the (element, priority) pair, if present, for a specified element or element from a specified (element, priority) pair.
      Specified by:
      remove in interface Collection<E>
      Parameters:
      o - An element or (element, priority) pair, such that element designates the desired pair to remove (note that if you pass an (element, priority) pair, only the element must match to cause removal.
      Returns:
      true if and only if an (element, priority) pair was removed as a result of this method call.
    • removeAll

      boolean removeAll(Collection<?> c)
      Removes from this PriorityQueueDouble all (element, priority) pairs such that a given Collection c either contains the element or contains an (element, priority) pair with the same element.
      Specified by:
      removeAll in interface Collection<E>
      Parameters:
      c - A Collection of elements or (element, priority) pairs for removal.
      Returns:
      true if and only if this PriorityQueueDouble changed as a result of this method.
    • removeElement

      default E removeElement()
      Removes and returns the next element in priority order from this PriorityQueueDouble. This method differs from pollElement() in that if the PriorityQueueDouble is empty, this method throws an exception, while pollElement() returns null.
      Returns:
      the next element in priority order.
      Throws:
      NoSuchElementException - if the PriorityQueueDouble is empty
    • retainAll

      boolean retainAll(Collection<?> c)
      Removes from this PriorityQueueDouble all (element, priority) pairs except for the elements or (element, priority) pairs contained in a given Collection c.
      Specified by:
      retainAll in interface Collection<E>
      Parameters:
      c - A Collection of elements or (element, priority) pairs to keep.
      Returns:
      true if and only if this PriorityQueueDouble changed as a result of this method.
    • size

      int size()
      Gets the current size of the PriorityQueueDouble, which is the number of (element, value) pairs that it contains.
      Specified by:
      size in interface Collection<E>
      Returns:
      the current size of the PriorityQueueDouble.
    • toArray

      Object[] toArray()
      Returns an array containing all of the (element, priority) pairs contained in the PriorityQueueDouble. The order is not guaranteed. The runtime component type is Object. The PriorityQueueDouble does not maintain any references to the array that is returned, instead creating a new array upon each call to the toArray method. The length of the array that is returned is equal to the current size() of the PriorityQueueDouble.
      Specified by:
      toArray in interface Collection<E>
      Returns:
      an array, whose runtime component type is Object, containing all of the (element, priority) pairs currently in the PriorityQueueDouble.
    • toArray

      <T> T[] toArray(T[] array)
      Returns an array containing all of the (element, priority) pairs contained in the PriorityQueueDouble. The order is not guaranteed. The runtime component type is the same as the array passed to it as a parameter. If the specified array is large enough, then it is used, otherwise a new array is allocated whose length is equal to the current size() of the PriorityQueueDouble. If the specified array is larger than the current size() of the PriorityQueueDouble, the first extra cell is set to null.
      Specified by:
      toArray in interface Collection<E>
      Type Parameters:
      T - The component type of the array to contain the (element, priority) pairs
      Parameters:
      array - The array in which to place the (element, priority) pairs, if it is sufficiently large, otherwise a new array of length size() is allocated of the same runtime type as array.
      Returns:
      The array in which the (element, priority) pairs have been inserted.
      Throws:
      ArrayStoreException - if the runtime component type of array is not compatible with the type of the (element, priority) pairs.
      NullPointerException - if array is null