Class BoundedPriorityQueue<E>

  • Type Parameters:
    E - type of the element
    All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Queue<E>

    public class BoundedPriorityQueue<E>
    extends AbstractQueue<E>
    implements Serializable
    Bounded variant of PriorityQueue. Note: elements are returned in reverse order. For instance, if "top N smallest elements" are required, use new BoundedPriorityQueue(N), and the elements would be returned in largest to smallest order.
    See Also:
    Serialized Form
    • Constructor Detail

      • BoundedPriorityQueue

        public BoundedPriorityQueue​(int maxSize)
        Creates a bounded priority queue with the specified maximum size and default ordering. At most maxSize smallest elements would be kept in the queue.
        Parameters:
        maxSize - maximum size of the queue
      • BoundedPriorityQueue

        public BoundedPriorityQueue​(int maxSize,
                                    Comparator<? super E> comparator)
        Creates a bounded priority queue with the specified maximum size. At most maxSize smallest elements would be kept in the queue.
        Parameters:
        maxSize - maximum size of the queue
        comparator - comparator that orders the elements