BitSet of fixed length (numBits), backed by accessible (#getBits) long[], accessed with an int index, implementing GetBits and DocIdSet. If you need to manage more than 2.1B bits, use LongBitSet. @lucene.internal
Inheritance: DocIdSet, Bits
Esempio n. 1
0
        private FixedBitSet CorrectBits(AtomicReader reader, Bits acceptDocs)
        {
            FixedBitSet bits = new FixedBitSet(reader.MaxDoc); //assume all are INvalid
            Terms terms = reader.Fields.Terms(fieldName);

            if (terms == null)
            {
                return bits;
            }

            TermsEnum termsEnum = terms.Iterator(null);
            DocsEnum docs = null;
            while (true)
            {
                BytesRef currTerm = termsEnum.Next();
                if (currTerm == null)
                {
                    break;
                }
                else
                {
                    docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE);
                    int doc = docs.NextDoc();
                    if (doc != DocIdSetIterator.NO_MORE_DOCS)
                    {
                        if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE)
                        {
                            bits.Set(doc);
                        }
                        else
                        {
                            int lastDoc = doc;
                            while (true)
                            {
                                lastDoc = doc;
                                doc = docs.NextDoc();
                                if (doc == DocIdSetIterator.NO_MORE_DOCS)
                                {
                                    break;
                                }
                            }
                            bits.Set(lastDoc);
                        }
                    }
                }
            }
            return bits;
        }
Esempio n. 2
0
 /// <summary>
 /// Useful from an assert. </summary>
 internal virtual bool IsConsistent(int maxDoc)
 {
     FixedBitSet targets = new FixedBitSet(maxDoc);
     for (int i = 0; i < maxDoc; ++i)
     {
         int target = Map(i);
         if (target < 0 || target >= maxDoc)
         {
             Debug.Assert(false, "out of range: " + target + " not in [0-" + maxDoc + "[");
             return false;
         }
         else if (targets.Get(target))
         {
             Debug.Assert(false, target + " is already taken (" + i + ")");
             return false;
         }
     }
     return true;
 }
        protected override DocIdSet DocIdSetToCache(DocIdSet docIdSet, AtomicReader reader)
        {
            if (docIdSet == null)
            {
                return EMPTY_DOCIDSET;
            }

            if (docIdSet is FixedBitSet)
            {
                // this is different from CachingWrapperFilter: even when the DocIdSet is
                // cacheable, we convert it to a FixedBitSet since we require all the
                // cached filters to be FixedBitSets
                return docIdSet;
            }

            DocIdSetIterator it = docIdSet.GetIterator();
            if (it == null)
            {
                return EMPTY_DOCIDSET;
            }
            FixedBitSet copy = new FixedBitSet(reader.MaxDoc);
            copy.Or(it);
            return copy;
        }
Esempio n. 4
0
 /// <summary>
 /// this = this XOR other </summary>
 public void Xor(FixedBitSet other)
 {
     Debug.Assert(other.NumWords <= NumWords, "numWords=" + NumWords + ", other.numWords=" + other.NumWords);
     long[] thisBits = this.bits;
     long[] otherBits = other.bits;
     int pos = Math.Min(NumWords, other.NumWords);
     while (--pos >= 0)
     {
         thisBits[pos] ^= otherBits[pos];
     }
 }
