Inheritance: Lucene.Net.Search.DocIdSet, System.ICloneable
 public static OpenBitSet CreateBitSet(IndexReader reader, Filter filter)
 {
     IndexSearcher searcher = new IndexSearcher(reader);
     OpenBitSet result = new OpenBitSet();
     searcher.Search(new MatchAllDocsQuery(), filter, new BitSetCollector(result));
     return result;
 }
Example #2
0
        /// <summary>
        /// Asserts that the documents returned by <paramref name="q1"/>
        /// are a subset of those returned by <paramref name="q2"/>.
        /// <para/>
        /// Both queries will be filtered by <paramref name="filter"/>.
        /// </summary>
        protected virtual void AssertSubsetOf(Query q1, Query q2, Filter filter)
        {
            // TRUNK ONLY: test both filter code paths
            if (filter != null && Random.NextBoolean())
            {
                q1     = new FilteredQuery(q1, filter, TestUtil.RandomFilterStrategy(Random));
                q2     = new FilteredQuery(q2, filter, TestUtil.RandomFilterStrategy(Random));
                filter = null;
            }

            // not efficient, but simple!
            TopDocs td1 = m_s1.Search(q1, filter, m_reader.MaxDoc);
            TopDocs td2 = m_s2.Search(q2, filter, m_reader.MaxDoc);

            Assert.IsTrue(td1.TotalHits <= td2.TotalHits);

            // fill the superset into a bitset
            var bitset = new BitSet(td2.ScoreDocs.Length);

            for (int i = 0; i < td2.ScoreDocs.Length; i++)
            {
                bitset.Set(td2.ScoreDocs[i].Doc);
            }

            // check in the subset, that every bit was set by the super
            for (int i = 0; i < td1.ScoreDocs.Length; i++)
            {
                Assert.IsTrue(bitset.Get(td1.ScoreDocs[i].Doc));
            }
        }
 public BitSetRandomAccessDocIdSet(bool multi, MultiValueFacetDataCache multiCache, OpenBitSet openBitSet, FacetDataCache dataCache)
 {
     _multi = multi;
     _multiCache = multiCache;
     _openBitSet = openBitSet;
     _dataCache = dataCache;
 }
Example #4
0
		// test interleaving different OpenBitSetIterator.next()/skipTo()
		internal virtual void  DoIterate(System.Collections.BitArray a, OpenBitSet b, int mode)
		{
			if (mode == 1)
				DoIterate1(a, b);
			if (mode == 2)
				DoIterate2(a, b);
		}
 public override sealed int FindValues(OpenBitSet bitset, int docId, int maxId)
 {
     while (docId <= maxId && !bitset.FastGet(array[docId >> SHIFT_SIZE][docId & MASK]))
     {
         docId++;
     }
     return docId;
 }
 public override int FindValues(OpenBitSet bitset, int docId, int maxId)
 {
     while (docId <= maxId && !bitset.FastGet(array[docId >> SHIFT_SIZE][docId & MASK]))
     {
         docId++;
     }
     return docId > maxId ? DocIdSetIterator.NO_MORE_DOCS : docId;
 }
Example #7
0
 internal virtual void  DoGet(System.Collections.BitArray a, OpenBitSet b)
 {
     int max = a.Count;
     for (int i = 0; i < max; i++)
     {
         Assert.AreEqual(a.Get(i) != b.Get(i), "mismatch: BitSet=[" + i + "]=" + a.Get(i));
     }
 }
Example #8
0
 public override sealed int FindValues(OpenBitSet bitset, int docId, int maxId)
 {
     while (true)
     {
         if (bitset.FastGet(_array[docId >> SHIFT_SIZE][docId & MASK])) return docId;
         if (docId++ >= maxId) break;
     }
     return DocIdSetIterator.NO_MORE_DOCS;
 }
 public virtual OpenBitSet GetBitSet(FacetDataCache dataCache)
 {
     if (lastCache == dataCache)
     {
         return bitSet;
     }
     bitSet = bitSetBuilder.BitSet(dataCache);
     lastCache = dataCache;
     return bitSet;
 }
Example #10
0
		internal virtual void  DoNextSetBit(System.Collections.BitArray a, OpenBitSet b)
		{
			int aa = - 1, bb = - 1;
			do 
			{
				aa = SupportClass.BitSetSupport.NextSetBit(a, aa + 1);
				bb = b.NextSetBit(bb + 1);
				Assert.AreEqual(aa, bb);
			}
			while (aa >= 0);
		}
 public MultiValueORFacetFilter(MultiValueFacetDataCache dataCache, int[] index)
 {
     _dataCache = dataCache;
     _nestedArray = dataCache._nestedArray;
     _index = index;
     _bitset = new OpenBitSet(_dataCache.valArray.Count);
     foreach (int i in _index)
     {
         _bitset.FastSet(i);
     }
 }
