@Override public FixedBitSet clone() { long[] bits = new long[this.bits.length]; System.arraycopy(this.bits, 0, bits, 0, numWords); return new FixedBitSet(bits, numBits); }
/** bit-sets - for each repeating pp, for each of its repeating terms, the term ordinal values is set */ private ArrayList<FixedBitSet> ppTermsBitSets(PhrasePositions[] rpp, HashMap<Term,Integer> tord) { ArrayList<FixedBitSet> bb = new ArrayList<>(rpp.length); for (PhrasePositions pp : rpp) { FixedBitSet b = new FixedBitSet(tord.size()); Integer ord; for (Term t: pp.terms) { if ((ord=tord.get(t))!=null) { b.set(ord); } } bb.add(b); } return bb; }
/** bit-sets - for each repeating pp, for each of its repeating terms, the term ordinal values is set */ private ArrayList<FixedBitSet> ppTermsBitSets(PhrasePositions[] rpp, HashMap<Term,Integer> tord) { ArrayList<FixedBitSet> bb = new ArrayList<>(rpp.length); for (PhrasePositions pp : rpp) { FixedBitSet b = new FixedBitSet(tord.size()); Integer ord; for (Term t: pp.terms) { if ((ord=tord.get(t))!=null) { b.set(ord); } } bb.add(b); } return bb; }
TermsWriter(FieldInfo fieldInfo) { this.fieldInfo = fieldInfo; assert fieldInfo.getIndexOptions() != IndexOptions.NONE; docsSeen = new FixedBitSet(maxDoc); this.longsSize = postingsWriter.setField(fieldInfo); this.longs = new long[longsSize]; }
private static DocIdSet cacheIntoBitSet(BulkScorer scorer, int maxDoc) throws IOException { final FixedBitSet bitSet = new FixedBitSet(maxDoc); long cost[] = new long[1]; scorer.score(new LeafCollector() { @Override public void setScorer(Scorer scorer) throws IOException {} @Override public void collect(int doc) throws IOException { cost[0]++; bitSet.set(doc); } }, null); return new BitDocIdSet(bitSet, cost[0]); }
private void upgradeToBitSet() { assert bitSet == null; FixedBitSet bitSet = new FixedBitSet(maxDoc); long counter = 0; for (Buffer buffer : buffers) { int[] array = buffer.array; int length = buffer.length; counter += length; for (int i = 0; i < length; ++i) { bitSet.set(array[i]); } } this.bitSet = bitSet; this.counter = counter; this.buffers = null; this.adder = new FixedBitSetAdder(bitSet); }
/** Build a {@link BitSet} from the content of the provided {@link DocIdSetIterator}. * NOTE: this will fully consume the {@link DocIdSetIterator}. */ public static BitSet of(DocIdSetIterator it, int maxDoc) throws IOException { final long cost = it.cost(); final int threshold = maxDoc >>> 7; BitSet set; if (cost < threshold) { set = new SparseFixedBitSet(maxDoc); } else { set = new FixedBitSet(maxDoc); } set.or(it); return set; }
void add(int docID) { if (docID <= lastDocId) { throw new IllegalArgumentException("Out of order doc ids: last=" + lastDocId + ", next=" + docID); } if (set != null) { set = FixedBitSet.ensureCapacity(set, docID); set.set(docID); } else if (docID != cost) { // migrate to a sparse encoding using a bit set set = new FixedBitSet(docID + 1); set.set(0, cost); set.set(docID); } lastDocId = docID; cost++; }
/** * Make a copy of the given bits. */ public static FixedBitSet copyOf(Bits bits) { if (bits instanceof FixedBits) { // restore the original FixedBitSet FixedBits fixedBits = (FixedBits) bits; bits = new FixedBitSet(fixedBits.bits, fixedBits.length); } if (bits instanceof FixedBitSet) { return ((FixedBitSet)bits).clone(); } else { int length = bits.length(); FixedBitSet bitSet = new FixedBitSet(length); bitSet.set(0, length); for (int i = 0; i < length; ++i) { if (bits.get(i) == false) { bitSet.clear(i); } } return bitSet; } }
/** * If the given {@link FixedBitSet} is large enough to hold {@code numBits+1}, * returns the given bits, otherwise returns a new {@link FixedBitSet} which * can hold the requested number of bits. * <p> * <b>NOTE:</b> the returned bitset reuses the underlying {@code long[]} of * the given {@code bits} if possible. Also, calling {@link #length()} on the * returned bits may return a value greater than {@code numBits}. */ public static FixedBitSet ensureCapacity(FixedBitSet bits, int numBits) { if (numBits < bits.numBits) { return bits; } else { // Depends on the ghost bits being clear! // (Otherwise, they may become visible in the new instance) int numWords = bits2words(numBits); long[] arr = bits.getBits(); if (numWords >= arr.length) { arr = ArrayUtil.grow(arr, numWords + 1); } return new FixedBitSet(arr, arr.length << 6); } }
static SortingLeafReader.CachedNumericDVs sortDocValues(int maxDoc, Sorter.DocMap sortMap, NumericDocValues oldDocValues) throws IOException { FixedBitSet docsWithField = new FixedBitSet(maxDoc); long[] values = new long[maxDoc]; while (true) { int docID = oldDocValues.nextDoc(); if (docID == NO_MORE_DOCS) { break; } int newDocID = sortMap.oldToNew(docID); docsWithField.set(newDocID); values[newDocID] = oldDocValues.longValue(); } return new SortingLeafReader.CachedNumericDVs(values, docsWithField); }
protected FixedBitSet getMutableBits() { // if we pull mutable bits but we haven't been initialized something is completely off. // this means we receive deletes without having the bitset that is on-disk ready to be cloned assert liveDocsInitialized : "can't delete if liveDocs are not initialized"; if (writeableLiveDocs == null) { // Copy on write: this means we've cloned a // SegmentReader sharing the current liveDocs // instance; must now make a private clone so we can // change it: if (liveDocs != null) { writeableLiveDocs = FixedBitSet.copyOf(liveDocs); } else { writeableLiveDocs = new FixedBitSet(info.info.maxDoc()); writeableLiveDocs.set(0, info.info.maxDoc()); } liveDocs = writeableLiveDocs.asReadOnlyBits(); } return writeableLiveDocs; }
private SortingLeafReader.CachedBinaryDVs sortDocValues(int maxDoc, Sorter.DocMap sortMap, BinaryDocValues oldValues) throws IOException { FixedBitSet docsWithField = new FixedBitSet(maxDoc); BytesRef[] values = new BytesRef[maxDoc]; while (true) { int docID = oldValues.nextDoc(); if (docID == NO_MORE_DOCS) { break; } int newDocID = sortMap.oldToNew(docID); docsWithField.set(newDocID); values[newDocID] = BytesRef.deepCopyOf(oldValues.binaryValue()); } return new SortingLeafReader.CachedBinaryDVs(values, docsWithField); }
private FixedBitSet sortLiveDocs(Bits liveDocs, Sorter.DocMap sortMap) throws IOException { assert liveDocs != null && sortMap != null; FixedBitSet sortedLiveDocs = new FixedBitSet(liveDocs.length()); sortedLiveDocs.set(0, liveDocs.length()); for (int i = 0; i < liveDocs.length(); i++) { if (liveDocs.get(i) == false) { sortedLiveDocs.clear(sortMap.oldToNew(i)); } } return sortedLiveDocs; }
@Override public NumericDocValues getNormValues(String field) throws IOException { final NumericDocValues oldNorms = in.getNormValues(field); if (oldNorms == null) return null; CachedNumericDVs norms; synchronized (cachedNorms) { norms = cachedNorms.get(field); if (norms == null) { FixedBitSet docsWithField = new FixedBitSet(maxDoc()); long[] values = new long[maxDoc()]; while (true) { int docID = oldNorms.nextDoc(); if (docID == NO_MORE_DOCS) { break; } int newDocID = docMap.oldToNew(docID); docsWithField.set(newDocID); values[newDocID] = oldNorms.longValue(); } norms = new CachedNumericDVs(values, docsWithField); cachedNorms.put(field, norms); } } return new SortingNumericDocValues(norms); }
@Override public NumericDocValues getNumericDocValues(String field) throws IOException { final NumericDocValues oldDocValues = in.getNumericDocValues(field); if (oldDocValues == null) return null; CachedNumericDVs dvs; synchronized (cachedNumericDVs) { dvs = cachedNumericDVs.get(field); if (dvs == null) { FixedBitSet docsWithField = new FixedBitSet(maxDoc()); long[] values = new long[maxDoc()]; while (true) { int docID = oldDocValues.nextDoc(); if (docID == NO_MORE_DOCS) { break; } int newDocID = docMap.oldToNew(docID); docsWithField.set(newDocID); values[newDocID] = oldDocValues.longValue(); } dvs = new CachedNumericDVs(values, docsWithField); cachedNumericDVs.put(field, dvs); } } return new SortingNumericDocValues(dvs); }
@Override public BinaryDocValues getBinaryDocValues(String field) throws IOException { final BinaryDocValues oldDocValues = in.getBinaryDocValues(field); if (oldDocValues == null) return null; CachedBinaryDVs dvs; synchronized (cachedBinaryDVs) { dvs = cachedBinaryDVs.get(field); if (dvs == null) { FixedBitSet docsWithField = new FixedBitSet(maxDoc()); BytesRef[] values = new BytesRef[maxDoc()]; while (true) { int docID = oldDocValues.nextDoc(); if (docID == NO_MORE_DOCS) { break; } int newDocID = docMap.oldToNew(docID); docsWithField.set(newDocID); values[newDocID] = BytesRef.deepCopyOf(oldDocValues.binaryValue()); } dvs = new CachedBinaryDVs(values, docsWithField); cachedBinaryDVs.put(field, dvs); } } return new SortingBinaryDocValues(dvs); }
/** Sliced reference to points in an OfflineSorter.ByteSequencesWriter file. */ private static final class PathSlice { final PointWriter writer; final long start; final long count; public PathSlice(PointWriter writer, long start, long count) { this.writer = writer; this.start = start; this.count = count; } @Override public String toString() { return "PathSlice(start=" + start + " count=" + count + " writer=" + writer + ")"; } }
static LeafReader wrap(LeafReader reader, String field) throws IOException { DocIdSetIterator iterator = DocValuesFieldExistsQuery.getDocValuesDocIdSetIterator(field, reader); if (iterator == null) { return reader; } Bits liveDocs = reader.getLiveDocs(); final FixedBitSet bits; if (liveDocs != null) { bits = FixedBitSet.copyOf(liveDocs); } else { bits = new FixedBitSet(reader.maxDoc()); bits.set(0, reader.maxDoc()); } int numSoftDeletes = PendingSoftDeletes.applySoftDeletes(iterator, bits); int numDeletes = reader.numDeletedDocs() + numSoftDeletes; int numDocs = reader.maxDoc() - numDeletes; assert assertDocCounts(numDocs, numSoftDeletes, reader); return reader instanceof CodecReader ? new SoftDeletesFilterCodecReader((CodecReader) reader, bits, numDocs) : new SoftDeletesFilterLeafReader(reader, bits, numDocs); }
static void writeBitSet(DocIdSetIterator it, IndexOutput out) throws IOException { int i = 0; final FixedBitSet buffer = new FixedBitSet(1<<16); int prevBlock = -1; for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) { final int block = doc >>> 16; if (prevBlock != -1 && block != prevBlock) { flush(prevBlock, buffer, i, out); buffer.clear(0, buffer.length()); prevBlock = block; i = 0; } buffer.set(doc & 0xFFFF); i++; prevBlock = block; } if (i > 0) { flush(prevBlock, buffer, i, out); buffer.clear(0, buffer.length()); } // NO_MORE_DOCS is stored explicitly buffer.set(DocIdSetIterator.NO_MORE_DOCS & 0xFFFF); flush(DocIdSetIterator.NO_MORE_DOCS >>> 16, buffer, 1, out); }