Esempio n. 5
0
 /// <summary>
 /// returns true if the sets have any elements in common </summary>
 public bool Intersects(FixedBitSet other)
 {
     int pos = Math.Min(NumWords, other.NumWords);
     while (--pos >= 0)
     {
         if ((bits[pos] & other.bits[pos]) != 0)
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 6
0
 /// <summary>
 /// Returns the popcount or cardinality of the intersection of the two sets.
 /// Neither set is modified.
 /// </summary>
 public static long IntersectionCount(FixedBitSet a, FixedBitSet b)
 {
     return BitUtil.Pop_intersect(a.bits, b.bits, 0, Math.Min(a.NumWords, b.NumWords));
 }
Esempio n. 7
0
 /// <summary>
 /// Returns the popcount or cardinality of "a and not b" or
 /// "intersection(a, not(b))". Neither set is modified.
 /// </summary>
 public static long AndNotCount(FixedBitSet a, FixedBitSet b)
 {
     long tot = BitUtil.Pop_andnot(a.bits, b.bits, 0, Math.Min(a.NumWords, b.NumWords));
     if (a.NumWords > b.NumWords)
     {
         tot += BitUtil.Pop_array(a.bits, b.NumWords, a.NumWords - b.NumWords);
     }
     return tot;
 }
Esempio n. 8
0
 public static long IntersectionCount(FixedBitSet a, FixedBitSet b)
 {
     return(BitUtil.Pop_Intersect(a.bits, b.bits, 0, Math.Min(a.numWords, b.numWords)));
 }
 protected override DocIdSet CacheImpl(DocIdSetIterator iterator, AtomicReader reader)
 {
     FixedBitSet cached = new FixedBitSet(reader.MaxDoc);
     cached.Or(iterator);
     return cached;
 }
Esempio n. 10
0
 /// <summary>
 /// this = this OR other </summary>
 public void Or(FixedBitSet other)
 {
     Or(other.bits, other.numWords);
 }
Esempio n. 11
0
 /// <summary>
 /// this = this AND NOT other </summary>
 public void AndNot(FixedBitSet other)
 {
     AndNot(other.bits, other.bits.Length);
 }
 internal SVInOrderScorer(TermsIncludingScoreQuery outerInstance, Weight weight, Bits acceptDocs,
     TermsEnum termsEnum, int maxDoc, long cost)
     : base(weight)
 {
     this.outerInstance = outerInstance;
     FixedBitSet matchingDocs = new FixedBitSet(maxDoc);
     scores = new float[maxDoc];
     FillDocsAndScores(matchingDocs, acceptDocs, termsEnum);
     matchingDocsIterator = matchingDocs.GetIterator();
     cost_Renamed = cost;
 }
Esempio n. 13
0
 /// <summary>
 /// this = this AND NOT other </summary>
 public void AndNot(FixedBitSet other)
 {
     AndNot(other.bits, other.bits.Length);
 }
Esempio n. 14
0
        private FixedBitSet FastBits(AtomicReader reader, Bits acceptDocs)
        {
            FixedBitSet bits = new FixedBitSet(reader.MaxDoc);
            bits.Set(0, reader.MaxDoc); //assume all are valid
            Terms terms = reader.Fields.Terms(fieldName);

            if (terms == null)
            {
                return bits;
            }

            TermsEnum termsEnum = terms.Iterator(null);
            DocsEnum docs = null;
            while (true)
            {
                BytesRef currTerm = termsEnum.Next();
                if (currTerm == null)
                {
                    break;
                }
                else
                {
                    if (termsEnum.DocFreq() > 1)
                    {
                        // unset potential duplicates
                        docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE);
                        int doc = docs.NextDoc();
                        if (doc != DocIdSetIterator.NO_MORE_DOCS)
                        {
                            if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE)
                            {
                                doc = docs.NextDoc();
                            }
                        }

                        int lastDoc = -1;
                        while (true)
                        {
                            lastDoc = doc;
                            bits.Clear(lastDoc);
                            doc = docs.NextDoc();
                            if (doc == DocIdSetIterator.NO_MORE_DOCS)
                            {
                                break;
                            }
                        }

                        if (keepMode == KeepMode.KM_USE_LAST_OCCURRENCE)
                        {
                            // restore the last bit
                            bits.Set(lastDoc);
                        }
                    }
                }
            }

            return bits;
        }
 protected internal override void Start()
 {
     results = new FixedBitSet(maxDoc);
 }