Example #12
0
		internal virtual void  DoIterate2(System.Collections.BitArray a, OpenBitSet b)
		{
			int aa = - 1, bb = - 1;
			OpenBitSetIterator iterator = new OpenBitSetIterator(b);
			do 
			{
				aa = SupportClass.BitSetSupport.NextSetBit(a, aa + 1);
				bb = rand.NextDouble() > 0.5 ? iterator.NextDoc() : iterator.Advance(bb + 1);
				Assert.AreEqual(aa == - 1?DocIdSetIterator.NO_MORE_DOCS:aa, bb);
			}
			while (aa >= 0);
		}
 public override DocIdSet GetDocIdSet(IndexReader reader)
 {
     OpenBitSet bitSet = new OpenBitSet(reader.NumDocs());
     TermDocs termDocs = reader.TermDocs(new Term("TenantId", _tenantId));
     while (termDocs.Next())
     {
         if (termDocs.Freq > 0)
         {
             bitSet.Set(termDocs.Doc);
         }
     }
     return bitSet;
 }
 public FacetOrFilter(FacetDataCache dataCache, int[] index, bool takeCompliment)
 {
     this.dataCache = dataCache;
     orderArray = dataCache.orderArray;
     this.index = index;
     bitset = new OpenBitSet(this.dataCache.valArray.Count);
     foreach (int i in this.index)
     {
         bitset.FastSet(i);
     }
     if (takeCompliment)
     {
         bitset.Flip(0, this.dataCache.valArray.Count);
     }
 }
        public virtual OpenBitSet BitSet(FacetDataCache dataCache)
        {
            int[] index = facetValueConverter.Convert(dataCache, vals);

            OpenBitSet bitset = new OpenBitSet(dataCache.ValArray.Count);
            foreach (int i in index)
            {
                bitset.FastSet(i);
            }
            if (takeCompliment)
            {
                // flip the bits
                for (int i = 0; i < index.Length; ++i)
                {
                    bitset.FastFlip(i);
                }
            }
            return bitset;
        }
Example #16
0
        /// <summary>
        /// Get the DocIdSet.
        /// </summary>
        /// <param name="reader">Applcible reader.</param>
        /// <returns>The set.</returns>
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            OpenBitSet result = new OpenBitSet(reader.MaxDoc());
            TermDocs td = reader.TermDocs();
            try
            {
                foreach (Term t in this.terms)
                {
                    td.Seek(t);
                    while (td.Next())
                    {
                        result.Set(td.Doc());
                    }
                }
            }
            finally
            {
                td.Close();
            }

            return result;
        }
Example #17
0
        private static void Walk <T>(FST <T> fst) // LUCENENET NOTE: Not referenced anywhere
        {
            var queue = new List <FST.Arc <T> >();

            // Java version was BitSet(), but in .NET we don't have a zero contructor BitSet.
            // Couldn't find the default size in BitSet, so went with zero here.
            var seen     = new BitSet();
            var reader   = fst.GetBytesReader();
            var startArc = fst.GetFirstArc(new FST.Arc <T>());

            queue.Add(startArc);
            while (queue.Count > 0)
            {
                //FST.Arc<T> arc = queue.Remove(0);
                var arc = queue[0];
                queue.RemoveAt(0);

                long node = arc.Target;
                //System.out.println(arc);
                if (FST <T> .TargetHasArcs(arc) && !seen.Get((int)node))
                {
                    seen.Set((int)node);
                    fst.ReadFirstRealTargetArc(node, arc, reader);
                    while (true)
                    {
                        queue.Add((new FST.Arc <T>()).CopyFrom(arc));
                        if (arc.IsLast)
                        {
                            break;
                        }
                        else
                        {
                            fst.ReadNextRealArc(arc, reader);
                        }
                    }
                }
            }
        }
Example #18
0
        private OpenBitSet CorrectBits(IndexReader reader)
        {

            OpenBitSet bits = new OpenBitSet(reader.MaxDoc()); //assume all are INvalid
            Term startTerm = new Term(fieldName);
            TermEnum te = reader.Terms(startTerm);
            if (te != null)
            {
                Term currTerm = te.Term();
                while ((currTerm != null) && (currTerm.Field() == startTerm.Field())) //term fieldnames are interned
                {
                    int lastDoc = -1;
                    //set non duplicates
                    TermDocs td = reader.TermDocs(currTerm);
                    if (td.Next())
                    {
                        if (keepMode == KM_USE_FIRST_OCCURRENCE)
                        {
                            bits.Set(td.Doc());
                        }
                        else
                        {
                            do
                            {
                                lastDoc = td.Doc();
                            } while (td.Next());
                            bits.Set(lastDoc);
                        }
                    }
                    if (!te.Next())
                    {
                        break;
                    }
                    currTerm = te.Term();
                }
            }
            return bits;
        }
        public NuGetIndexSearcher(
            NuGetSearcherManager manager,
            IndexReader reader,
            IDictionary<string, string> commitUserData,
            IDictionary<string, Filter> curatedFeeds,
            Filter[][] latest,
            IReadOnlyDictionary<string, int[]> docIdMapping,
            Downloads downloads,
            VersionResult[] versions,
            RankingResult rankings,
            QueryBoostingContext context,
            OpenBitSet latestBitSet,
            OpenBitSet latestStableBitSet,
            OwnersResult owners)
            : base(reader)
        {
            Manager = manager;
            CommitUserData = commitUserData;

            _curatedFeeds = new Dictionary<string, Filter>(curatedFeeds.Count);
            foreach (var curatedFeedsFilter in curatedFeeds)
            {
                _curatedFeeds.Add(curatedFeedsFilter.Key, new CachingWrapperFilter(curatedFeedsFilter.Value));
            }

            _latest = latest;
            DocIdMapping = docIdMapping;
            Downloads = downloads;
            Versions = versions;
            Rankings = rankings;
            LatestBitSet = latestBitSet;
            LatestStableBitSet = latestStableBitSet;
            Owners = owners;
            QueryBoostingContext = context;
            LastReopen = DateTime.UtcNow;
        }
