/** Creates a new AND interval iterator. * * @param index the index of the iterator. * @param n the number of component iterators. */ protected AndIndexIntervalIterator( final Index index, final int n ) { super( n ); // We just set up some internal data, but we perform no initialisation. this.index = index; queue = new IntHeapSemiIndirectPriorityQueue( curr ); }
private int hasNextInternal() { if ( positionQueue.isEmpty() ) return -1; int first; while ( curr[ first = positionQueue.first() ] == last ) { if ( ++currPos[ first ] == count[ first ] ) { positionQueue.dequeue(); if ( positionQueue.isEmpty() ) return -1; } else { curr[ first ] = position[ first ][ currPos[ first ] ]; positionQueue.changed(); } } return first; }
/** Forces computation of the current front, returning the number of indices it contains. * * <p>After a call to this method, * the first elements of {@link #front} contain * the indices of the {@linkplain AbstractCompositeDocumentIterator#documentIterator component document iterators} * that are positioned on the current document. If the front has already been * computed for the current document, this method has no side effects. * * @return the size of the current front (the number of valid entries in {@link #front}). */ protected int computeFront() { if ( frontSize == -1 ) frontSize = queue.front( front ); return frontSize; }
public boolean hasNext() { if ( endOfProcess ) return false; int first; while ( curr[ first = queue.first() ] == lastLeft ) { if ( ++currPos[ first ] == count[ first ] ) { endOfProcess = true; return false; } curr[ first ] = position[ first ][ currPos[ first ] ]; maxRight = Math.max( maxRight, curr[ first ] ); queue.changed(); } return true; }
/** Creates a new document iterator that computes the OR of the given array of iterators. * @param documentIterator the iterators to be joined. * @throws IOException */ protected AbstractUnionDocumentIterator( final DocumentIterator... documentIterator ) throws IOException { super( documentIterator ); this.refArray = new int[ n ]; queue = new IntHeapSemiIndirectPriorityQueue( refArray ); intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( indices.size() ); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( indices.size() ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); // Only add to the queue nonempty iterators... for ( int i = 0; i < n; i++ ) if ( ( refArray[ i ] = documentIterator[ i ].nextDocument() ) != -1 ) queue.enqueue( i ); // If queue is empty, the process is over if ( queue.isEmpty() ) curr = END_OF_LIST; else { curr = refArray[ queue.first() ]; ahead = true; } front = new int[ queue.size() ]; }
public void reset() throws IOException { last = Integer.MIN_VALUE; positionQueue.clear(); for ( int i = computeFront(), k; i-- != 0; ) { k = front[ i ]; if ( indexIterator[ k ].index() == index && indexIterator[ k ].index().hasPositions ) { position[ k ] = indexIterator[ k ].positionArray(); count[ k ] = indexIterator[ k ].count(); curr[ k ] = position[ k ][ currPos[ k ] = 0 ]; positionQueue.enqueue( k ); } } if ( ASSERTS ) assert ! positionQueue.isEmpty(); next = Interval.valueOf( curr[ positionQueue.first() ] ); }
queue = new IntHeapSemiIndirectPriorityQueue( globalDocumentPointer, n ); indices.addAll( documentIterator[ i ].indices() ); globalDocumentPointer[ i ] = strategy.globalPointer( usedIndex[ i ], result ); queue.enqueue( i ); if ( queue.isEmpty() ) curr = END_OF_LIST;
public void reset() throws IOException { emitted = extracted = 0; next = null; positionQueue.clear(); for ( int i = computeFront(), k; i-- != 0; ) { k = front[ i ]; position[ k ] = indexIterator[ k ].positionArray(); count[ k ] = indexIterator[ k ].count(); curr[ k ] = position[ k ][ 0 ]; currPos[ k ] = 0; positionQueue.enqueue( k ); } if ( ASSERTS ) assert ! positionQueue.isEmpty(); }
@Override public IntervalIterator reset() throws IOException { queue.clear(); maxRight = Integer.MIN_VALUE; lastLeft = Integer.MIN_VALUE; endOfProcess = false; for ( int i = 0; i < n; i++ ) { // The case != index is identical to the TRUE/FALSE case in AndIntervalIterator. final Index indexIteratorIndex = indexIterator[ i ].index(); if ( indexIteratorIndex == index && indexIteratorIndex.hasPositions ) { curr[ i ] = indexIterator[ i ].nextPosition(); queue.enqueue( i ); maxRight = Math.max( maxRight, curr[ i ] ); } } if ( ASSERTS ) assert ! queue.isEmpty(); return this; }
this.inputStreamLength = new int[batches.size()]; Arrays.fill(this.prevTarget, -1); queue = new IntHeapSemiIndirectPriorityQueue(this.refArray); this.inputStreamLength[i] = batchIbs[i].readDelta(); this.refArray[i] = batchIbs[i].readDelta(); queue.enqueue(i); this.prevTarget = prevTarget; this.inputStreamLength = inputStreamLength; queue = new IntHeapSemiIndirectPriorityQueue(refArray); batchIbs[i] = new InputBitStream(batches.get(i), STD_BUFFER_SIZE); batchIbs[i].position(baseIbs[i].position()); queue.enqueue(i);
queue = new IntHeapSemiIndirectPriorityQueue( globalDocumentPointer, n ); indices.addAll( documentIterator[ i ].indices() ); globalDocumentPointer[ i ] = strategy.globalPointer( usedIndex[ i ], result ); queue.enqueue( i ); if ( queue.isEmpty() ) curr = END_OF_LIST; else { currentIterator = queue.first(); curr = globalDocumentPointer[ currentIterator ];
while ( curr[ first = queue.first() ] == lastLeft ) { if ( ++currPos[ first ] == count[ first ] ) { endOfProcess = true; queue.changed(); nextLeft = curr[ first = queue.first() ]; nextRight = maxRight; if ( DEBUG ) System.err.println( this + " is saving interval " + Interval.valueOf( nextLeft, nextRight ) ); queue.changed(); } while ( maxRight == nextRight );
public void reset() throws IOException { positionQueue.clear(); for ( int i = computeFront(), k; i-- != 0; ) { k = front[ i ]; if ( indexIterator[ k ].index() == index && indexIterator[ k ].index().hasPositions ) { position[ k ] = indexIterator[ k ].positionArray(); count[ k ] = indexIterator[ k ].count(); curr[ k ] = position[ k ][ currPos[ k ] = 0 ]; positionQueue.enqueue( k ); } } if ( ASSERTS ) assert ! positionQueue.isEmpty(); next = Interval.valueOf( curr[ positionQueue.first() ] ); }
public void reset() throws IOException { emitted = extracted = 0; next = null; positionQueue.clear(); for ( int i = computeFront(), k; i-- != 0; ) { k = front[ i ]; position[ k ] = indexIterator[ k ].positionArray(); count[ k ] = indexIterator[ k ].count(); curr[ k ] = position[ k ][ 0 ]; currPos[ k ] = 0; positionQueue.enqueue( k ); } if ( ASSERTS ) assert ! positionQueue.isEmpty(); }
@Override public IntervalIterator reset() throws IOException { queue.clear(); maxRight = Integer.MIN_VALUE; lastLeft = Integer.MIN_VALUE; endOfProcess = false; for ( int i = 0; i < n; i++ ) { // The case != index is identical to the TRUE/FALSE case in AndIntervalIterator. final Index indexIteratorIndex = indexIterator[ i ].index(); if ( indexIteratorIndex == index && indexIteratorIndex.hasPositions ) { curr[ i ] = indexIterator[ i ].nextPosition(); queue.enqueue( i ); maxRight = Math.max( maxRight, curr[ i ] ); } } if ( ASSERTS ) assert ! queue.isEmpty(); return this; }
public int nextDocument() throws IOException { if ( curr == END_OF_LIST ) return END_OF_LIST; if ( curr != -1 ) { final int result; if ( ( result = documentIterator[ currentIterator ].nextDocument() ) != END_OF_LIST ) { globalDocumentPointer[ currentIterator ] = strategy.globalPointer( usedIndex[ currentIterator ], result ); queue.changed(); } else queue.dequeue(); } return curr = queue.isEmpty() ? END_OF_LIST : globalDocumentPointer[ currentIterator = queue.first() ]; }
@Override public Interval nextInterval() throws IOException { if ( endOfProcess ) return null; int first; while ( curr[ first = queue.first() ] == lastLeft ) { if ( ( curr[ first ] = indexIterator[ first ].nextPosition() ) == IndexIterator.END_OF_POSITIONS ) { endOfProcess = true; return null; } maxRight = Math.max( maxRight, curr[ first ] ); queue.changed(); } int nextLeft, nextRight; do { nextLeft = curr[ first = queue.first() ]; nextRight = maxRight; if ( DEBUG ) System.err.println( this + " is saving interval " + Interval.valueOf( nextLeft, nextRight ) ); /* We check whether all iterators are on the same position, and * whether the top interval iterator is exhausted. In both cases, the * current span is guaranteed to be a minimal interval. */ if ( curr[ first ] == maxRight || ( endOfProcess = ( curr[ first ] = indexIterator[ first ].nextPosition() ) == IndexIterator.END_OF_POSITIONS ) ) break; if ( maxRight < curr[ first ] ) maxRight = curr[ first ]; queue.changed(); } while ( maxRight == nextRight ); return Interval.valueOf( lastLeft = nextLeft, nextRight ); }
public void reset() throws IOException { queue.clear(); maxRight = Integer.MIN_VALUE; lastLeft = Integer.MIN_VALUE; next = null; endOfProcess = false; for ( int i = 0; i < n; i++ ) { // The case != index is identical to the TRUE/FALSE case in AndIntervalIterator. final Index indexIteratorIndex = indexIterator[ i ].index(); if ( indexIteratorIndex == index && indexIteratorIndex.hasPositions ) { position[ i ] = indexIterator[ i ].positionArray(); count[ i ] = indexIterator[ i ].count(); curr[ i ] = position[ i ][ currPos[ i ] = 0 ]; queue.enqueue( i ); maxRight = Math.max( maxRight, curr[ i ] ); } } if ( ASSERTS ) assert ! queue.isEmpty(); }
public MultiTermIntervalIterator() { super( n ); positionQueue = new IntHeapSemiIndirectPriorityQueue( curr ); cache = new int[ 4 ]; }
public void intervalTerms( final IntSet terms ) { final int frontSize = positionQueue.front( positionFront ); final int[] positionFront = this.positionFront; for( int i = frontSize; i-- != 0; ) terms.add( indexIterator[ positionFront[ i ] ].termNumber() ); }