Esempio n. 16
0
            public DocumentFilteredAtomicIndexReader(AtomicReaderContext context, Filter preserveFilter, bool negateFilter)
                    : base(context.AtomicReader)
            {
                int maxDoc = @in.MaxDoc;
                FixedBitSet bits = new FixedBitSet(maxDoc);
                // ignore livedocs here, as we filter them later:
                DocIdSet docs = preserveFilter.GetDocIdSet(context, null);
                if (docs != null)
                {
                    DocIdSetIterator it = docs.GetIterator();
                    if (it != null)
                    {
                        bits.Or(it);
                    }
                }
                if (negateFilter)
                {
                    bits.Flip(0, maxDoc);
                }

                if (@in.HasDeletions)
                {
                    Bits oldLiveDocs = @in.LiveDocs;
                    Debug.Assert(oldLiveDocs != null);
                    DocIdSetIterator it = bits.GetIterator();
                    for (int i = it.NextDoc(); i < maxDoc; i = it.NextDoc())
                    {
                        if (!oldLiveDocs.Get(i))
                        {
                            // we can safely modify the current bit, as the iterator already stepped over it:
                            bits.Clear(i);
                        }
                    }
                }

                this.liveDocs = bits;
                this.numDocs_Renamed = bits.Cardinality();
            }
Esempio n. 17
0
 protected internal override void Start()
 {
     inside = new FixedBitSet(maxDoc);
     outside = new FixedBitSet(maxDoc);
 }
 protected virtual void FillDocsAndScores(FixedBitSet matchingDocs, Bits acceptDocs,
     TermsEnum termsEnum)
 {
     BytesRef spare = new BytesRef();
     DocsEnum docsEnum = null;
     for (int i = 0; i < outerInstance._terms.Size(); i++)
     {
         if (termsEnum.SeekExact(outerInstance._terms.Get(outerInstance._ords[i], spare)))
         {
             docsEnum = termsEnum.Docs(acceptDocs, docsEnum, FLAG_NONE);
             float score = outerInstance._scores[outerInstance._ords[i]];
             for (int doc = docsEnum.NextDoc();
                 doc != NO_MORE_DOCS;
                 doc = docsEnum.NextDoc())
             {
                 matchingDocs.Set(doc);
                 // In the case the same doc is also related to a another doc, a score might be overwritten. I think this
                 // can only happen in a many-to-many relation
                 scores[doc] = score;
             }
         }
     }
 }
Esempio n. 19
0
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: private void doChain(org.apache.lucene.util.FixedBitSet result, int logic, org.apache.lucene.search.DocIdSet dis) throws java.io.IOException
        private void doChain(FixedBitSet result, int logic, DocIdSet dis)
        {
            if (dis is FixedBitSet)
            {
                // optimized case for FixedBitSets
                switch (logic)
                {
                    case OR:
                        result.Or((FixedBitSet)dis);
                        break;
                    case AND:
                        result.And((FixedBitSet)dis);
                        break;
                    case ANDNOT:
                        result.AndNot((FixedBitSet)dis);
                        break;
                    case XOR:
                        result.Xor((FixedBitSet)dis);
                        break;
                    default:
                        doChain(result, DEFAULT, dis);
                        break;
                }
            }
            else
            {
                DocIdSetIterator disi;
                if (dis == null)
                {
                    disi = DocIdSetIterator.Empty();
                }
                else
                {
                    disi = dis.GetIterator() ?? DocIdSetIterator.Empty();
                }

                switch (logic)
                {
                    case OR:
                        result.Or(disi);
                        break;
                    case AND:
                        result.And(disi);
                        break;
                    case ANDNOT:
                        result.AndNot(disi);
                        break;
                    case XOR:
                        result.Xor(disi);
                        break;
                    default:
                        doChain(result, DEFAULT, dis);
                        break;
                }
            }
        }
Esempio n. 20
0
 private FixedBitSet InitialResult(AtomicReaderContext context, int logic, int[] index)
 {
     AtomicReader reader = context.AtomicReader;
     FixedBitSet result = new FixedBitSet(reader.MaxDoc);
     if (logic == AND)
     {
         result.Or(GetDISI(chain[index[0]], context));
         ++index[0];
     }
     else if (logic == ANDNOT)
     {
         result.Or(GetDISI(chain[index[0]], context));
         result.Flip(0, reader.MaxDoc); // NOTE: may set bits for deleted docs.
         ++index[0];
     }
     return result;
 }