Example #20
0
		public override DocIdSet GetDocIdSet(IndexReader reader)
		{
			var bits = new OpenBitSet(reader.MaxDoc());

			TermDocs termDocs = reader.TermDocs();
			List<double> area = _shape.Area;
			int sz = area.Count;
			
			// iterate through each boxid
			for (int i = 0; i < sz; i++)
			{
				double boxId = area[i];
				termDocs.Seek(new Term(_fieldName, NumericUtils.DoubleToPrefixCoded(boxId)));

				// iterate through all documents
				// which have this boxId
				while (termDocs.Next())
				{
					bits.FastSet(termDocs.Doc());
				}
			}

			return bits;
		}
Example #21
0
		internal virtual void  DoRandomSets(int maxSize, int iter, int mode)
		{
			System.Collections.BitArray a0 = null;
			OpenBitSet b0 = null;
			
			for (int i = 0; i < iter; i++)
			{
				int sz = rand.Next(maxSize);
				System.Collections.BitArray a = new System.Collections.BitArray(sz);
				OpenBitSet b = new OpenBitSet(sz);
				
				// test the various ways of setting bits
				if (sz > 0)
				{
					int nOper = rand.Next(sz);
					for (int j = 0; j < nOper; j++)
					{
						int idx;
						
						idx = rand.Next(sz);
						a.Set(idx, true);
						b.FastSet(idx);
						idx = rand.Next(sz);
						a.Set(idx, false);
						b.FastClear(idx);
						idx = rand.Next(sz);
						a.Set(idx, !a.Get(idx));
						b.FastFlip(idx);
						
						bool val = b.FlipAndGet(idx);
						bool val2 = b.FlipAndGet(idx);
						Assert.IsTrue(val != val2);
						
						val = b.GetAndSet(idx);
						Assert.IsTrue(val2 == val);
						Assert.IsTrue(b.Get(idx));
						
						if (!val)
							b.FastClear(idx);
						Assert.IsTrue(b.Get(idx) == val);
					}
				}
				
				// test that the various ways of accessing the bits are equivalent
				DoGet(a, b);
				
                // {{dougsale-2.4.0}}
                //
                // Java's java.util.BitSet automatically grows as needed - i.e., when a bit is referenced beyond
                // the size of the BitSet, an exception isn't thrown - rather, the set grows to the size of the 
                // referenced bit.
                //
                // System.Collections.BitArray does not have this feature, and thus I've faked it here by
                // "growing" the array explicitly when necessary (creating a new instance of the appropriate size
                // and setting the appropriate bits).
                //

                // test ranges, including possible extension
                int fromIndex, toIndex;
                fromIndex = rand.Next(sz + 80);
                toIndex = fromIndex + rand.Next((sz >> 1) + 1);

                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSets 'a'
                // and 'aa' to the same cardinality as 'j+1' when 'a.Count < j+1' and 'fromIndex < toIndex':
                //BitArray aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
                // So, if necessary, lets explicitly grow 'a' now; then 'a' and its clone, 'aa', will be of the required size.
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    System.Collections.BitArray tmp = new System.Collections.BitArray(toIndex, false);
                    for (int k = 0; k < a.Count; k++)
                        tmp.Set(k, a.Get(k));
                    a = tmp;
                }
                // {{dougsale-2.4.0}}: now we can invoke this statement without going 'out-of-bounds'
                System.Collections.BitArray aa = (System.Collections.BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
                OpenBitSet bb = (OpenBitSet)b.Clone(); bb.Flip(fromIndex, toIndex);

                DoIterate(aa, bb, mode); // a problem here is from flip or doIterate

                fromIndex = rand.Next(sz + 80);
                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
                // when 'a.Count < j+1' and 'fromIndex < toIndex'
                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                // So, if necessary, lets explicitly grow 'aa' now
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    aa = new System.Collections.BitArray(toIndex);
                    for (int k = 0; k < a.Count; k++)
                        aa.Set(k, a.Get(k));
                }
                else
                {
                    aa = (System.Collections.BitArray)a.Clone();
                }
                for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                bb = (OpenBitSet)b.Clone(); bb.Clear(fromIndex, toIndex);

                DoNextSetBit(aa, bb); // a problem here is from clear() or nextSetBit

                fromIndex = rand.Next(sz + 80);
                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
                // when 'a.Count < j+1' and 'fromIndex < toIndex'
                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                // So, if necessary, lets explicitly grow 'aa' now
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    aa = new System.Collections.BitArray(toIndex);
                    for (int k = 0; k < a.Count; k++)
                        aa.Set(k, a.Get(k));
                }
                else
                {
                    aa = (System.Collections.BitArray)a.Clone();
                }
                for (int j = fromIndex; j < toIndex; j++) aa.Set(j, true);
                bb = (OpenBitSet)b.Clone(); bb.Set(fromIndex, toIndex);
				
				DoNextSetBit(aa, bb); // a problem here is from set() or nextSetBit     
				
				
				if (a0 != null)
				{
                    Assert.AreEqual(a.Equals(a0), b.Equals(b0));

                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a), b.Cardinality());

                    // {{dougsale-2.4.0}}
                    //
                    // The Java code used java.util.BitSet, which grows as needed.
                    // When a bit, outside the dimension of the set is referenced,
                    // the set automatically grows to the necessary size.  The
                    // new entries default to false.
                    //
                    // BitArray does not grow automatically and is not growable.
                    // Thus when BitArray instances of mismatched cardinality
                    // interact, we must first explicitly "grow" the smaller one.
                    //
                    // This growth is acheived by creating a new instance of the
                    // required size and copying the appropriate values.
                    //

                    //BitArray a_and = (BitArray)a.Clone(); a_and.And(a0);
                    //BitArray a_or = (BitArray)a.Clone(); a_or.Or(a0);
                    //BitArray a_xor = (BitArray)a.Clone(); a_xor.Xor(a0);
                    //BitArray a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);

                    System.Collections.BitArray a_and;
                    System.Collections.BitArray a_or;
                    System.Collections.BitArray a_xor;
                    System.Collections.BitArray a_andn;

                    if (a.Count < a0.Count)
                    {
                        // the Java code would have implicitly resized 'a_and', 'a_or', 'a_xor', and 'a_andn'
                        // in this case, so we explicitly create a resized stand-in for 'a' here, allowing for
                        // a to keep its original size while 'a_and', 'a_or', 'a_xor', and 'a_andn' are resized
                        System.Collections.BitArray tmp = new System.Collections.BitArray(a0.Count, false);
                        for (int z = 0; z < a.Count; z++)
                            tmp.Set(z, a.Get(z));

                        a_and = (System.Collections.BitArray)tmp.Clone(); a_and.And(a0);
                        a_or = (System.Collections.BitArray)tmp.Clone(); a_or.Or(a0);
                        a_xor = (System.Collections.BitArray)tmp.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)tmp.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
                    }
                    else if (a.Count > a0.Count)
                    {
                        // the Java code would have implicitly resized 'a0' in this case, so
                        // we explicitly do so here:
                        System.Collections.BitArray tmp = new System.Collections.BitArray(a.Count, false);
                        for (int z = 0; z < a0.Count; z++)
                            tmp.Set(z, a0.Get(z));
                        a0 = tmp;

                        a_and = (System.Collections.BitArray)a.Clone(); a_and.And(a0);
                        a_or = (System.Collections.BitArray)a.Clone(); a_or.Or(a0);
                        a_xor = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
                    }
                    else
                    {
                        // 'a' and 'a0' are the same size, no explicit growing necessary
                        a_and = (System.Collections.BitArray)a.Clone(); a_and.And(a0);
                        a_or = (System.Collections.BitArray)a.Clone(); a_or.Or(a0);
                        a_xor = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
                    }

                    OpenBitSet b_and = (OpenBitSet)b.Clone(); Assert.AreEqual(b, b_and); b_and.And(b0);
                    OpenBitSet b_or = (OpenBitSet)b.Clone(); b_or.Or(b0);
                    OpenBitSet b_xor = (OpenBitSet)b.Clone(); b_xor.Xor(b0);
                    OpenBitSet b_andn = (OpenBitSet)b.Clone(); b_andn.AndNot(b0);

                    DoIterate(a_and, b_and, mode);
                    DoIterate(a_or, b_or, mode);
                    DoIterate(a_xor, b_xor, mode);
                    DoIterate(a_andn, b_andn, mode);

                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_and), b_and.Cardinality());
                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_or), b_or.Cardinality());
                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_xor), b_xor.Cardinality());
                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_andn), b_andn.Cardinality());

                    // test non-mutating popcounts
                    Assert.AreEqual(b_and.Cardinality(), OpenBitSet.IntersectionCount(b, b0));
                    Assert.AreEqual(b_or.Cardinality(), OpenBitSet.UnionCount(b, b0));
                    Assert.AreEqual(b_xor.Cardinality(), OpenBitSet.XorCount(b, b0));
                    Assert.AreEqual(b_andn.Cardinality(), OpenBitSet.AndNotCount(b, b0));
                }
				
				a0 = a;
				b0 = b;
			}
		}
