/** Creates a new remapping document iterator wrapping a given document iterator and remapping interval-iterator requests * through a given mapping from external to internal indices. * * @param documentIterator the underlying document iterator. * @param indexInverseRemapping the mapping from external to internal indices. */ public RemappingDocumentIterator( final DocumentIterator documentIterator, final Reference2ReferenceMap<? extends Index, ? extends Index> indexInverseRemapping ) { this.documentIterator = documentIterator; this.indexInverseRemapping = indexInverseRemapping; final int n = documentIterator.indices().size(); this.currentIterators = new Index2IntervalIteratorMap( n ); this.unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); indices = new ReferenceArraySet<Index>( documentIterator.indices().size() ); final ReferenceArraySet<Index> nonIndices = new ReferenceArraySet<Index>(); for( Map.Entry<? extends Index, ? extends Index> e : indexInverseRemapping.entrySet() ) { if ( documentIterator.indices().contains( e.getKey() ) ) throw new IllegalArgumentException( "You cannot remap index " + e.getValue() + " to index " + e.getKey() + " as the latter already belongs to the document iterator" ); if ( ! documentIterator.indices().contains( e.getValue() ) ) throw new IllegalArgumentException( "You cannot remap index " + e.getValue() + " to index " + e.getKey() + " as the former does not belong to the document iterator" ); nonIndices.add( e.getValue() ); indices.add( e.getKey() ); } for( Index index: documentIterator.indices() ) if ( ! nonIndices.contains( index ) ) indices.add( index ); soleIndex = n == 1 ? indices.iterator().next() : null; }
/** Creates a new remapping document iterator wrapping a given document iterator and remapping interval-iterator requests * through a given mapping from external to internal indices. * * @param documentIterator the underlying document iterator. * @param indexInverseRemapping the mapping from external to internal indices. */ public RemappingDocumentIterator( final DocumentIterator documentIterator, final Reference2ReferenceMap<? extends Index, ? extends Index> indexInverseRemapping ) { this.documentIterator = documentIterator; this.indexInverseRemapping = indexInverseRemapping; final int n = documentIterator.indices().size(); this.currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( new Index[ n ], new IntervalIterator[ n ] ); this.unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); indices = new ReferenceArraySet<Index>( documentIterator.indices().size() ); final ReferenceArraySet<Index> nonIndices = new ReferenceArraySet<Index>(); for( Map.Entry<? extends Index, ? extends Index> e : indexInverseRemapping.entrySet() ) { if ( documentIterator.indices().contains( e.getKey() ) ) throw new IllegalArgumentException( "You cannot remap index " + e.getValue() + " to index " + e.getKey() + " as the latter already belongs to the document iterator" ); if ( ! documentIterator.indices().contains( e.getValue() ) ) throw new IllegalArgumentException( "You cannot remap index " + e.getValue() + " to index " + e.getKey() + " as the former does not belong to the document iterator" ); nonIndices.add( e.getValue() ); indices.add( e.getKey() ); } for( Index index: documentIterator.indices() ) if ( ! nonIndices.contains( index ) ) indices.add( index ); soleIndex = n == 1 ? indices.iterator().next() : null; }
protected AlignDocumentIterator( final DocumentIterator firstIterator, final DocumentIterator secondIterator ) { this.firstIterator = firstIterator; this.secondIterator = secondIterator; if ( firstIterator instanceof IndexIterator && secondIterator instanceof IndexIterator ) { firstIndexIterator = (IndexIterator)firstIterator; secondIndexIterator = (IndexIterator)secondIterator; } else firstIndexIterator = secondIndexIterator = null; if ( firstIterator.indices().size() != 1 || secondIterator.indices().size() != 1 ) throw new IllegalArgumentException( "You can align single-index iterators only" ); index = firstIterator.indices().iterator().next(); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( 1 ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
protected AlignDocumentIterator( final DocumentIterator firstIterator, final DocumentIterator secondIterator ) { this.firstIterator = firstIterator; this.secondIterator = secondIterator; if ( firstIterator instanceof IndexIterator && secondIterator instanceof IndexIterator ) { firstIndexIterator = (IndexIterator)firstIterator; secondIndexIterator = (IndexIterator)secondIterator; } else firstIndexIterator = secondIndexIterator = null; if ( firstIterator.indices().size() != 1 || secondIterator.indices().size() != 1 ) throw new IllegalArgumentException( "You can align single-index iterators only" ); index = firstIterator.indices().iterator().next(); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( 1 ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
/** Creates a new difference document iterator given a minuend and a subtrahend iterator. * @param minuendIterator the minuend. * @param subtrahendIterator the subtrahend. */ protected DifferenceDocumentIterator( final DocumentIterator minuendIterator, final DocumentIterator subtrahendIterator, final int leftMargin, final int rightMargin ) { if ( leftMargin < 0 || rightMargin < 0 ) throw new IllegalArgumentException( "Illegal margins: " + leftMargin + ", " + rightMargin ); this.minuendIterator = minuendIterator; this.subtrahendIterator = subtrahendIterator; this.leftMargin = leftMargin; this.rightMargin = rightMargin; final int n = minuendIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; // If the subtrahend is empty, the result is equal to the minuend. nonEmptySubtrahend = subtrahendIterator.hasNext(); intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
public CachingDocumentIterator( final DocumentIterator documentIterator ) { this.documentIterator = documentIterator; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; this.currentIterators = new Index2IntervalIteratorMap( n ); this.cachingIterators = new Index2IntervalIteratorMap( n ); this.unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
public CachingDocumentIterator( final DocumentIterator documentIterator ) { this.documentIterator = documentIterator; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; this.currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( new Index[ n ], new IntervalIterator[ n ] ); this.cachingIterators = new Reference2ReferenceArrayMap<Index,CachingIntervalIterator>( new Index[ n ], new CachingIntervalIterator[ n ] ); this.unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
public CachingDocumentIterator( final DocumentIterator documentIterator ) { this.documentIterator = documentIterator; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; this.currentIterators = new Index2IntervalIteratorMap( n ); this.cachingIterators = new Index2IntervalIteratorMap( n ); this.unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
public CachingDocumentIterator( final DocumentIterator documentIterator ) { this.documentIterator = documentIterator; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; this.currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( new Index[ n ], new IntervalIterator[ n ] ); this.cachingIterators = new Reference2ReferenceArrayMap<Index,CachingIntervalIterator>( new Index[ n ], new CachingIntervalIterator[ n ] ); this.unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
/** Creates a new difference document iterator given a minuend and a subtrahend iterator. * @param minuendIterator the minuend. * @param subtrahendIterator the subtrahend. */ protected DifferenceDocumentIterator( final DocumentIterator minuendIterator, final DocumentIterator subtrahendIterator, final int leftMargin, final int rightMargin ) { if ( leftMargin < 0 || rightMargin < 0 ) throw new IllegalArgumentException( "Illegal margins: " + leftMargin + ", " + rightMargin ); this.minuendIterator = minuendIterator; this.subtrahendIterator = subtrahendIterator; this.leftMargin = leftMargin; this.rightMargin = rightMargin; final int n = minuendIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; // If the subtrahend is empty, the result is equal to the minuend. maybeNonEmptySubtrahend = subtrahendIterator.mayHaveNext(); intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
/** Creates a new low-pass document iterator over a given iterator. * @param documentIterator the iterator to be filtered. * @param threshold the filter threshold. */ protected LowPassDocumentIterator( final DocumentIterator documentIterator, final int threshold ) { this.documentIterator = documentIterator; this.threshold = threshold; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
/** Creates a new low-pass document iterator over a given iterator. * @param documentIterator the iterator to be filtered. * @param threshold the filter threshold. */ protected LowPassDocumentIterator( final DocumentIterator documentIterator, final int threshold ) { this.documentIterator = documentIterator; this.threshold = threshold; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); currentIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); }
/** Creates a new NOT document iterator over a given iterator. * @param documentIterator an iterator. * @param numberOfDocuments the number of documents. */ protected NotDocumentIterator( final DocumentIterator documentIterator, final long numberOfDocuments ) throws IOException { this.documentIterator = documentIterator; this.numberOfDocuments = numberOfDocuments; if ( ( nextToSkip = documentIterator.nextDocument() ) == END_OF_LIST ) nextToSkip = numberOfDocuments; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; intervalIterators = new Index2IntervalIteratorMap( n ); for( Index i: indices() ) intervalIterators.put( i, IntervalIterators.TRUE ); unmodifiableIntervalIterators = Reference2ReferenceMaps.unmodifiable( intervalIterators ); }
/** Creates a new NOT document iterator over a given iterator. * @param documentIterator an iterator. * @param numberOfDocuments the number of documents. */ protected NotDocumentIterator( final DocumentIterator documentIterator, final int numberOfDocuments ) throws IOException { this.documentIterator = documentIterator; this.numberOfDocuments = numberOfDocuments; if ( ( nextToSkip = documentIterator.nextDocument() ) == END_OF_LIST ) nextToSkip = numberOfDocuments; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; intervalIterators = new Index2IntervalIteratorMap( n ); for( Index i: indices() ) intervalIterators.put( i, IntervalIterators.TRUE ); unmodifiableIntervalIterators = Reference2ReferenceMaps.unmodifiable( intervalIterators ); }
/** 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 long[ n ]; queue = new LongHeapSemiIndirectPriorityQueue( 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; front = new int[ queue.size() ]; }
/** Creates a new NOT document iterator over a given iterator. * @param documentIterator an iterator. * @param numberOfDocuments the number of documents. */ protected NotDocumentIterator( final DocumentIterator documentIterator, final int numberOfDocuments ) throws IOException { this.documentIterator = documentIterator; this.numberOfDocuments = numberOfDocuments; if ( ( nextToSkip = documentIterator.nextDocument() ) == -1 ) nextToSkip = numberOfDocuments; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); for( Index i: indices() ) intervalIterators.put( i, IntervalIterators.TRUE ); intervalIterators.defaultReturnValue( IntervalIterators.FALSE ); unmodifiableIntervalIterators = Reference2ReferenceMaps.unmodifiable( intervalIterators ); }
/** Creates a new NOT document iterator over a given iterator. * @param documentIterator an iterator. * @param numberOfDocuments the number of documents. */ protected NotDocumentIterator( final DocumentIterator documentIterator, final long numberOfDocuments ) throws IOException { this.documentIterator = documentIterator; this.numberOfDocuments = numberOfDocuments; if ( ( nextToSkip = documentIterator.nextDocument() ) == -1 ) nextToSkip = numberOfDocuments; final int n = documentIterator.indices().size(); soleIndex = n == 1 ? indices().iterator().next() : null; intervalIterators = new Reference2ReferenceArrayMap<Index,IntervalIterator>( n ); for( Index i: indices() ) intervalIterators.put( i, IntervalIterators.TRUE ); intervalIterators.defaultReturnValue( IntervalIterators.FALSE ); unmodifiableIntervalIterators = Reference2ReferenceMaps.unmodifiable( intervalIterators ); }
/** 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() ]; }
/** Creates a new instance. * @param n the number of underlying iterators. * @param indices the set of indices appearing in the underlying iterators. * @param allIndexIterators whether all underlying iterators are {@linkplain IndexIterator index iterators}. * @param arg an argument that will be passed to {@link #getIntervalIterator(Index, int, boolean, Object)}. */ protected AbstractIntervalDocumentIterator( final int n, final ReferenceSet<Index> indices, final boolean allIndexIterators, final Object arg ) { this.indices = indices; intervalIterators = new Index2IntervalIteratorMap( indices.size() ); currentIterators = new Index2IntervalIteratorMap( indices.size() ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); if ( indices.size() == 1 ) { soleIndex = indices.iterator().next(); soleIntervalIterator = getIntervalIterator( soleIndex, n, allIndexIterators, arg ); intervalIterators.add( soleIndex, soleIntervalIterator ); } else { soleIndex = null; soleIntervalIterator = null; for( Index in: indices ) if ( in.hasPositions ) intervalIterators.add( in, getIntervalIterator( in, n, allIndexIterators, arg ) ); } }
/** Creates a new instance. * @param n the number of underlying iterators. * @param indices the set of indices appearing in the underlying iterators. * @param allIndexIterators whether all underlying iterators are {@linkplain IndexIterator index iterators}. * @param arg an argument that will be passed to {@link #getIntervalIterator(Index, int, boolean, Object)}. */ protected AbstractIntervalDocumentIterator( final int n, final ReferenceSet<Index> indices, final boolean allIndexIterators, final Object arg ) { this.indices = indices; intervalIterators = new Index2IntervalIteratorMap( indices.size() ); currentIterators = new Index2IntervalIteratorMap( indices.size() ); unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators ); if ( indices.size() == 1 ) { soleIndex = indices.iterator().next(); soleIntervalIterator = getIntervalIterator( soleIndex, n, allIndexIterators, arg ); intervalIterators.add( soleIndex, soleIntervalIterator ); } else { soleIndex = null; soleIntervalIterator = null; for( Index in: indices ) if ( in.hasPositions ) intervalIterators.add( in, getIntervalIterator( in, n, allIndexIterators, arg ) ); } }