Class AbstractHeapPriorityQueue<T extends HeapPriorityQueueElement>

    • Field Summary

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

      All Methods Instance Methods Abstract Methods Concrete Methods 
      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 clear()
      Clears the queue.
      protected abstract int getHeadElementIndex()
      Returns the start index of the queue elements in the array.
      boolean isEmpty()
      Check if the set contains any elements.
      org.apache.flink.util.CloseableIterator<T> iterator()
      Returns an iterator over the elements in this queue.
      protected void moveElementToIdx​(T element, int idx)  
      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.
      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 size()
      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.
    • Constructor Detail

      • AbstractHeapPriorityQueue

        public AbstractHeapPriorityQueue​(@Nonnegative
                                         int minimumCapacity)
    • Method Detail

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