PrevSetBit() public method

Returns the index of the last set bit before or on the index specified. -1 is returned if there are no more set bits.
public PrevSetBit ( long index ) : long
index long
return long
コード例 #1
0
 internal virtual void DoPrevSetBit(BitArray a, LongBitSet b)
 {
     int aa = a.Count + Random().Next(100);
     long bb = aa;
     do
     {
         //aa = a.PrevSetBit(aa-1);
         aa--;
         while ((aa >= 0) && (!a.SafeGet(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);
 }
コード例 #2
0
        internal virtual void DoPrevSetBit(BitArray a, LongBitSet b)
        {
            int  aa = a.Count + Random().Next(100);
            long bb = aa;

            do
            {
                //aa = a.PrevSetBit(aa-1);
                aa--;
                while ((aa >= 0) && (!a.SafeGet(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);
        }