Example #22
0
 public OpenBitSetIterator(OpenBitSet obs) : this(obs.Bits, obs.NumWords)
 {
 }
Example #23
0
 /// <summary>
 /// Returns the popcount or cardinality of the intersection of the two sets.
 /// Neither set is modified.
 /// </summary>
 public static long IntersectionCount(OpenBitSet a, OpenBitSet b)
 {
     return(BitUtil.Pop_Intersect(a.m_bits, b.m_bits, 0, Math.Min(a.m_wlen, b.m_wlen)));
 }
 //* see <see cref="union" /> */
 public virtual void  Or(OpenBitSet other)
 {
     Union(other);
 }
 public MultiRandomAccessDocIdSet(MultiValueFacetDataCache dataCache, OpenBitSet bitset)
 {
     this.dataCache = dataCache;
     this.bitset = bitset;
     this.nestedArray = dataCache.NestedArray;
 }
Example #26
0
 public OpenBitSetIterator(OpenBitSet obs)
     : this(obs.GetBits(), obs.GetNumWords())
 {
 }
 /**
  * Create a SortedVIntList from an OpenBitSet.
  * @param  bits  A bit set representing a set of integers.
  */
 public SortedVIntList(OpenBitSet bits)
 {
     SortedVIntListBuilder builder = new SortedVIntListBuilder(this);
     int nextInt = bits.NextSetBit(0);
     while (nextInt != -1)
     {
         builder.AddInt(nextInt);
         nextInt = bits.NextSetBit(nextInt + 1);
     }
     builder.Done();
 }
        public override RandomAccessDocIdSet GetRandomAccessDocIdSet(BoboIndexReader reader)
        {
            MultiValueFacetDataCache dataCache = _facetHandler.GetFacetData<MultiValueFacetDataCache>(reader);
            int[] index = _valueConverter.Convert(dataCache, _vals);
            //BigNestedIntArray nestedArray = dataCache.NestedArray;
            OpenBitSet bitset = new OpenBitSet(dataCache.ValArray.Count);

            foreach (int i in index)
            {
                bitset.FastSet(i);
            }

            if (_takeCompliment)
            {
                // flip the bits
                int size = dataCache.ValArray.Count;
                for (int i = 0; i < size; ++i)
                {
                    bitset.FastFlip(i);
                }
            }

            long count = bitset.Cardinality();

            if (count == 0)
            {
                return new EmptyRandomAccessDocIdSet();
            }
            else
            {
                return new MultiRandomAccessDocIdSet(dataCache, bitset);
            }
        }
