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 via HeapPriorityQueueElement.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected T[]
    The array that represents the heap-organized priority queue.
    protected int
    The current size of the priority queue.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractHeapPriorityQueue(int minimumCapacity)
     
  • Method Summary

    Modifier and Type
    Method
    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.
    protected abstract void
    addInternal(T toAdd)
    Implements how to add an element to the queue.
    void
    Clears the queue.
    protected abstract int
    Returns the start index of the queue elements in the array.
    boolean
    Check if the set contains any elements.
    org.apache.flink.util.CloseableIterator<T>
    Returns an iterator over the elements in this queue.
    protected void
    moveElementToIdx(T element, int idx)
     
    Retrieves, but does not remove, the element (w.r.t. order) of this set, or returns null if this set is empty.
    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.
    protected abstract T
    removeInternal(int elementIndex)
    Implements how to remove the element at the given index from the queue.
    protected void
    resizeForBulkLoad(int totalSize)
     
    protected void
    resizeQueueArray(int desiredSize, int minRequiredSize)
     
    int
    Returns the number of elements in this set.
    <O> O[]
    toArray(O[] out)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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.
  • Constructor Details

    • AbstractHeapPriorityQueue

      public AbstractHeapPriorityQueue(@Nonnegative int minimumCapacity)
  • Method Details

    • poll

      @Nullable public T poll()
      Description copied from interface: InternalPriorityQueue
      Retrieves and removes the first element (w.r.t. the order) of this set, or returns 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.

      Specified by:
      poll in interface InternalPriorityQueue<T extends HeapPriorityQueueElement>
      Returns:
      the first element of this ordered set, or null if this set is empty.
    • peek

      @Nullable public T peek()
      Description copied from interface: InternalPriorityQueue
      Retrieves, but does not remove, the element (w.r.t. order) of this set, or returns null if this set is empty.
      Specified by:
      peek in interface InternalPriorityQueue<T extends HeapPriorityQueueElement>
      Returns:
      the first element (w.r.t. order) of this ordered set, or null if this set is empty.
    • add

      public boolean add(@Nonnull T toAdd)
      Description copied from interface: InternalPriorityQueue
      Adds the given element to the set, if it is not already contained.
      Specified by:
      add in interface InternalPriorityQueue<T extends HeapPriorityQueueElement>
      Parameters:
      toAdd - the element to add to the set.
      Returns:
      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.
    • remove

      public boolean remove(@Nonnull T toRemove)
      Description copied from interface: InternalPriorityQueue
      Removes 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:
      remove in interface InternalPriorityQueue<T extends HeapPriorityQueueElement>
      Parameters:
      toRemove - the element to remove.
      Returns:
      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.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: InternalPriorityQueue
      Check if the set contains any elements.
      Specified by:
      isEmpty in interface InternalPriorityQueue<T extends HeapPriorityQueueElement>
      Returns:
      true if the set is empty, i.e. no element is contained.
    • size

      public int size()
      Description copied from interface: InternalPriorityQueue
      Returns the number of elements in this set.
      Specified by:
      size in interface InternalPriorityQueue<T extends HeapPriorityQueueElement>
      Returns:
      the number of elements in this set.
    • addAll

      public void addAll(@Nullable Collection<? extends T> toAdd)
      Description copied from interface: InternalPriorityQueue
      Adds all the given elements to the set.
      Specified by:
      addAll in interface InternalPriorityQueue<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:
      iterator in interface InternalPriorityQueue<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.