Class HeapPriorityQueueSet<T extends HeapPriorityQueueElement>
- java.lang.Object
-
- org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue<T>
-
- org.apache.flink.runtime.state.heap.HeapPriorityQueue<T>
-
- org.apache.flink.runtime.state.heap.HeapPriorityQueueSet<T>
-
- Type Parameters:
T- type of the contained elements.
- All Implemented Interfaces:
InternalPriorityQueue<T>,KeyGroupedInternalPriorityQueue<T>
public class HeapPriorityQueueSet<T extends HeapPriorityQueueElement> extends HeapPriorityQueue<T> implements KeyGroupedInternalPriorityQueue<T>
A heap-based priority queue with set semantics, based onHeapPriorityQueue. The heap is supported by hash set for fast contains (de-duplication) and deletes. Object identification happens based onObject.equals(Object).Possible future improvements:
- We could also implement shrinking for the heap and the deduplication set.
- We could replace the deduplication maps with more efficient custom implementations. In particular, a hash set would be enough if it could return existing elements on unsuccessful adding, etc..
-
-
Field Summary
-
Fields inherited from class org.apache.flink.runtime.state.heap.HeapPriorityQueue
elementPriorityComparator
-
Fields inherited from class org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue
queue, size
-
-
Constructor Summary
Constructors Constructor Description HeapPriorityQueueSet(PriorityComparator<T> elementPriorityComparator, KeyExtractorFunction<T> keyExtractor, int minimumCapacity, KeyGroupRange keyGroupRange, int totalNumberOfKeyGroups)Creates an emptyHeapPriorityQueueSetwith the requested initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T element)Adds the element to the queue.voidclear()Clears the queue.Set<T>getSubsetForKeyGroup(int keyGroupId)Returns the subset of elements in the priority queue that belongs to the given key-group, within the operator's key-group range.Tpoll()Retrieves and removes the first element (w.r.t.booleanremove(T toRemove)In contrast to the superclass and to maintain set semantics, removal here is based on comparing the given element viaObject.equals(Object).-
Methods inherited from class org.apache.flink.runtime.state.heap.HeapPriorityQueue
addInternal, adjustModifiedElement, getHeadElementIndex, removeInternal
-
Methods inherited from class org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue
addAll, isEmpty, iterator, moveElementToIdx, peek, resizeForBulkLoad, resizeQueueArray, size, toArray
-
-
-
-
Constructor Detail
-
HeapPriorityQueueSet
public HeapPriorityQueueSet(@Nonnull PriorityComparator<T> elementPriorityComparator, @Nonnull KeyExtractorFunction<T> keyExtractor, @Nonnegative int minimumCapacity, @Nonnull KeyGroupRange keyGroupRange, @Nonnegative int totalNumberOfKeyGroups)
Creates an emptyHeapPriorityQueueSetwith the requested initial capacity.- Parameters:
elementPriorityComparator- comparator for the priority of contained elements.keyExtractor- function to extract a key from the contained elements.minimumCapacity- the minimum and initial capacity of this priority queue.keyGroupRange- the key-group range of the elements in this set.totalNumberOfKeyGroups- the total number of key-groups of the job.
-
-
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>- Overrides:
pollin classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>- Returns:
- the first element of this ordered set, or
nullif this set is empty.
-
add
public boolean add(@Nonnull T element)
Adds the element to the queue. In contrast to the superclass and to maintain set semantics, this happens only if no such element is already contained (determined byObject.equals(Object)).- Specified by:
addin interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Overrides:
addin classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>- Parameters:
element- the element to add to the set.- Returns:
trueif the operation changed the head element or if is it unclear if the head element changed. Only returnsfalseiff the head element was not changed by this operation.
-
remove
public boolean remove(@Nonnull T toRemove)
In contrast to the superclass and to maintain set semantics, removal here is based on comparing the given element viaObject.equals(Object).- Specified by:
removein interfaceInternalPriorityQueue<T extends HeapPriorityQueueElement>- Overrides:
removein classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>- Parameters:
toRemove- the element to remove.- Returns:
trueif the operation changed the head element or if is it unclear if the head element changed. Only returnsfalseiff the head element was not changed by this operation.
-
clear
public void clear()
Description copied from class:AbstractHeapPriorityQueueClears the queue.- Overrides:
clearin classAbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>
-
getSubsetForKeyGroup
@Nonnull public Set<T> getSubsetForKeyGroup(int keyGroupId)
Description copied from interface:KeyGroupedInternalPriorityQueueReturns the subset of elements in the priority queue that belongs to the given key-group, within the operator's key-group range.- Specified by:
getSubsetForKeyGroupin interfaceKeyGroupedInternalPriorityQueue<T extends HeapPriorityQueueElement>
-
-