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 forHeapPriorityQueueElement
objects. This heap supports fast deletes because it manages position indexes of the containedHeapPriorityQueueElement
s. 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 fromHeapPriorityQueueElement
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
Fields Modifier and Type Field Description protected PriorityComparator<T>
elementPriorityComparator
Comparator for the priority of contained elements.-
Fields inherited from class org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue
queue, size
-
-
Constructor Summary
Constructors Constructor Description HeapPriorityQueue(PriorityComparator<T> elementPriorityComparator, int minimumCapacity)
Creates an emptyHeapPriorityQueue
with the requested initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addInternal(T element)
Implements how to add an element to the queue.void
adjustModifiedElement(T element)
protected int
getHeadElementIndex()
Returns the start index of the queue elements in the array.protected T
removeInternal(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 Detail
-
elementPriorityComparator
@Nonnull protected final PriorityComparator<T extends HeapPriorityQueueElement> elementPriorityComparator
Comparator for the priority of contained elements.
-
-
Constructor Detail
-
HeapPriorityQueue
public HeapPriorityQueue(@Nonnull PriorityComparator<T> elementPriorityComparator, @Nonnegative int minimumCapacity)
Creates an emptyHeapPriorityQueue
with the requested initial capacity.- Parameters:
elementPriorityComparator
- comparator for the priority of contained elements.minimumCapacity
- the minimum and initial capacity of this priority queue.
-
-
Method Detail
-
adjustModifiedElement
public void adjustModifiedElement(@Nonnull T element)
-
getHeadElementIndex
protected int getHeadElementIndex()
Description copied from class:AbstractHeapPriorityQueue
Returns the start index of the queue elements in the array.- Specified by:
getHeadElementIndex
in classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
-
addInternal
protected void addInternal(@Nonnull T element)
Description copied from class:AbstractHeapPriorityQueue
Implements how to add an element to the queue.- Specified by:
addInternal
in classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
- Parameters:
element
- the element to add.
-
removeInternal
protected T removeInternal(int removeIdx)
Description copied from class:AbstractHeapPriorityQueue
Implements how to remove the element at the given index from the queue.- Specified by:
removeInternal
in classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
- Parameters:
removeIdx
- the index to remove.- Returns:
- the removed element.
-
-