Class AbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
java.lang.Object
org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue<T>
- Type Parameters:
T- type of the elements contained in the priority queue.
- All Implemented Interfaces:
InternalPriorityQueue<T>
- Direct Known Subclasses:
HeapPriorityQueue
public abstract class AbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
extends Object
implements InternalPriorityQueue<T>
Abstract base class for heap (object array) based implementations of priority queues, with
support for fast deletes via
HeapPriorityQueueElement.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the given element to the set, if it is not already contained.voidaddAll(Collection<? extends T> toAdd) Adds all the given elements to the set.protected abstract voidaddInternal(T toAdd) Implements how to add an element to the queue.voidclear()Clears the queue.protected abstract intReturns the start index of the queue elements in the array.booleanisEmpty()Check if the set contains any elements.org.apache.flink.util.CloseableIterator<T>iterator()Returns an iterator over the elements in this queue.protected voidmoveElementToIdx(T element, int idx) peek()Retrieves, but does not remove, the element (w.r.t. order) of this set, or returnsnullif this set is empty.poll()Retrieves and removes the first element (w.r.t. the order) of this set, or returnsnullif this set is empty.booleanRemoves the given element from the set, if is contained in the set.protected abstract TremoveInternal(int elementIndex) Implements how to remove the element at the given index from the queue.protected voidresizeForBulkLoad(int totalSize) protected voidresizeQueueArray(int desiredSize, int minRequiredSize) intsize()Returns the number of elements in this set.<O> O[]toArray(O[] out)
-
Field Details
-
queue
The array that represents the heap-organized priority queue. -
size
@Nonnegative protected int sizeThe current size of the priority queue.
-
-
Constructor Details
-
AbstractHeapPriorityQueue
public AbstractHeapPriorityQueue(@Nonnegative int minimumCapacity)
-
-
Method Details
-
poll
Description copied from interface:InternalPriorityQueueRetrieves and removes the first element (w.r.t. the order) of this set, or returnsnullif this set is empty.NOTE: Correct key (i.e. the key of the polled element) must be set on KeyContext before calling this method.
- Specified by:
pollin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Returns:
- the first element of this ordered set, or
nullif this set is empty.
-
peek
Description copied from interface:InternalPriorityQueueRetrieves, but does not remove, the element (w.r.t. order) of this set, or returnsnullif this set is empty.- Specified by:
peekin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Returns:
- the first element (w.r.t. order) of this ordered set, or
nullif this set is empty.
-
add
Description copied from interface:InternalPriorityQueueAdds the given element to the set, if it is not already contained.- Specified by:
addin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Parameters:
toAdd- the element to add to the set.- Returns:
trueif the operation changed the head element or if it is unclear if the head element changed. Only returnsfalseif the head element was not changed by this operation.
-
remove
Description copied from interface:InternalPriorityQueueRemoves the given element from the set, if is contained in the set.NOTE: Correct key (i.e. the key of the polled element) must be set on KeyContext before calling this method.
- Specified by:
removein interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Parameters:
toRemove- the element to remove.- Returns:
trueif the operation changed the head element or if it is unclear if the head element changed. Only returnsfalseif the head element was not changed by this operation.
-
isEmpty
public boolean isEmpty()Description copied from interface:InternalPriorityQueueCheck if the set contains any elements.- Specified by:
isEmptyin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Returns:
- true if the set is empty, i.e. no element is contained.
-
size
public int size()Description copied from interface:InternalPriorityQueueReturns the number of elements in this set.- Specified by:
sizein interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Returns:
- the number of elements in this set.
-
addAll
Description copied from interface:InternalPriorityQueueAdds all the given elements to the set.- Specified by:
addAllin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>
-
toArray
@Nonnull public <O> O[] toArray(O[] out) -
iterator
Returns an iterator over the elements in this queue. The iterator does not return the elements in any particular order.- Specified by:
iteratorin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Returns:
- an iterator over the elements in this queue.
-
clear
public void clear()Clears the queue. -
resizeForBulkLoad
protected void resizeForBulkLoad(int totalSize) -
resizeQueueArray
protected void resizeQueueArray(int desiredSize, int minRequiredSize) -
moveElementToIdx
-
removeInternal
Implements how to remove the element at the given index from the queue.- Parameters:
elementIndex- the index to remove.- Returns:
- the removed element.
-
addInternal
Implements how to add an element to the queue.- Parameters:
toAdd- the element to add.
-
getHeadElementIndex
protected abstract int getHeadElementIndex()Returns the start index of the queue elements in the array.
-