public Reference2ReferenceMap<Index, IntervalIterator> intervalIterators() { return Reference2ReferenceMaps.singleton( soleIndex, IntervalIterators.TRUE ); }
/** * Returns a hash code for this map. * * The hash code of a map is computed by summing the hash codes of its entries. * * @return a hash code for this map. */ @Override public int hashCode() { int h = 0, n = size(); final ObjectIterator<Reference2ReferenceMap.Entry<K, V>> i = Reference2ReferenceMaps.fastIterator(this); while (n-- != 0) h += i.next().hashCode(); return h; } @Override
/** 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; }
/** 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; }
public Reference2ReferenceMap<Index, IntervalIterator> intervalIterators() { return Reference2ReferenceMaps.singleton( soleIndex, IntervalIterators.TRUE ); }
@Override public String toString() { final StringBuilder s = new StringBuilder(); final ObjectIterator<Reference2ReferenceMap.Entry<K, V>> i = Reference2ReferenceMaps.fastIterator(this); int n = size(); Reference2ReferenceMap.Entry<K, V> e; boolean first = true; s.append("{"); while (n-- != 0) { if (first) first = false; else s.append(", "); e = i.next(); if (this == e.getKey()) s.append("(this map)"); else s.append(String.valueOf(e.getKey())); s.append("=>"); if (this == e.getValue()) s.append("(this map)"); else s.append(String.valueOf(e.getValue())); } s.append("}"); return s.toString(); } }
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 TrueDocumentIterator( final Index index ) { indices = ReferenceSets.singleton( soleIndex = index ); intervalIterators = Reference2ReferenceMaps.singleton( soleIndex, IntervalIterators.TRUE ); }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked", "deprecation"}) @Override public void putAll(final Map<? extends K, ? extends V> m) { if (m instanceof Reference2ReferenceMap) { ObjectIterator<Reference2ReferenceMap.Entry<K, V>> i = Reference2ReferenceMaps .fastIterator((Reference2ReferenceMap<K, V>) m); while (i.hasNext()) { final Reference2ReferenceMap.Entry<? extends K, ? extends V> e = i.next(); put(e.getKey(), e.getValue()); } } else { int n = m.size(); final Iterator<? extends Map.Entry<? extends K, ? extends V>> i = m.entrySet().iterator(); Map.Entry<? extends K, ? extends V> e; while (n-- != 0) { e = i.next(); put(e.getKey(), e.getValue()); } } } /**
/** 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 AbstractQuasiSuccinctIndexIterator( final QuasiSuccinctIndexReader indexReader ) { this.indexReader = indexReader; index = indexReader.index; keyIndex = index.keyIndex; hasPositions = index.hasPositions; hasCounts = index.hasCounts; numberOfDocuments = index.numberOfDocuments; pointersList = indexReader.pointersList; countsList = indexReader.countsList; positionsList = indexReader.positionsList; intervalIterator = hasPositions ? new IndexIntervalIterator( this ) : IntervalIterators.FALSE; singletonIntervalIterator = Reference2ReferenceMaps.singleton( keyIndex, hasPositions ? intervalIterator : IntervalIterators.FALSE ); currentTerm = frequency = -1; }
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 TrueDocumentIterator( final Index index ) { indices = ReferenceSets.singleton( soleIndex = index ); intervalIterators = Reference2ReferenceMaps.singleton( soleIndex, IntervalIterators.TRUE ); }
unmodifiableCurrentIterators = Reference2ReferenceMaps.unmodifiable( currentIterators );
protected AbstractQuasiSuccinctIndexIterator( final QuasiSuccinctIndexReader indexReader ) { this.indexReader = indexReader; index = indexReader.index; keyIndex = index.keyIndex; hasPositions = index.hasPositions; hasCounts = index.hasCounts; numberOfDocuments = index.numberOfDocuments; pointersList = indexReader.pointersList; countsList = indexReader.countsList; positionsList = indexReader.positionsList; intervalIterator = hasPositions ? new IndexIntervalIterator( this ) : null; singletonIntervalIterator = hasPositions ? Reference2ReferenceMaps.singleton( keyIndex, (IntervalIterator)intervalIterator ) : null; currentTerm = frequency = -1; }
/** 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 BitStreamIndexReaderIndexIterator( final GammaDeltaGammaDeltaBitStreamIndexReader parent, final InputBitStream ibs ) { this.parent = parent; this.ibs = ibs; index = parent.index; keyIndex = index.keyIndex; pointerCoding = index.pointerCoding; if ( index.hasPayloads ) throw new IllegalStateException(); if ( ! index.hasCounts ) throw new IllegalStateException(); countCoding = index.countCoding; if ( ! index.hasPositions ) throw new IllegalStateException(); positionCoding = index.positionCoding; positionCache = new int[ POSITION_CACHE_INITIAL_SIZE ]; intervalIterator = index.hasPositions ? new it.unimi.di.big.mg4j.index.IndexIntervalIterator( this ) : null; singletonIntervalIterator = index.hasPositions ? Reference2ReferenceMaps.singleton( keyIndex, (IntervalIterator)intervalIterator ) : null; }
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 BitStreamIndexReaderIndexIterator( final GammaDeltaGammaDeltaBitStreamIndexReader parent, final InputBitStream ibs ) { this.parent = parent; this.ibs = ibs; index = parent.index; keyIndex = index.keyIndex; pointerCoding = index.pointerCoding; if ( index.hasPayloads ) throw new IllegalStateException(); if ( ! index.hasCounts ) throw new IllegalStateException(); countCoding = index.countCoding; if ( ! index.hasPositions ) throw new IllegalStateException(); positionCoding = index.positionCoding; positionCache = new int[ POSITION_CACHE_INITIAL_SIZE ]; intervalIterator = index.hasPositions ? new it.unimi.di.mg4j.index.IndexIntervalIterator( this ) : null; singletonIntervalIterator = index.hasPositions ? Reference2ReferenceMaps.singleton( keyIndex, (IntervalIterator)intervalIterator ) : null; } /** Positions the index on the inverted list of a given term.