Example #29
0
 /// <summary>Returns the popcount or cardinality of the intersection of the two sets.
 /// Neither set is modified.
 /// </summary>
 public static long IntersectionCount(OpenBitSet a, OpenBitSet b)
 {
     return(BitUtil.Pop_intersect(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen)));
 }
 //* see <see cref="andNot" /> */
 public virtual void  AndNot(OpenBitSet other)
 {
     Remove(other);
 }
Example #31
0
 public SearchBits(OpenBitSet openBitSet) {
     _openBitSet = openBitSet;
 }
Example #32
0
 public OpenBitSetIterator(OpenBitSet obs) : this(obs.GetBits(), obs.GetNumWords())
 {
 }
		public override DocIdSet GetDocIdSet(Index.IndexReader reader /*, Bits acceptDocs*/)
		{
			var bits = new OpenBitSet(reader.MaxDoc);
			var terms = new TermsEnumCompatibility(reader, fieldName);
			var term = terms.Next();
			if (term == null)
				return null;
			Node scanCell = null;

			//cells is treated like a stack. LinkedList conveniently has bulk add to beginning. It's in sorted order so that we
			//  always advance forward through the termsEnum index.
			var cells = new LinkedList<Node>(
				grid.GetWorldNode().GetSubCells(queryShape));

			//This is a recursive algorithm that starts with one or more "big" cells, and then recursively dives down into the
			// first such cell that intersects with the query shape.  It's a depth first traversal because we don't move onto
			// the next big cell (breadth) until we're completely done considering all smaller cells beneath it. For a given
			// cell, if it's *within* the query shape then we can conveniently short-circuit the depth traversal and
			// grab all documents assigned to this cell/term.  For an intersection of the cell and query shape, we either
			// recursively step down another grid level or we decide heuristically (via prefixGridScanLevel) that there aren't
			// that many points, and so we scan through all terms within this cell (i.e. the term starts with the cell's term),
			// seeing which ones are within the query shape.
			while (cells.Count > 0)
			{
				Node cell = cells.First.Value; cells.RemoveFirst();
				var cellTerm = cell.GetTokenString();
				var seekStat = terms.Seek(cellTerm);
				if (seekStat == TermsEnumCompatibility.SeekStatus.END)
					break;
				if (seekStat == TermsEnumCompatibility.SeekStatus.NOT_FOUND)
					continue;
				if (cell.GetLevel() == detailLevel || cell.IsLeaf())
				{
					terms.Docs(bits);
				}
				else
				{//any other intersection
					//If the next indexed term is the leaf marker, then add all of them
					var nextCellTerm = terms.Next();
					Debug.Assert(nextCellTerm.Text.StartsWith(cellTerm));
					scanCell = grid.GetNode(nextCellTerm.Text, scanCell);
					if (scanCell.IsLeaf())
					{
						terms.Docs(bits);
						term = terms.Next();//move pointer to avoid potential redundant addDocs() below
					}

					//Decide whether to continue to divide & conquer, or whether it's time to scan through terms beneath this cell.
					// Scanning is a performance optimization trade-off.
					bool scan = cell.GetLevel() >= prefixGridScanLevel;//simple heuristic

					if (!scan)
					{
						//Divide & conquer
						var lst = cell.GetSubCells(queryShape);
						for (var i = lst.Count - 1; i >= 0; i--) //add to beginning
						{
							cells.AddFirst(lst[i]);
						}
					}
					else
					{
						//Scan through all terms within this cell to see if they are within the queryShape. No seek()s.
						for (var t = terms.Term(); t != null && t.Text.StartsWith(cellTerm); t = terms.Next())
						{
							scanCell = grid.GetNode(t.Text, scanCell);
							int termLevel = scanCell.GetLevel();
							if (termLevel > detailLevel)
								continue;
							if (termLevel == detailLevel || scanCell.IsLeaf())
							{
								//TODO should put more thought into implications of box vs point
								Shape cShape = termLevel == grid.GetMaxLevels() ? scanCell.GetCenter() : scanCell.GetShape();
                                if (queryShape.Relate(cShape) == SpatialRelation.DISJOINT)
									continue;

								terms.Docs(bits);
							}
						}//term loop
					}
				}
			}//cell loop

			return bits;
		}
 /// <summary>
 /// (non-Javadoc)
 /// see com.browseengine.bobo.util.BigSegmentedArray#findValues(org.apache.lucene.util.OpenBitSet, int, int)
 /// </summary>
 /// <param name="bitset"></param>
 /// <param name="id"></param>
 /// <param name="maxId"></param>
 /// <returns></returns>
 public override int FindValues(OpenBitSet bitset, int id, int maxId)
 {
     while (id <= maxId)
     {
         int i = id >> SHIFT_SIZE;
         if (_array[i] == null)
         {
             if (bitset.FastGet(_fillValue))
                 return id;
             else
                 id = (i + 1) << SHIFT_SIZE; // jump to next segment
         }
         else
         {
             if (bitset.FastGet(_array[i][id & MASK]))
                 return id;
             else
                 id++;
         }
     }
     return DocIdSetIterator.NO_MORE_DOCS;
 }
