public MergedIterator(final Iterator<T>[] iterators, final Comparator<T> comparator) { this(iterators.length, comparator); for (Iterator<T> iterator : iterators) { IteratorNode ctx = new IteratorNode(iterator); if (ctx.fetch()) _queue.add(ctx); } }
public MergedIterator(final List<Iterator<T>> iterators, final Comparator<T> comparator) { this(iterators.size(), comparator); for (Iterator<T> iterator : iterators) { IteratorNode ctx = new IteratorNode(iterator); if (ctx.fetch()) _queue.add(ctx); } }
@SuppressWarnings("unchecked") public T next() { IteratorNode ctx = (IteratorNode) _queue.top(); T val = ctx._curVal; if (ctx.fetch()) { _queue.updateTop(); } else { _queue.pop(); } return val; }