Esempio n. 21
0
 /// <summary>
 /// this = this AND other </summary>
 public void And(FixedBitSet other)
 {
     And(other.bits, other.numWords);
 }
 public BlockJoinScorer(Weight weight, Scorer childScorer, FixedBitSet parentBits, int firstChildDoc, ScoreMode scoreMode, Bits acceptDocs) : base(weight)
 {
     //System.out.println("Q.init firstChildDoc=" + firstChildDoc);
     _parentBits = parentBits;
     _childScorer = childScorer;
     _scoreMode = scoreMode;
     _acceptDocs = acceptDocs;
     _nextChildDoc = firstChildDoc;
 }
Esempio n. 23
0
 public IntRangeBuilderAnonymousClass(int lower, int upper, bool useBitSet, FixedBitSet bits, IEnumerator <int> neededBounds, IEnumerator <int> neededShifts)
 {
     this.lower        = lower;
     this.upper        = upper;
     this.useBitSet    = useBitSet;
     this.bits         = bits;
     this.neededBounds = neededBounds;
     this.neededShifts = neededShifts;
 }
Esempio n. 24
0
 public ToChildBlockJoinScorer(Weight weight, Scorer parentScorer, FixedBitSet parentBits, bool doScores, Bits acceptDocs)
     : base(weight)
 {
     _doScores = doScores;
     _parentBits = parentBits;
     _parentScorer = parentScorer;
     _acceptDocs = acceptDocs;
 }
Esempio n. 25
0
 /// <summary>
 /// Creates an iterator over the given <see cref="FixedBitSet"/>. </summary>
 public FixedBitSetIterator(FixedBitSet bits)
     : this(bits.bits, bits.numBits, bits.numWords)
 {
 }
