void doPrevSetBit(BitArray a, FixedBitSet b)
        {
            int aa = a.Length + rnd.Next(100);
            int bb = aa;

            do
            {
                // aa = a.prevSetBit(aa-1);
                aa--;
                while ((aa >= 0) && (!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);
        }
Example #2
0
		void doPrevSetBit(BitArray a, FixedBitSet b)
		{
			int aa = a.Length + rnd.Next(100);
			int bb = aa;
			do
			{
				// aa = a.prevSetBit(aa-1);
				aa--;
				while ((aa >= 0) && (!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);
		}
Example #3
0
		void doNextSetBit(BitArray a, FixedBitSet b)
		{
			int aa = -1, bb = -1;
			do
			{
				aa = a.NextSetBit(aa + 1);
				bb = bb < b.Length() - 1 ? b.NextSetBit(bb + 1) : -1;
				Assert.AreEqual(aa, bb);
			} while (aa >= 0);
		}
        void doNextSetBit(BitArray a, FixedBitSet b)
        {
            int aa = -1, bb = -1;

            do
            {
                aa = a.NextSetBit(aa + 1);
                bb = bb < b.Length() - 1 ? b.NextSetBit(bb + 1) : -1;
                Assert.AreEqual(aa, bb);
            } while (aa >= 0);
        }
Example #5
0
		void doGet(BitArray 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));
				}
			}
		}
        void doGet(BitArray 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));
                }
            }
        }
Example #7
0
        /// <summary>
        /// pp was just advanced. If that caused a repeater collision, resolve by advancing the lesser
        /// of the two colliding pps. Note that there can only be one collision, as by the initialization
        /// there were no collisions before pp was advanced.
        /// </summary>
        private bool AdvanceRpts(PhrasePositions pp)
        {
            if (pp.RptGroup < 0)
            {
                return(true); // not a repeater
            }
            PhrasePositions[] rg   = RptGroups[pp.RptGroup];
            FixedBitSet       bits = new FixedBitSet(rg.Length); // for re-queuing after collisions are resolved
            int k0 = pp.RptInd;
            int k;

            while ((k = Collide(pp)) >= 0)
            {
                pp = Lesser(pp, rg[k]); // always advance the lesser of the (only) two colliding pps
                if (!AdvancePP(pp))
                {
                    return(false); // exhausted
                }
                if (k != k0)       // careful: mark only those currently in the queue
                {
                    bits = FixedBitSet.EnsureCapacity(bits, k);
                    bits.Set(k); // mark that pp2 need to be re-queued
                }
            }
            // collisions resolved, now re-queue
            // empty (partially) the queue until seeing all pps advanced for resolving collisions
            int n = 0;
            // TODO would be good if we can avoid calling cardinality() in each iteration!
            int numBits = bits.Length(); // larges bit we set

            while (bits.Cardinality() > 0)
            {
                PhrasePositions pp2 = Pq.Pop();
                RptStack[n++] = pp2;
                if (pp2.RptGroup >= 0 && pp2.RptInd < numBits && bits.Get(pp2.RptInd)) // this bit may not have been set
                {
                    bits.Clear(pp2.RptInd);
                }
            }
            // add back to queue
            for (int i = n - 1; i >= 0; i--)
            {
                Pq.Add(RptStack[i]);
            }
            return(true);
        }
Example #8
0
            public override int Advance(int childTarget)
            {
                Debug.Assert(childTarget >= _parentBits.Length() || !_parentBits.Get(childTarget));

                //System.out.println("Q.advance childTarget=" + childTarget);
                if (childTarget == NO_MORE_DOCS)
                {
                    //System.out.println("  END");
                    return(_childDoc = _parentDoc = NO_MORE_DOCS);
                }

                Debug.Assert(_childDoc == -1 || childTarget != _parentDoc, "childTarget=" + childTarget);
                if (_childDoc == -1 || childTarget > _parentDoc)
                {
                    // Advance to new parent:
                    _parentDoc = _parentScorer.Advance(childTarget);
                    ValidateParentDoc();
                    //System.out.println("  advance to parentDoc=" + parentDoc);
                    Debug.Assert(_parentDoc > childTarget);
                    if (_parentDoc == NO_MORE_DOCS)
                    {
                        //System.out.println("  END");
                        return(_childDoc = NO_MORE_DOCS);
                    }
                    if (_doScores)
                    {
                        _parentScore = _parentScorer.Score();
                        _parentFreq  = _parentScorer.Freq();
                    }
                    int firstChild = _parentBits.PrevSetBit(_parentDoc - 1);
                    //System.out.println("  firstChild=" + firstChild);
                    childTarget = Math.Max(childTarget, firstChild);
                }

                Debug.Assert(childTarget < _parentDoc);

                // Advance within children of current parent:
                _childDoc = childTarget;
                //System.out.println("  " + childDoc);
                if (_acceptDocs != null && !_acceptDocs.Get(_childDoc))
                {
                    NextDoc();
                }
                return(_childDoc);
            }
 public int Length()
 {
     return(Bits.Length());
 }