Class HeapPriorityQueue<T extends HeapPriorityQueueElement>
java.lang.Object
org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue<T>
org.apache.flink.runtime.state.heap.HeapPriorityQueue<T>
- Type Parameters:
T- type of the contained elements.
- All Implemented Interfaces:
InternalPriorityQueue<T>
- Direct Known Subclasses:
HeapPriorityQueueSet
public class HeapPriorityQueue<T extends HeapPriorityQueueElement>
extends AbstractHeapPriorityQueue<T>
Basic heap-based priority queue for
HeapPriorityQueueElement objects. This heap supports
fast deletes because it manages position indexes of the contained HeapPriorityQueueElements. The heap implementation is a simple binary tree stored inside an
array. Element indexes in the heap array start at 1 instead of 0 to make array index computations
a bit simpler in the hot methods. Object identification of remove is based on object identity and
not on equals. We use the managed index from HeapPriorityQueueElement to find an element
in the queue array to support fast deletes.
Possible future improvements:
- We could also implement shrinking for the heap.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final PriorityComparator<T>Comparator for the priority of contained elements.Fields inherited from class org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue
queue, size -
Constructor Summary
ConstructorsConstructorDescriptionHeapPriorityQueue(PriorityComparator<T> elementPriorityComparator, int minimumCapacity) Creates an emptyHeapPriorityQueuewith the requested initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddInternal(T element) Implements how to add an element to the queue.voidadjustModifiedElement(T element) protected intReturns the start index of the queue elements in the array.protected TremoveInternal(int removeIdx) Implements how to remove the element at the given index from the queue.Methods inherited from class org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue
add, addAll, clear, isEmpty, iterator, moveElementToIdx, peek, poll, remove, resizeForBulkLoad, resizeQueueArray, size, toArray
-
Field Details
-
elementPriorityComparator
@Nonnull protected final PriorityComparator<T extends HeapPriorityQueueElement> elementPriorityComparatorComparator for the priority of contained elements.
-
-
Constructor Details
-
HeapPriorityQueue
public HeapPriorityQueue(@Nonnull PriorityComparator<T> elementPriorityComparator, @Nonnegative int minimumCapacity) Creates an emptyHeapPriorityQueuewith the requested initial capacity.- Parameters:
elementPriorityComparator- comparator for the priority of contained elements.minimumCapacity- the minimum and initial capacity of this priority queue.
-
-
Method Details
-
adjustModifiedElement
-
getHeadElementIndex
protected int getHeadElementIndex()Description copied from class:AbstractHeapPriorityQueueReturns the start index of the queue elements in the array.- Specified by:
getHeadElementIndexin classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
-
addInternal
Description copied from class:AbstractHeapPriorityQueueImplements how to add an element to the queue.- Specified by:
addInternalin classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>- Parameters:
element- the element to add.
-
removeInternal
Description copied from class:AbstractHeapPriorityQueueImplements how to remove the element at the given index from the queue.- Specified by:
removeInternalin classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>- Parameters:
removeIdx- the index to remove.- Returns:
- the removed element.
-