protected HeapIterator(int maxSize) { createHeap(maxSize); }
protected final void addSource(SortedKeyValueIterator<Key,Value> source) { if (source.hasTop()) { heap.add(source); if (topIdx != null) { heap.add(topIdx); } pullReferencesFromHeap(); } } }
@Override public final void next() throws IOException { if (topIdx == null) { throw new IllegalStateException("Called next() when there is no top"); } topIdx.next(); if (!topIdx.hasTop()) { if (nextKey == null) { // No iterators left topIdx = null; return; } pullReferencesFromHeap(); } else { if (nextKey == null) { // topIdx is the only iterator return; } if (nextKey.compareTo(topIdx.getTopKey()) < 0) { // Grab the next top iterator and put the current top iterator back on the heap // This updating of references is special-cased to save on percolation on edge cases // since the current top is guaranteed to not be the minimum SortedKeyValueIterator<Key,Value> nextTopIdx = heap.remove(); heap.add(topIdx); topIdx = nextTopIdx; nextKey = heap.peek().getTopKey(); } } }
protected HeapIterator(int maxSize) { createHeap(maxSize); }
final protected void addSource(SortedKeyValueIterator<Key,Value> source) { if (source.hasTop()) { heap.add(source); if (topIdx != null) { heap.add(topIdx); } pullReferencesFromHeap(); } } }
@Override final public void next() throws IOException { if (topIdx == null) { throw new IllegalStateException("Called next() when there is no top"); } topIdx.next(); if (!topIdx.hasTop()) { if (nextKey == null) { // No iterators left topIdx = null; return; } pullReferencesFromHeap(); } else { if (nextKey == null) { // topIdx is the only iterator return; } if (nextKey.compareTo(topIdx.getTopKey()) < 0) { // Grab the next top iterator and put the current top iterator back on the heap // This updating of references is special-cased to save on percolation on edge cases // since the current top is guaranteed to not be the minimum SortedKeyValueIterator<Key,Value> nextTopIdx = heap.remove(); heap.add(topIdx); topIdx = nextTopIdx; nextKey = heap.peek().getTopKey(); } } }