private bool InsertToPriortyQueueIfNecessary(ComparableSortedSequenceEnumerator <T> enumerator)
        {
            Diagnostics.Assert(enumerator != null, ClassName, "Input enumerator must not be null.");

            while (true)
            {
                bool wasPushed = this.priorityQueue.TryPush(enumerator);
                if (wasPushed)
                {
                    return(true);
                }

                var isNotEmpty = enumerator.MoveNext();
                if (isNotEmpty == false)
                {
                    enumerator.Dispose();
                    return(false);
                }
            }
        }
        /// <summary>
        /// Prepares the enumerator to be added to the priority queue.
        /// Preparation includes moving the enumerator until the current key obides filters.
        /// </summary>
        /// <param name="enumerator">The enumerator.</param>
        /// <returns>Boolean that indicates that the enumerator is now empty.</returns>
        private bool PrepareEnumerator(ComparableSortedSequenceEnumerator <T> enumerator)
        {
            while (true)
            {
                bool itemExists = enumerator.MoveNext();
                if (itemExists == false)
                {
                    return(false);
                }

                if (this.useFirstKey)
                {
                    int firstKeyComparison = this.keyComparer.Compare(this.firstKey, enumerator.Current);

                    // If firstKey for the filter is greater than the current, continue moving the enumerator.
                    if (firstKeyComparison > 0)
                    {
                        continue;
                    }
                }

                if (this.useLastKey)
                {
                    int lastKeyComparison = this.keyComparer.Compare(this.lastKey, enumerator.Current);

                    // If lastKey for the filter is less than the current, indicate that the enumerator is practically empty
                    if (lastKeyComparison < 0)
                    {
                        return(false);
                    }
                }

                // If current item does not fit the filter, go to next.
                if (this.keyFilter != null && this.keyFilter.Invoke(enumerator.Current) == false)
                {
                    continue;
                }

                return(true);
            }
        }