Class BoundedPriorityQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.openjdk.jmh.util.BoundedPriorityQueue<E>
- Type Parameters:
E- type of the element
- All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Queue<E>
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator<? super E> private final intprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionBoundedPriorityQueue(int maxSize) Creates a bounded priority queue with the specified maximum size and default ordering.BoundedPriorityQueue(int maxSize, Comparator<? super E> comparator) Creates a bounded priority queue with the specified maximum size. -
Method Summary
Methods inherited from class AbstractQueue
addAll, clear, element, removeMethods inherited from class AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Collection
contains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
maxSize
private final int maxSize -
comparator
-
queue
-
-
Constructor Details
-
BoundedPriorityQueue
public BoundedPriorityQueue(int maxSize) Creates a bounded priority queue with the specified maximum size and default ordering. At mostmaxSizesmallest elements would be kept in the queue.- Parameters:
maxSize- maximum size of the queue
-
BoundedPriorityQueue
Creates a bounded priority queue with the specified maximum size. At mostmaxSizesmallest elements would be kept in the queue.- Parameters:
maxSize- maximum size of the queuecomparator- comparator that orders the elements
-
-
Method Details
-
reverse
Internal queue should be in fact in reverse order. By default, the queue aims for "top N smallest elements". So peek() should return the biggest element, so it can be removed when adding smaller element- Type Parameters:
E- type of the element- Parameters:
comparator- comparator that designates ordering of the entries ornullfor default ordering- Returns:
- reverse comparator
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceQueue<E>- Overrides:
addin classAbstractQueue<E>
-
offer
-
poll
-
peek
-
iterator
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-