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 forHeapPriorityQueueElementobjects. This heap supports fast deletes because it manages position indexes of the containedHeapPriorityQueueElements. 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 fromHeapPriorityQueueElementto 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>elementPriorityComparatorComparator 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 emptyHeapPriorityQueuewith the requested initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddInternal(T element)Implements how to add an element to the queue.voidadjustModifiedElement(T element)protected intgetHeadElementIndex()Returns 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 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 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 Detail
-
adjustModifiedElement
public void adjustModifiedElement(@Nonnull T element)
-
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
protected void addInternal(@Nonnull T element)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
protected T removeInternal(int removeIdx)
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.
-
-