Class Iterators.MergingIterator<T>

  • All Implemented Interfaces:
    java.util.Iterator<T>
    Enclosing class:
    Iterators

    private static class Iterators.MergingIterator<T>
    extends UnmodifiableIterator<T>
    An iterator that performs a lazy N-way merge, calculating the next value each time the iterator is polled. This amortizes the sorting cost over the iteration and requires less memory than sorting all elements at once.

    Retrieving a single element takes approximately O(log(M)) time, where M is the number of iterators. (Retrieving all elements takes approximately O(N*log(M)) time, where N is the total number of elements.)

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.Queue<PeekingIterator<T>> queue  
    • Constructor Summary

      Constructors 
      Constructor Description
      MergingIterator​(java.lang.Iterable<? extends java.util.Iterator<? extends T>> iterators, java.util.Comparator<? super T> itemComparator)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()  
      T next()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • MergingIterator

        public MergingIterator​(java.lang.Iterable<? extends java.util.Iterator<? extends T>> iterators,
                               java.util.Comparator<? super T> itemComparator)
    • Method Detail

      • hasNext

        public boolean hasNext()
      • next

        public T next()