Example #35
0
		public virtual void  TestEquals()
		{
			rand = NewRandom();
			OpenBitSet b1 = new OpenBitSet(1111);
			OpenBitSet b2 = new OpenBitSet(2222);
			Assert.IsTrue(b1.Equals(b2));
			Assert.IsTrue(b2.Equals(b1));
			b1.Set(10);
			Assert.IsFalse(b1.Equals(b2));
			Assert.IsFalse(b2.Equals(b1));
			b2.Set(10);
			Assert.IsTrue(b1.Equals(b2));
			Assert.IsTrue(b2.Equals(b1));
			b2.Set(2221);
			Assert.IsFalse(b1.Equals(b2));
			Assert.IsFalse(b2.Equals(b1));
			b1.Set(2221);
			Assert.IsTrue(b1.Equals(b2));
			Assert.IsTrue(b2.Equals(b1));
			
			// try different type of object
			Assert.IsFalse(b1.Equals(new System.Object()));
		}
 public MultiValueOrFacetDocIdSetIterator(MultiValueFacetDataCache dataCache, OpenBitSet bs)
     : base(dataCache, bs)
 {
     _nestedArray = dataCache.NestedArray;
 }           
        internal virtual void  DoRandomSets(int maxSize, int iter, int mode)
        {
            System.Collections.BitArray a0 = null;
            OpenBitSet b0 = null;

            for (int i = 0; i < iter; i++)
            {
                int sz = rand.Next(maxSize);
                System.Collections.BitArray a = new System.Collections.BitArray(sz);
                OpenBitSet b = new OpenBitSet(sz);

                // test the various ways of setting bits
                if (sz > 0)
                {
                    int nOper = rand.Next(sz);
                    for (int j = 0; j < nOper; j++)
                    {
                        int idx;

                        idx = rand.Next(sz);
                        a.Set(idx, true);
                        b.FastSet(idx);
                        idx = rand.Next(sz);
                        a.Set(idx, false);
                        b.FastClear(idx);
                        idx = rand.Next(sz);
                        a.Set(idx, !a.Get(idx));
                        b.FastFlip(idx);

                        bool val  = b.FlipAndGet(idx);
                        bool val2 = b.FlipAndGet(idx);
                        Assert.IsTrue(val != val2);

                        val = b.GetAndSet(idx);
                        Assert.IsTrue(val2 == val);
                        Assert.IsTrue(b.Get(idx));

                        if (!val)
                        {
                            b.FastClear(idx);
                        }
                        Assert.IsTrue(b.Get(idx) == val);
                    }
                }

                // test that the various ways of accessing the bits are equivalent
                DoGet(a, b);

                // {{dougsale-2.4.0}}
                //
                // Java's java.util.BitSet automatically grows as needed - i.e., when a bit is referenced beyond
                // the size of the BitSet, an exception isn't thrown - rather, the set grows to the size of the
                // referenced bit.
                //
                // System.Collections.BitArray does not have this feature, and thus I've faked it here by
                // "growing" the array explicitly when necessary (creating a new instance of the appropriate size
                // and setting the appropriate bits).
                //

                // test ranges, including possible extension
                int fromIndex, toIndex;
                fromIndex = rand.Next(sz + 80);
                toIndex   = fromIndex + rand.Next((sz >> 1) + 1);

                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSets 'a'
                // and 'aa' to the same cardinality as 'j+1' when 'a.Count < j+1' and 'fromIndex < toIndex':
                //BitArray aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
                // So, if necessary, lets explicitly grow 'a' now; then 'a' and its clone, 'aa', will be of the required size.
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    System.Collections.BitArray tmp = new System.Collections.BitArray(toIndex, false);
                    for (int k = 0; k < a.Count; k++)
                    {
                        tmp.Set(k, a.Get(k));
                    }
                    a = tmp;
                }
                // {{dougsale-2.4.0}}: now we can invoke this statement without going 'out-of-bounds'
                System.Collections.BitArray aa = (System.Collections.BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++)
                {
                    aa.Set(j, !a.Get(j));
                }
                OpenBitSet bb = (OpenBitSet)b.Clone(); bb.Flip(fromIndex, toIndex);

                DoIterate(aa, bb, mode); // a problem here is from flip or doIterate

                fromIndex = rand.Next(sz + 80);
                toIndex   = fromIndex + rand.Next((sz >> 1) + 1);
                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
                // when 'a.Count < j+1' and 'fromIndex < toIndex'
                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                // So, if necessary, lets explicitly grow 'aa' now
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    aa = new System.Collections.BitArray(toIndex);
                    for (int k = 0; k < a.Count; k++)
                    {
                        aa.Set(k, a.Get(k));
                    }
                }
                else
                {
                    aa = (System.Collections.BitArray)a.Clone();
                }
                for (int j = fromIndex; j < toIndex; j++)
                {
                    aa.Set(j, false);
                }
                bb = (OpenBitSet)b.Clone(); bb.Clear(fromIndex, toIndex);

                DoNextSetBit(aa, bb); // a problem here is from clear() or nextSetBit

                fromIndex = rand.Next(sz + 80);
                toIndex   = fromIndex + rand.Next((sz >> 1) + 1);
                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
                // when 'a.Count < j+1' and 'fromIndex < toIndex'
                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                // So, if necessary, lets explicitly grow 'aa' now
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    aa = new System.Collections.BitArray(toIndex);
                    for (int k = 0; k < a.Count; k++)
                    {
                        aa.Set(k, a.Get(k));
                    }
                }
                else
                {
                    aa = (System.Collections.BitArray)a.Clone();
                }
                for (int j = fromIndex; j < toIndex; j++)
                {
                    aa.Set(j, true);
                }
                bb = (OpenBitSet)b.Clone(); bb.Set(fromIndex, toIndex);

                DoNextSetBit(aa, bb); // a problem here is from set() or nextSetBit


                if (a0 != null)
                {
                    Assert.AreEqual(a.Equals(a0), b.Equals(b0));

                    Assert.AreEqual(BitSetSupport.Cardinality(a), b.Cardinality());

                    // {{dougsale-2.4.0}}
                    //
                    // The Java code used java.util.BitSet, which grows as needed.
                    // When a bit, outside the dimension of the set is referenced,
                    // the set automatically grows to the necessary size.  The
                    // new entries default to false.
                    //
                    // BitArray does not grow automatically and is not growable.
                    // Thus when BitArray instances of mismatched cardinality
                    // interact, we must first explicitly "grow" the smaller one.
                    //
                    // This growth is acheived by creating a new instance of the
                    // required size and copying the appropriate values.
                    //

                    //BitArray a_and = (BitArray)a.Clone(); a_and.And(a0);
                    //BitArray a_or = (BitArray)a.Clone(); a_or.Or(a0);
                    //BitArray a_xor = (BitArray)a.Clone(); a_xor.Xor(a0);
                    //BitArray a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);

                    System.Collections.BitArray a_and;
                    System.Collections.BitArray a_or;
                    System.Collections.BitArray a_xor;
                    System.Collections.BitArray a_andn;

                    if (a.Count < a0.Count)
                    {
                        // the Java code would have implicitly resized 'a_and', 'a_or', 'a_xor', and 'a_andn'
                        // in this case, so we explicitly create a resized stand-in for 'a' here, allowing for
                        // a to keep its original size while 'a_and', 'a_or', 'a_xor', and 'a_andn' are resized
                        System.Collections.BitArray tmp = new System.Collections.BitArray(a0.Count, false);
                        for (int z = 0; z < a.Count; z++)
                        {
                            tmp.Set(z, a.Get(z));
                        }

                        a_and  = (System.Collections.BitArray)tmp.Clone(); a_and.And(a0);
                        a_or   = (System.Collections.BitArray)tmp.Clone(); a_or.Or(a0);
                        a_xor  = (System.Collections.BitArray)tmp.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)tmp.Clone(); for (int j = 0; j < a_andn.Count; j++)
                        {
                            if (a0.Get(j))
                            {
                                a_andn.Set(j, false);
                            }
                        }
                    }
                    else if (a.Count > a0.Count)
                    {
                        // the Java code would have implicitly resized 'a0' in this case, so
                        // we explicitly do so here:
                        System.Collections.BitArray tmp = new System.Collections.BitArray(a.Count, false);
                        for (int z = 0; z < a0.Count; z++)
                        {
                            tmp.Set(z, a0.Get(z));
                        }
                        a0 = tmp;

                        a_and  = (System.Collections.BitArray)a.Clone(); a_and.And(a0);
                        a_or   = (System.Collections.BitArray)a.Clone(); a_or.Or(a0);
                        a_xor  = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++)
                        {
                            if (a0.Get(j))
                            {
                                a_andn.Set(j, false);
                            }
                        }
                    }
                    else
                    {
                        // 'a' and 'a0' are the same size, no explicit growing necessary
                        a_and  = (System.Collections.BitArray)a.Clone(); a_and.And(a0);
                        a_or   = (System.Collections.BitArray)a.Clone(); a_or.Or(a0);
                        a_xor  = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++)
                        {
                            if (a0.Get(j))
                            {
                                a_andn.Set(j, false);
                            }
                        }
                    }

                    OpenBitSet b_and  = (OpenBitSet)b.Clone(); Assert.AreEqual(b, b_and); b_and.And(b0);
                    OpenBitSet b_or   = (OpenBitSet)b.Clone(); b_or.Or(b0);
                    OpenBitSet b_xor  = (OpenBitSet)b.Clone(); b_xor.Xor(b0);
                    OpenBitSet b_andn = (OpenBitSet)b.Clone(); b_andn.AndNot(b0);

                    DoIterate(a_and, b_and, mode);
                    DoIterate(a_or, b_or, mode);
                    DoIterate(a_xor, b_xor, mode);
                    DoIterate(a_andn, b_andn, mode);

                    Assert.AreEqual(BitSetSupport.Cardinality(a_and), b_and.Cardinality());
                    Assert.AreEqual(BitSetSupport.Cardinality(a_or), b_or.Cardinality());
                    Assert.AreEqual(BitSetSupport.Cardinality(a_xor), b_xor.Cardinality());
                    Assert.AreEqual(BitSetSupport.Cardinality(a_andn), b_andn.Cardinality());

                    // test non-mutating popcounts
                    Assert.AreEqual(b_and.Cardinality(), OpenBitSet.IntersectionCount(b, b0));
                    Assert.AreEqual(b_or.Cardinality(), OpenBitSet.UnionCount(b, b0));
                    Assert.AreEqual(b_xor.Cardinality(), OpenBitSet.XorCount(b, b0));
                    Assert.AreEqual(b_andn.Cardinality(), OpenBitSet.AndNotCount(b, b0));
                }

                a0 = a;
                b0 = b;
            }
        }
