Package org.openjdk.jmh.util
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 int
private 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 java.util.AbstractQueue
addAll, clear, element, remove
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.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 mostmaxSize
smallest 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 mostmaxSize
smallest 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 ornull
for default ordering- Returns:
- reverse comparator
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceQueue<E>
- Overrides:
add
in classAbstractQueue<E>
-
offer
-
poll
-
peek
-
iterator
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<E>
-