Esempio n. 26
0
 protected virtual void CollectDocs(FixedBitSet bitSet)
 {
     //WARN: keep this specialization in sync
     Debug.Assert(termsEnum != null);
     docsEnum = termsEnum.Docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
     int docid;
     while ((docid = docsEnum.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
     {
         bitSet.Set(docid);
     }
 }
Esempio n. 27
0
 /// <summary>
 /// If the given <seealso cref="FixedBitSet"/> is large enough to hold {@code numBits},
 /// returns the given bits, otherwise returns a new <seealso cref="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 <seealso cref="#length()"/> on the
 /// returned bits may return a value greater than {@code numBits}.
 /// </summary>
 public static FixedBitSet EnsureCapacity(FixedBitSet bits, int numBits)
 {
     if (numBits < bits.Length())
     {
         return bits;
     }
     else
     {
         int numWords = Bits2words(numBits);
         long[] arr = bits.Bits;
         if (numWords >= arr.Length)
         {
             arr = ArrayUtil.Grow(arr, numWords + 1);
         }
         return new FixedBitSet(arr, arr.Length << 6);
     }
 }
Esempio n. 28
0
 public IntRangeBuilderAnonymousInnerClassHelper(TestNumericUtils outerInstance, int lower, int upper, bool useBitSet, FixedBitSet bits, IEnumerator <int> neededBounds, IEnumerator <int> neededShifts)
 {
     this.OuterInstance = outerInstance;
     this.Lower         = lower;
     this.Upper         = upper;
     this.UseBitSet     = useBitSet;
     this.Bits          = bits;
     this.NeededBounds  = neededBounds;
     this.NeededShifts  = neededShifts;
 }
Esempio n. 29
0
 /// <summary>
 /// Returns the popcount or cardinality of the union of the two sets. Neither
 /// set is modified.
 /// </summary>
 public static long UnionCount(FixedBitSet a, FixedBitSet b)
 {
     long tot = BitUtil.Pop_union(a.bits, b.bits, 0, Math.Min(a.NumWords, b.NumWords));
     if (a.NumWords < b.NumWords)
     {
         tot += BitUtil.Pop_array(b.bits, a.NumWords, b.NumWords - a.NumWords);
     }
     else if (a.NumWords > b.NumWords)
     {
         tot += BitUtil.Pop_array(a.bits, b.NumWords, a.NumWords - b.NumWords);
     }
     return tot;
 }
Esempio n. 30
0
 public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
 {
     AtomicReader reader = context.AtomicReader;
     FixedBitSet result = null; // lazy init if needed - no need to create a big bitset ahead of time
     Fields fields = reader.Fields;
     BytesRef spare = new BytesRef(this.termsBytes);
     if (fields == null)
     {
         return result;
     }
     Terms terms = null;
     TermsEnum termsEnum = null;
     DocsEnum docs = null;
     foreach (TermsAndField termsAndField in this.termsAndFields)
     {
         if ((terms = fields.Terms(termsAndField.field)) != null)
         {
             termsEnum = terms.Iterator(termsEnum); // this won't return null
             for (int i = termsAndField.start; i < termsAndField.end; i++)
             {
                 spare.Offset = offsets[i];
                 spare.Length = offsets[i + 1] - offsets[i];
                 if (termsEnum.SeekExact(spare))
                 {
                     docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE); // no freq since we don't need them
                     if (result == null)
                     {
                         if (docs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                         {
                             result = new FixedBitSet(reader.MaxDoc);
                             // lazy init but don't do it in the hot loop since we could read many docs
                             result.Set(docs.DocID());
                         }
                     }
                     while (docs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                     {
                         result.Set(docs.DocID());
                     }
                 }
             }
         }
     }
     return result;
 }
Esempio n. 31
0
 /// <summary>
 /// this = this OR other </summary>
 public void Or(FixedBitSet other)
 {
     Or(other.bits, other.NumWords);
 }
 private Bits GetMissingBits(int fieldNumber, long offset, long length)
 {
     if (offset == -1)
     {
         return new Bits_MatchAllBits(maxDoc);
     }
     else
     {
         Bits instance;
         lock (this)
         {
             if (!docsWithFieldInstances.TryGetValue(fieldNumber, out instance))
             {
                 var data = (IndexInput)this.data.Clone();
                 data.Seek(offset);
                 Debug.Assert(length % 8 == 0);
                 var bits = new long[(int)length >> 3];
                 for (var i = 0; i < bits.Length; i++)
                 {
                     bits[i] = data.ReadLong();
                 }
                 instance = new FixedBitSet(bits, maxDoc);
                 docsWithFieldInstances[fieldNumber] = instance;
             }
         }
         return instance;
     }
 }
Esempio n. 33
0
 /// <summary>
 /// Creates an iterator over the given <seealso cref="FixedBitSet"/>. </summary>
 public FixedBitSetIterator(FixedBitSet bits)
     : this(bits.bits, bits.NumBits, bits.NumWords)
 {
 }
Esempio n. 34
0
 public IntRangeBuilderAnonymousInnerClassHelper(TestNumericUtils outerInstance, int lower, int upper, bool useBitSet, FixedBitSet bits, IEnumerator<int> neededBounds, IEnumerator<int> neededShifts)
 {
     this.OuterInstance = outerInstance;
     this.Lower = lower;
     this.Upper = upper;
     this.UseBitSet = useBitSet;
     this.Bits = bits;
     this.NeededBounds = neededBounds;
     this.NeededShifts = neededShifts;
 }
Esempio n. 35
0
 /// <summary>
 /// this = this AND other </summary>
 public void And(FixedBitSet other)
 {
     And(other.bits, other.NumWords);
 }
Esempio n. 36
0
 public DocsAnonymousInnerClassHelper(FacetsCollector outerInstance, int maxDoc)
 {
     this.outerInstance = outerInstance;
     this.maxDoc = maxDoc;
     bits = new FixedBitSet(maxDoc);
 }
Esempio n. 37
0
 internal RandomBits(int maxDoc, double pctLive, Random random)
 {
     bits = new FixedBitSet(maxDoc);
     for (int i = 0; i < maxDoc; i++)
     {
         if (random.NextDouble() <= pctLive)
         {
             bits.Set(i);
         }
     }
 }
Esempio n. 38
0
 public static int Cardinality(this FixedBitSet set)
 {
     return(set.Cardinality);
 }