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 viaHeapPriorityQueueElement.
-
-
Constructor Summary
Constructors Constructor Description AbstractHeapPriorityQueue(int minimumCapacity)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(T toAdd)Adds 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 intgetHeadElementIndex()Returns 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)Tpeek()Retrieves, but does not remove, the element (w.r.t. order) of this set, or returnsnullif this set is empty.Tpoll()Retrieves and removes the first element (w.r.t. the order) of this set, or returnsnullif this set is empty.booleanremove(T toRemove)Removes 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 Detail
-
queue
@Nonnull protected T extends HeapPriorityQueueElement[] queue
The array that represents the heap-organized priority queue.
-
size
@Nonnegative protected int size
The current size of the priority queue.
-
-
Method Detail
-
poll
@Nullable public T 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
@Nullable public T 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
public boolean add(@Nonnull T toAdd)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
public boolean remove(@Nonnull T toRemove)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
public void addAll(@Nullable Collection<? extends T> toAdd)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
@Nonnull public org.apache.flink.util.CloseableIterator<T> 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
protected void moveElementToIdx(T element, int idx)
-
removeInternal
protected abstract T removeInternal(@Nonnegative int elementIndex)
Implements how to remove the element at the given index from the queue.- Parameters:
elementIndex- the index to remove.- Returns:
- the removed element.
-
addInternal
protected abstract void addInternal(@Nonnull T toAdd)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.
-
-