示例#1
0
        internal virtual void DoGet(BitSet a, FixedBitSet b)
        {
            int max = b.Length;

            for (int i = 0; i < max; i++)
            {
                if (a.Get(i) != b.Get(i))
                {
                    Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.Get(i));
                }
            }
        }
示例#2
0
        internal virtual void DoPrevSetBit(BitSet a, FixedBitSet b)
        {
            int aa = a.Length + Random.Next(100);
            int bb = aa;

            do
            {
                // aa = a.PrevSetBit(aa-1);
                aa--;
                while ((aa >= 0) && (aa >= a.Length || !a.Get(aa)))
                {
                    aa--;
                }
                if (b.Length == 0)
                {
                    bb = -1;
                }
                else if (bb > b.Length - 1)
                {
                    bb = b.PrevSetBit(b.Length - 1);
                }
                else if (bb < 1)
                {
                    bb = -1;
                }
                else
                {
                    bb = bb >= 1 ? b.PrevSetBit(bb - 1) : -1;
                }
                Assert.AreEqual(aa, bb);
            } while (aa >= 0);
        }
示例#3
0
        /// <summary>
        /// Create a random set which has <paramref name="numBitsSet"/> of its <paramref name="numBits"/> bits set. </summary>
        protected static BitSet RandomSet(int numBits, int numBitsSet)
        {
            Debug.Assert(numBitsSet <= numBits);
            BitSet set    = new BitSet(numBits);
            Random random = Random;

            if (numBitsSet == numBits)
            {
                set.Set(0, numBits);
            }
            else
            {
                for (int i = 0; i < numBitsSet; ++i)
                {
                    while (true)
                    {
                        int o = random.Next(numBits);
                        if (!set.Get(o))
                        {
                            set.Set(o);
                            break;
                        }
                    }
                }
            }
            return(set);
        }
示例#4
0
        public virtual void TestCompact()
        {
            BytesRef @ref = new BytesRef();
            int      num  = AtLeast(2);

            for (int j = 0; j < num; j++)
            {
                int       numEntries = 0;
                const int size       = 797;
                BitSet    bits       = new BitSet(size);
                for (int i = 0; i < size; i++)
                {
                    string str;
                    do
                    {
                        str = TestUtil.RandomRealisticUnicodeString(Random, 1000);
                    } while (str.Length == 0);
                    @ref.CopyChars(str);
                    int key = hash.Add(@ref);
                    if (key < 0)
                    {
                        Assert.IsTrue(bits.Get((-key) - 1));
                    }
                    else
                    {
                        Assert.IsFalse(bits.Get(key));
                        bits.Set(key);
                        numEntries++;
                    }
                }
                Assert.AreEqual(hash.Count, bits.Cardinality);
                Assert.AreEqual(numEntries, bits.Cardinality);
                Assert.AreEqual(numEntries, hash.Count);
                int[] compact = hash.Compact();
                Assert.IsTrue(numEntries < compact.Length);
                for (int i = 0; i < numEntries; i++)
                {
                    bits.Clear(compact[i]);
                }
                Assert.AreEqual(0, bits.Cardinality);
                hash.Clear();
                Assert.AreEqual(0, hash.Count);
                hash.Reinit();
            }
        }
示例#5
0
        public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter)
        {
            int  ret      = 0;
            long nMatches = 0;

            for (int i = 0; i < iter; i++)
            {
                int          oClauses = Random.Next(maxOuterClauses - 1) + 2;
                BooleanQuery oq       = new BooleanQuery();
                for (int o = 0; o < oClauses; o++)
                {
                    int          nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
                    BooleanQuery bq       = new BooleanQuery();
                    BitSet       termflag = new BitSet(termsInIndex);
                    for (int j = 0; j < nClauses; j++)
                    {
                        int tnum;
                        // don't pick same clause twice
                        tnum = Random.Next(termsInIndex);
                        if (termflag.Get(tnum))
                        {
                            tnum = termflag.NextClearBit(tnum);
                        }
                        if (tnum < 0 || tnum >= 25)
                        {
                            tnum = termflag.NextClearBit(0);
                        }
                        termflag.Set(tnum);
                        Query tq = new TermQuery(terms[tnum]);
                        bq.Add(tq, Occur.MUST);
                    } // inner

                    oq.Add(bq, Occur.MUST);
                } // outer

                CountingHitCollector hc = new CountingHitCollector();
                s.Search(oq, hc);
                nMatches += hc.Count;
                ret      += hc.Sum;
            }
            if (Verbose)
            {
                Console.WriteLine("Average number of matches=" + (nMatches / iter));
            }
            return(ret);
        }