Example #38
0
 private int FindIn(OpenBitSet OpenBitSet, int baseVal, int val)
 {
     return -1;
 }
Example #39
0
 ///<summary>Method to decompress the entire batch
 ///   *  </summary>
 ///   * <param name="blob"> OpenBitSet </param>
 ///   * <returns> int array with decompressed segment of numbers </returns>
 protected internal virtual int[] Decompress(OpenBitSet blob)
 {
     return new P4DSetNoBase().Decompress(blob);
 }
Example #40
0
        // some BitSet compatability methods

        //** see {@link intersect} */
        public virtual void  And(OpenBitSet other)
        {
            Intersect(other);
        }
Example #41
0
        /// <summary>
        /// Assert that the content of the <see cref="DocIdSet"/> is the same as the content of the <see cref="OpenBitSet"/>.
        /// </summary>
#pragma warning disable xUnit1013
        public virtual void AssertEquals(int numBits, OpenBitSet ds1, WAH8DocIdSet ds2)
#pragma warning restore xUnit1013
        {
            // nextDoc
            DocIdSetIterator it2 = ds2.GetIterator();

            if (it2 == null)
            {
                Assert.AreEqual(-1, ds1.NextSetBit(0));
            }
            else
            {
                Assert.AreEqual(-1, it2.DocID);
                for (int doc = ds1.NextSetBit(0); doc != -1; doc = ds1.NextSetBit(doc + 1))
                {
                    Assert.AreEqual(doc, it2.NextDoc());
                    Assert.AreEqual(doc, it2.DocID);
                }
                Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, it2.NextDoc());
                Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, it2.DocID);
            }

            // nextDoc / advance
            it2 = ds2.GetIterator();
            if (it2 == null)
            {
                Assert.AreEqual(-1, ds1.NextSetBit(0));
            }
            else
            {
                for (int doc = -1; doc != DocIdSetIterator.NO_MORE_DOCS;)
                {
                    if (Random.NextBoolean())
                    {
                        doc = ds1.NextSetBit(doc + 1);
                        if (doc == -1)
                        {
                            doc = DocIdSetIterator.NO_MORE_DOCS;
                        }
                        Assert.AreEqual(doc, it2.NextDoc());
                        Assert.AreEqual(doc, it2.DocID);
                    }
                    else
                    {
                        int target = doc + 1 + Random.Next(Random.NextBoolean() ? 64 : Math.Max(numBits / 8, 1));
                        doc = ds1.NextSetBit(target);
                        if (doc == -1)
                        {
                            doc = DocIdSetIterator.NO_MORE_DOCS;
                        }
                        Assert.AreEqual(doc, it2.Advance(target));
                        Assert.AreEqual(doc, it2.DocID);
                    }
                }
            }

            // bits()
            IBits bits = ds2.Bits;

            if (bits != null)
            {
                // test consistency between bits and iterator
                it2 = ds2.GetIterator();
                for (int previousDoc = -1, doc = it2.NextDoc(); ; previousDoc = doc, doc = it2.NextDoc())
                {
                    int max = doc == DocIdSetIterator.NO_MORE_DOCS ? bits.Length : doc;
                    for (int i = previousDoc + 1; i < max; ++i)
                    {
                        Assert.AreEqual(false, bits.Get(i));
                    }
                    if (doc == DocIdSetIterator.NO_MORE_DOCS)
                    {
                        break;
                    }
                    Assert.AreEqual(true, bits.Get(doc));
                }
            }

            Assert.AreEqual(ds1.Cardinality(), ds2.Cardinality());
        }