T
- the type of elements in the queue.PQ
- the type of sub-queue used for each key-group partition.public class KeyGroupPartitionedPriorityQueue<T,PQ extends InternalPriorityQueue<T> & HeapPriorityQueueElement> extends Object implements InternalPriorityQueue<T>, KeyGroupedInternalPriorityQueue<T>
InternalPriorityQueue
is internally partitioned into sub-queues
per key-group and essentially works as a heap-of-heaps. Instances will have set semantics for
elements if the sub-queues have set semantics.Modifier and Type | Class and Description |
---|---|
static interface |
KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<T,PQS extends InternalPriorityQueue<T> & HeapPriorityQueueElement>
Factory that produces the sub-queues that represent the partitions of a
KeyGroupPartitionedPriorityQueue . |
Constructor and Description |
---|
KeyGroupPartitionedPriorityQueue(KeyExtractorFunction<T> keyExtractor,
PriorityComparator<T> elementPriorityComparator,
KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<T,PQ> orderedCacheFactory,
KeyGroupRange keyGroupRange,
int totalKeyGroups) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T toAdd)
Adds the given element to the set, if it is not already contained.
|
void |
addAll(Collection<? extends T> toAdd)
Adds all the given elements to the set.
|
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.
|
boolean |
isEmpty()
Check if the set contains any elements.
|
CloseableIterator<T> |
iterator()
Iterator over all elements, no order guaranteed.
|
T |
peek()
Retrieves, but does not remove, the element (w.r.t. order) of this set, or returns
null if this set is empty. |
T |
poll()
Retrieves and removes the first element (w.r.t. the order) of this set, or returns
null if this set is empty. |
boolean |
remove(T toRemove)
Removes the given element from the set, if is contained in the set.
|
int |
size()
Returns the number of elements in this set.
|
public KeyGroupPartitionedPriorityQueue(@Nonnull KeyExtractorFunction<T> keyExtractor, @Nonnull PriorityComparator<T> elementPriorityComparator, @Nonnull KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<T,PQ> orderedCacheFactory, @Nonnull KeyGroupRange keyGroupRange, @Nonnegative int totalKeyGroups)
@Nullable public T poll()
InternalPriorityQueue
null
if this set is empty.
NOTE: Correct key (i.e. the key of the polled element) must be set on KeyContext before calling this method.
poll
in interface InternalPriorityQueue<T>
null
if this set is empty.@Nullable public T peek()
InternalPriorityQueue
null
if this set is empty.peek
in interface InternalPriorityQueue<T>
null
if this set is
empty.public boolean add(@Nonnull T toAdd)
InternalPriorityQueue
add
in interface InternalPriorityQueue<T>
toAdd
- the element to add to the set.true
if the operation changed the head element or if it is unclear if
the head element changed. Only returns false
if the head element was not
changed by this operation.public boolean remove(@Nonnull T toRemove)
InternalPriorityQueue
NOTE: Correct key (i.e. the key of the polled element) must be set on KeyContext before calling this method.
remove
in interface InternalPriorityQueue<T>
toRemove
- the element to remove.true
if the operation changed the head element or if it is unclear if
the head element changed. Only returns false
if the head element was not
changed by this operation.public boolean isEmpty()
InternalPriorityQueue
isEmpty
in interface InternalPriorityQueue<T>
public int size()
InternalPriorityQueue
size
in interface InternalPriorityQueue<T>
public void addAll(@Nullable Collection<? extends T> toAdd)
InternalPriorityQueue
addAll
in interface InternalPriorityQueue<T>
@Nonnull public CloseableIterator<T> iterator()
InternalPriorityQueue
iterator
in interface InternalPriorityQueue<T>
@Nonnull public Set<T> getSubsetForKeyGroup(int keyGroupId)
KeyGroupedInternalPriorityQueue
getSubsetForKeyGroup
in interface KeyGroupedInternalPriorityQueue<T>
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.