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:
java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Queue<E>
public class BoundedPriorityQueue<E> extends java.util.AbstractQueue<E> implements java.io.Serializable
Bounded variant ofPriorityQueue
. Note: elements are returned in reverse order. For instance, if "top N smallest elements" are required, usenew BoundedPriorityQueue(N)
, and the elements would be returned in largest to smallest order.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Comparator<? super E>
comparator
private int
maxSize
private java.util.Queue<E>
queue
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description BoundedPriorityQueue(int maxSize)
Creates a bounded priority queue with the specified maximum size and default ordering.BoundedPriorityQueue(int maxSize, java.util.Comparator<? super E> comparator)
Creates a bounded priority queue with the specified maximum size.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
java.util.Iterator<E>
iterator()
boolean
offer(E e)
E
peek()
E
poll()
private static <E> java.util.Comparator<? super E>
reverse(java.util.Comparator<? super E> comparator)
Internal queue should be in fact in reverse order.int
size()
-
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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
maxSize
private final int maxSize
-
comparator
private final java.util.Comparator<? super E> comparator
-
queue
private final java.util.Queue<E> queue
-
-
Constructor Detail
-
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
public BoundedPriorityQueue(int maxSize, java.util.Comparator<? super E> comparator)
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 Detail
-
reverse
private static <E> java.util.Comparator<? super E> reverse(java.util.Comparator<? super E> comparator)
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
public boolean add(E e)
-
iterator
public java.util.Iterator<E> iterator()
-
-